為何我要介紹大家怎麼在K8s上跑Drone呢?因為之後某篇組合技會用到啊!
先來介紹各位如何安裝與設定
先建立For Drone Runner的RBAC
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: drone
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- delete
- apiGroups:
- ""
resources:
- pods
- pods/log
verbs:
- get
- create
- delete
- list
- watch
- update
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: drone
namespace: default
subjects:
- kind: ServiceAccount
name: default
namespace: default
roleRef:
kind: Role
name: drone
apiGroup: rbac.authorization.k8s.io
部署 Drone Runner
apiVersion: apps/v1
kind: Deployment
metadata:
name: drone
labels:
app.kubernetes.io/name: drone
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: drone
template:
metadata:
labels:
app.kubernetes.io/name: drone
spec:
containers:
- name: runner
image: drone/drone-runner-kube:latest
ports:
- containerPort: 3000
env:
- name: DRONE_RPC_HOST
value: $your_drone_server_host
- name: DRONE_RPC_PROTO
value: http
- name: DRONE_RPC_SECRET
value: $your_drone_secret
只要寫好上述兩個yaml部署檔,直接下kubectl apply -f xxx.yaml
就建立完成了。
kubectl get pods | grep "drone"
drone-5f3ccfb8dv-fek12 1/1 Running
這裡有官網提供的其他參數設定,想深入了解的朋友也可以進去看看唷!
防火牆需要開通 k8s -> drone or git private or public registry
如果你有多個cluster,需要by event觸發到指定cluster的跑drone的CI/CD時,無法指定cluster的窘境,我有試過使用node_selector設定,是會真的可以到指定node跑drone的CI/CD,但如果有指定cluster的需求就無法單純這樣做到。
我有想過要怎麼樣做到指定cluster去跑drone的CI/CD,因為看起來drone server無法指定cluster的runner......
那就開N台drone server,在該repo綁定N個webhook,在git registry的此專案設定哪個webhook綁定哪個branch,一個webhook代表一個cluster。
簡單來說就是要 by branch -> k8s drone by cluster 的意思
這樣就可以滿足「by event觸發到指定cluster的跑drone的CI/CD」的需求了。
最後期待drone在k8s方面能越來越滿足多clusters的需求囉。