1

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"] ?

purple_lolakos
  • 456
  • 5
  • 15

1 Answers1

2

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

Antoine
  • 577
  • 4
  • 17