<p>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:</p>
<p><a href="https://stackoverflow.com/questions/55159582/k8s-python-how-do-i-read-a-secret-using-the-kubernetes-python-client/55178953">k8s/python: How do I read a secret using the Kubernetes Python client?</a></p>
<p>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?</p>

<p>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.</p>
<p>For example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  username: xxxx
  password: xxxx
</code></pre>
<p>and the Pod</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: &quot;/etc/foo&quot;
      readOnly: true
  volumes:
  - name: foo
    secret:
      secretName: mysecret
</code></pre>
<p>You can see the content:</p>
<pre class="lang-sh prettyprint-override"><code>cat /etc/foo/data
</code></pre>
<p>If it's <code>Opaque</code> you can decode it with <code>base64</code></p>
<pre class="lang-sh prettyprint-override"><code>cat /etc/foo/data | base64 -d
</code></pre>
<p>✌️</p>
