purple_lolakos
purple_lolakos

Reputation: 496

K8s Python Access Secret from inside Kubernetes

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

Upvotes: 1

Views: 1581

Answers (1)

Antoine
Antoine

Reputation: 587

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

Upvotes: 2

Related Questions