My question is the same of this question: k8s/python: How do I read a secret using the Kubernetes Python client? but from inside Kubernetes. I know how to access secrets from the outside with kubernetes python client.
But how do I access a secret in python when inside kubernetes? I have several python microservices, and they should all access secrets from within kubernetes. According to the official documentation https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-pod-that-has-access-to-the-secret-data-through-environment-variables I can create environmental variables. Would these variables then be accessible through import os; os["MY_VAR"]
import os; os["MY_VAR"]
?
I think your guess is right, and that if you deploy a pod with the following configuration , then you will be able to access the environment variable SECRET_USERNAME
within your pod. Then,
import os
username = os.environ["SECRET_USERNAME"]
would allow you to access this value directly in python
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.