我使用舵图部署了drone.io。构建工作正常。对于我的秘密,我遵循了这个文档:https ://readme.drone.io/extend/secrets/kubernetes/install/
所以我创建了一个秘密来保存插件和无人机服务器之间的共享密钥(对不起,ansible 标记):
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: drone-kubernetes
data:
server: {{ server.stdout | b64encode }}
cert: {{ cert.stdout | b64encode }}
token: {{ token.stdout | b64encode }}
secret: {{ secret.stdout | b64encode }}
Kubernetes 秘密插件的部署:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: drone
component: secrets
release: drone
name: drone-drone-secrets
spec:
selector:
matchLabels:
app: drone
component: secrets
release: drone
template:
metadata:
labels:
app: drone
component: secrets
release: drone
spec:
containers:
- env:
- name: SECRET_KEY
valueFrom:
secretKeyRef:
key: secret
name: drone-kubernetes
image: docker.io/drone/kubernetes-secrets:linux-arm64
imagePullPolicy: IfNotPresent
name: secrets
ports:
- containerPort: 3000
name: secretapi
protocol: TCP
volumeMounts:
- mountPath: /etc/kubernetes/config
name: kube
volumes:
- name: kube
hostPath:
path: /etc/kubernetes/admin.conf
type: File
以及该部署的服务:
apiVersion: v1
kind: Service
metadata:
labels:
app: drone
component: secrets
release: drone
name: drone-secrets
spec:
ports:
- name: secretapi
port: 3000
protocol: TCP
selector:
app: drone
component: secrets
release: drone
type: ClusterIP
我修补了无人机服务器部署以设置 DRONE_SECRET_SECRET 和 DRONE_SECRET_ENDPOINT 变量。
kubernetes-secrets 插件的 pod 确实可以按预期看到文件“/etc/kubernetes/config”,并且将 SECRET_KEY 作为环境。并从无人机服务器吊舱:
kubectl exec -i drone-drone-server-some-hash-here -- sh -c 'curl -s $DRONE_SECRET_ENDPOINT'
Invalid or Missing Signature
到目前为止,一切都很好。一切似乎都设置正确。
这是我的测试项目的 .drone.yml 文件:
kind: pipeline
name: default
steps:
- name: kubectl
image: private-repo.local:5000/drone-kubectl
settings:
kubectl: "get pods"
kubernetes_server:
from_secret: kubernetes_server
kubernetes_cert:
from_secret: kubernetes_cert
image_pull_secrets:
- kubernetes_server
- kubernetes_cert
---
kind: secret
name: kubernetes_server
get:
path: drone-kubernetes
name: server
---
kind: secret
name: kubernetes_cert
get:
path: drone-kubernetes
name: cert
---
kind: secret
name: kubernetes_token
get:
path: drone-kubernetes
name: token
目前,自定义插件drone-kubectl 只运行 env 命令来查看我是否得到了我的秘密,而我没有......我错过了什么?