Reputation: 444
I am storing secrets in google cloud secret manager in JSON format and need to read each key and pass the value as environment variable. I have refered various blogs but not able to do so. In AWS, I was able to do it using JMESPATH, it would be great if some one could help me to achieve the same.
{
"value-A": "abscd"
"value-B": "sdskdf"
}
I need to Need Value-A and pass as environment variable. Similary Value-B as environment variable in the pod. so I could read the values using ${value-A} and ${value-B}
Upvotes: 0
Views: 142
Reputation: 197
I tried to replicate using your access secret data in a Pod by combining through a Volume and container environment variables which gives the desired values that you needed.
Here are the steps:
{
"value-A": "abscd"
,"value-B": "sdskdf"
}
apiVersion: v1
kind: Pod
metadata:
name: secret-test-pod
spec:
containers:
- name: test-container
image: nginx
volumeMounts:
# Mount the secret as a volume
- name: secret-volume
mountPath: /etc/secret-volume
readOnly: true
envFrom:
# Inject the secret as environment variables
- secretRef:
name: my-secret
volumes:
- name: secret-volume
secret:
secretName: my-secret
kubectl exec -i -t secret-test-pod(metadata_name) -- /bin/bash
# Run this in the shell inside the container
echo "$( cat /etc/secret-volume(volumes name)/value-A )"
echo "$( cat /etc/secret-volume(volumes name)/value-B )"
For alternative approaches, use the Secret Manager add-on for GKE.
Upvotes: 0
Reputation: 2189
I highly doubt that's possible, I also don't see why you would want to do this, you have 2 much more maintainable options already:
Upvotes: 0