- 配置宿主机hosts文件,加入以下条目3个域名
x.x.x.x drone.drone.svc.cluster.local gitea.gitea.svc.cluster.local runner.drone.svc.cluster.local
2.安装gitea
helm repo add gitea-charts https://dl.gitea.io/charts/
helm pull gitea-charts/gitea
tar -zxcf gitea-2.2.3.gz
修改values.yaml
ingress:
enabled: true
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- gitea.gitea.svc.cluster.local
创建gitea 命名空间和安装gitea
kubectl create namespace gitea
helm install gitea -n gitea gitea-charts/gitea --values values.yaml
浏览器里输入
https://rancher.taihu.org
进入gitea,找到service,创建一个叫gitea的service,因为gitea-http端口是3000
所以我们多加一个80端口的service


这样还有一个好处解决k3s集群内的域名和集群外的域名的一致性问题
因为根据k8s的命名规则
service.namespace.svc.cluster.local
k3s里coredns会自动解释这个域名,至于k3s集群外,就用宿主机的hosts文件里,本地ip映射这个域名就可以了。
宿主机映射的域名,必须创建ingress,之前的文件已经创建好了

登录这个地址,然后创建一个账户,taihu/taihu123
创建一个repository,叫test

- 安装drone
kubectl create namespace drone
helm repo add drone https://charts.drone.io
helm pull drone/drone
tar -zxvf drone-0.1.7.gz
生成RPC key
openssl rand -hex 16
在gitwa注册drone app
在setting-application-OAuth2 Application
名字写drone,地址写入http://drone.drone.svc.cluster.local/login
会生成client id 和 secret

修改values.yaml
如果用http,注释调tls[]
ingress:
enabled: true
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: drone.drone.svc.cluster.local
paths:
- "/"
#tls: []
........
env:
## REQUIRED: Set the user-visible Drone hostname, sans protocol.
## Ref: https://docs.drone.io/installation/reference/drone-server-host/
##
DRONE_SERVER_HOST: drone.drone.svc.cluster.local
## The protocol to pair with the value in DRONE_SERVER_HOST (http or https).
## Ref: https://docs.drone.io/installation/reference/drone-server-proto/
##
DRONE_SERVER_PROTO: http
## REQUIRED: Set the secret secret token that the Drone server and its Runners will use
## to authenticate. This is commented out in order to leave you the ability to set the
## key via a separately provisioned secret (see existingSecretName above).
## Ref: https://docs.drone.io/installation/reference/drone-rpc-secret/
##
DRONE_RPC_SECRET: 7d135806329fc6f42007ccb16e791a5e
...........
DRONE_GITEA_CLIENT_ID: 0bf1cfde-1b9f-429e-bda3-506593514008
DRONE_GITEA_CLIENT_SECRET: VLFw16i55MfFN0_wGFJtFJ7VMIpv51Gh2MndfbeY4hc=
DRONE_GITEA_SERVER: http://gitea.gitea.svc.cluster.local
安装drone server
helm install drone -n drone drone/drone --values values.yaml
drone自己的service就叫drone,另外暴露的端口就是80,所以本地域名就是
drone.drone.svc.cluster.local
再设置ingress里的域名也叫这个

浏览器里登录这个域名

- 安装drone runner
先下载
helm pull drone/drone-runner-kube
然后修改values.yaml
ingress设置为true,注释tls
需要设置docker路径映射到宿主机
ingress:
enabled: true
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: runner.drone.svc.cluster.local
paths:
- "/"
#tls: []
-----
extraVolumes:
- name: docker-volume
hostPath:
path: /var/run/docker.sock
## If you have declared extra volumes, mount them here, per the Pod Container's
## "volumeMounts" section.
##
extraVolumeMounts:
- name: docker-volume
mountPath: /var/run/docker.sock
-----
env:
## REQUIRED: Set the secret secret token that the Kubernetes runner and its runners will use
## to authenticate. This is commented out in order to leave you the ability to set the
## key via a separately provisioned secret (see existingSecretName above).
## Ref: https://kube-runner.docs.drone.io/installation/reference/drone-rpc-secret/
##
DRONE_RPC_SECRET: 7d135806329fc6f42007ccb16e791a5e
## The hostname/IP (and optionally the port) for your Kubernetes runner. Defaults to the "drone"
## service that the drone server Chart creates by default.
## Ref: https://kube-runner.docs.drone.io/installation/reference/drone-rpc-host/
##
DRONE_RPC_HOST: drone.drone.svc.cluster.local
## The protocol to use for communication with Drone server.
## Ref: https://kube-runner.docs.drone.io/installation/reference/drone-rpc-proto/
##
DRONE_RPC_PROTO: http
## Determines the default Kubernetes namespace for Drone builds to run in.
## Ref: https://kube-runner.docs.drone.io/installation/reference/drone-namespace-default/
##
DRONE_NAMESPACE_DEFAULT: drone
和server安装在同一个namespace下
helm install drone-runner-kube drone/drone-runner-kube --namespace drone --values values.yaml
因为默认创建的service的端口是3000,所以我们自己加一个80端口的service

同样ingress的域名也是相应的

- 更新gitea里的test项目
加入main.go
package main
import "fmt"
func main() {
fmt.Println("Hxello, World!")
fmt.Println("Hello, Woxxxxxr")
fmt.Println("Hello, World!")
}
加入.drone.yml文件
kind: pipeline
type: kubernetes
name: mygo
steps:
- name: test
image: golang:1.15-alpine
commands:
- ls
- go build -o myapp .
- ls
- ./myapp
这个里有坑,必须指定type是kubernetes,否则跑不起来
不容易啊搞了好几天终于跑成功了

网友评论