带有 Azure Key Vault 的 AKS - 环境变量未加载

带有 Azure Key Vault 的 AKS - 环境变量未加载

我正在尝试将 Kubernetes 部署中的 Azure Key Vault 中的机密用作环境变量,但一直难以做到。我使用 Azure pod 标识,机密已安装到文件中,并且可行,但我希望它们可以作为环境变量访问。

这是我的 secrets.yml 文件:

apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
kind: SecretProviderClass
metadata:
  name: azure-kvname
spec:
  provider: azure
  secretObjects:
  - secretName: test-secret
    type: Opaque
    data:
    - objectName: test-db-user
      key: dbuser
    - objectName: test-db-pass
      key: dbpassword
  parameters:
    usePodIdentity: "true"
    keyvaultName: "test-keyvault"      
    cloudName: ""               
    objects:  |
      array:
        - |
          objectName: test-db-user
          objectType: secret
          objectVersion: ""
        - |
          objectName: test-db-pass
          objectType: secret
          objectVersion: ""
    tenantId: "<tenantID>"

我的deployment.yml:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-secrets-store-inline
  labels:
    aadpodidbinding: aadpodidbinding
spec:
  containers:
    - name: nginx
      image: nginx
      volumeMounts:
        - name: secrets-store-inline
          mountPath: "/mnt/secrets-store"
          readOnly: true
      env:
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: test-secret
              key: dbuser
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: test-secret
              key: dbpassword
  volumes:
    - name: secrets-store-inline
      csi:
        driver: secrets-store.csi.k8s.io
        readOnly: true
        volumeAttributes:
          secretProviderClass: azure-kvname

我一直在关注 Azure 提供的示例:秘密部署

当我应用这两个文件时,我得到了CreateContainerConfigErrorError: secret "test-secret" not found

答案1

相关内容