2

How can I retrieve a Kubernetes secret from inside a pod hosting jupyterlab? I need to access a secret that holds information needed for spark executor pod configurations. I tried using the answer given here:

k8s/python: How do I read a secret using the Kubernetes Python client?

But I'm running into issues with it. Are there other ways or is there something not specifically mentioned in this answer that is necessary for it to work?

Rico
  • 58,485
  • 12
  • 111
  • 141
JMV12
  • 965
  • 1
  • 20
  • 52

1 Answers1

2

The secrets are really volumes mounted on your Pod. So you can access them that way. So depending where you are mounting the secret you can just the filename.

For example:

apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  username: xxxx
  password: xxxx

and the Pod

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo"
      readOnly: true
  volumes:
  - name: foo
    secret:
      secretName: mysecret

You can see the content:

cat /etc/foo/data

If it's Opaque you can decode it with base64

cat /etc/foo/data | base64 -d

✌️

Rico
  • 58,485
  • 12
  • 111
  • 141