I'm trying to use secrets from Azure Key Vault in my Kubernetes deployment as env variables and I'm struggling to do so. I'm using Azure pod identity and the secrets get mounted to the file and that works, however I want them to be accessible as env variables.
Here is my secrets.yml file:
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>"
And my 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
I've been following the examples provided by Azure: secret, deployment
When I apply both files, I get the CreateContainerConfigError
: Error: secret "test-secret" not found