k8s搭建drone
Drone 是用 Go 语言编写的基于 Docker 构建的开源轻量级 CI/CD 工具,可以通过 SaaS 服务和自托管服务两种方式使用,Drone 使用简单的 YAML 配置文件来定义和执行 Docker 容器中定义的 Pipeline,Drone 由两个部分组成:Server端负责身份认证,仓库配置,用户、Secrets 以及 Webhook 相关的配置。Agent端用于接受构建的作业和真正
Drone 是用 Go 语言编写的基于 Docker 构建的开源轻量级 CI/CD 工具,可以通过 SaaS 服务和自托管服务两种方式使用,Drone 使用简单的 YAML 配置文件来定义和执行 Docker 容器中定义的 Pipeline,Drone 由两个部分组成:
- Server端负责身份认证,仓库配置,用户、Secrets 以及 Webhook 相关的配置。
- Agent端用于接受构建的作业和真正用于运行的 Pipeline 工作流。
Server 和 Agent 都是非常轻量级的服务,大概只使用 10~15MB 内存,所以我们也可以很轻松的运行在笔记本、台式机甚至是 Raspberry PI 上面
1、申请域名,绑定VIP
2、创建如下service
apiVersion: v1
kind: Service
metadata:
annotations:
sigma.ali/vip: 100.64.46.7
name: drone-server
namespace: vts
labels:
app: drone-server
sigma.ali/internal-lb: vip
sigma.ali/instance-group: vts-drone
spec:
clusterIP: None
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: drone-server
3、创建 DRONE_RPC_SECRET # 共享密钥
openssl rand -hex 16
de9e0d708e49cc14c02008bc16ee8cca
4、创建drone-server.yml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: drone-server
name: drone-server
namespace: vts
spec:
replicas: 1
selector:
matchLabels:
app: drone-server
template:
metadata:
labels:
app: drone-server
sigma.ali/app-name: vts
sigma.ali/instance-group: vts-service
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: resource-group.bach.io/vts
operator: Exists
containers:
- env:
- name: DRONE_GITLAB_CLIENT_ID
value: d2e2f75e723e0fb91a3be09c650f6fbb3b2794fa6507e4a9cd3267fc2296c0b8
- name: DRONE_GITLAB_CLIENT_SECRET
value: 87aa84b868f8fc64b331f59c68904276ac976a01ac0c5c7b663faf216aca0282
- name: DRONE_GITLAB_SERVER
value: http://gitlab.alibaba-inc.com/
- name: DRONE_GIT_ALWAYS_AUTH
value: "true"
- name: DRONE_GITLAB_DEBUG
value: "true"
- name: DRONE_RPC_SECRET
#value: de9e0d708e49cc14c02008bc16ee8cca
value: bd6c2d42e64197b8753fab0d4cd5d27f
- name: DRONE_SERVER_HOST
value: vts-drone-test-inc.com
- name: DRONE_SERVER_PROTO
value: http
- name: DRONE_USER_CREATE
value: username:wb-ldp766934,machine:false,admin:true
- name: DRONE_GITLAB_SKIP_VERIFY
value: "true"
- name: DRONE_LOGS_DEBUG
value: "true"
- name: DRONE_DEBUG_DUMP_HOOK
value: "true"
- name: DRONE_REPOSITORY_TRUSTED
value: "true"
image: reg.docker.test.com/vts-test/drone-server:latest
imagePullPolicy: Always
name: drone-server
ports:
- containerPort: 80
name: http
protocol: TCP
- containerPort: 443
name: https
protocol: TCP
dnsPolicy: Default
restartPolicy: Always
schedulerName: default-scheduler
tolerations:
- effect: NoSchedule
key: sigma.ali/resource-pool
operator: Equal
value: mit_bach
- effect: NoSchedule
key: sigma.ali/is-ecs
operator: Equal
value: "true"
kubectl apply -f drone-server.yml -n vts
5、创建drone-runner.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: drone-runner
namespace: vts
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: reg.docker.test-inc.com/vts-test/drone-runner:latest
ports:
- containerPort: 3000
env:
- name: DRONE_RPC_HOST
#value: vts-drone.test-inc.com
value: 100.67.206.236
- name: DRONE_RPC_PROTO
value: http
- name: DRONE_RPC_SECRET
value: bd6c2d42e64197b8753fab0d4cd5d27f
tolerations:
- effect: NoSchedule
key: sigma.ali/resource-pool
value: sigma_public
- effect: NoSchedule
key: sigma.ali/is-ecs
operator: Exists
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
kubectl apply -f drone-runner.yml -n vts
6、查看pod
kubectl get pod -n vts | grep drone-runner
7、删除pod
kubectl delete -f drone-runner.yml -n vts
(必须)DRONE_GITLAB_CLIENT_ID # GitLab oauth客户端ID(必须)DRONE_GITLAB_CLIENT_SECRET # GitLab oauth客户端密钥
(必须)DRONE_RPC_SECRET # 共享密钥,de9e0d708e49cc14c02008bc16ee8cca[用于验证到服务器的rpc连接。必须为服务器和代理提供相同的秘密值]
(必须)DRONE_SERVER_HOST # drone地址[提供您的外部主机名或IP地址。如果使用IP地址,则可以包括端口]
(必须)DRONE_SERVER_PROTO # 提供了您的外部协议方案。此值应设置为http或https
(可选)DRONE_GITLAB_SERVER # 提供您的GitLab服务器网址,默认值为的gitlab.com服务器地址https://gitlab.com
(可选)DRONE_GIT_ALWAYS_AUTH # 可选的布尔值
DRONE_RPC_SECRET # 共享密钥
启动成功:
8、授权
打开浏览器,查看域名 http://vts-drone-new.test.com,经过 gitlab 授权后可以看到 drone.ci 的管理页面。
更多推荐
所有评论(0)