Your pod needs to talk to the api server and ask for the pod definition, to be able to find it.
For that, pod's service account (be it default
or a custom one) needs the appropriate Role
and RoleBinding
that allows that service account to read certain kubernetes resources, in this case, the pod definition itself, and probably the Secret
objects in the namespace, so it can find out the corresponding secret (i.e. if there is an environment variable that is coming from a secret via envFrom
directive).
The service account token is mounted to the path /var/run/secrets/kubernetes.io/serviceaccount/token
in a pod. Using that token, your process can talk to the Kubernetes api from inside the cluster. You can use any Kubernetes client library in any language, or simply kubectl
. Then it's a matter of implementing the logic that will find out which secrets are providing which files/variables.