您可能想要使用kubernetes-secret-generator。我已经对其进行了测试,它正在做你所需要的。
要完成它,您必须在集群中安装 helm 并按照以下说明进行操作:
克隆存储库
$ git clone https://github.com/mittwald/kubernetes-secret-generator
创建 helm 部署
$ helm upgrade --install secret-generator ./deploy/chart
现在你要使用它,你只需要
secret-generator.v1.mittwald.de/autogenerate
向任何 Kubernetes 密钥对象添加注解。注解的值可以是密钥中的字段名称(或逗号分隔的字段名称列表);SecretGeneratorController 将获取此注释并将一个字段[或字段](password
在下面的示例中)添加到具有随机生成的字符串值的密钥中。从这里。
$ kubectl apply -f mysecret.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
annotations:
secret-generator.v1.mittwald.de/autogenerate: password
data:
username: UGxlYXNlQWNjZXB0Cg==
应用此密码后,您可以查看它以检查密码是否按预期生成:
$ kubectl get secrets mysecret -o yaml
apiVersion: v1
data:
password: dnVKTDBJZ0tFS1BacmtTMnBuc3d2YWs2YlZsZ0xPTUFKdStDa3dwUQ==
username: UGxlYXNlQWNjZXB0Cg==
kind: Secret
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"username":"UGxlYXNlQWNjZXB0Cg=="},"kind":"Secret","metadata":{"annotations":{"secret-generator.v1.mittwald.de/autogenerate":"password"},"name":"mysecret","namespace":"default"}}
secret-generator.v1.mittwald.de/autogenerate: password
secret-generator.v1.mittwald.de/autogenerate-generated-at: 2020-01-09 14:29:44.397648062
+0000 UTC m=+664.011602557
secret-generator.v1.mittwald.de/secure: "yes"
creationTimestamp: "2020-01-09T14:29:44Z"
name: mysecret
namespace: default
resourceVersion: "297425"
selfLink: /api/v1/namespaces/default/secrets/mysecret
uid: 7ae42d71-32ec-11ea-92b3-42010a800009
type: Opaque
如我们所见,密码已生成,并根据您的需要进行了加密。