<p>I am a beginner to Kubernetes. I have created a secret file and referred it in deployment yaml file.</p>
<p>app-secret.yaml</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: app-secret
data:
  username: YWRtaW4=
  password: YWRtaW4=
</code></pre>
<p>deploy.yaml</p>
<pre><code>env:
          - name: DEPLOY_ENV
            value: ${env}
          - name: NAMESPACE_NAME
            valueFrom:
                fieldRef:
                  fieldPath : metadata.namespace
          - name: APP_USERNAME
            valueFrom:
                secretKeyRef:
                  name: app-secret
                  key: username
          - name: APP_PASSWORD
            valueFrom:
                secretKeyRef:
                  name: app-secret
                  key: password
</code></pre>
<p>While using the command <code>kubectl get secret pod-54rfxd -n dev-ns -o json</code>, it is printing the username and password in encoded format only. When i query for the environment variables list using the command <code>kubectl exec pod-54rfxd -n dev-ns -- printenv</code>, it was giving below result.</p>
<pre><code>APP_USERNAME=admin
APP_PASSWORD=admin
</code></pre>
<p>Why it was not in encoded format in environment variables. Could you please let me know the reason and is it possible to have it in encoded format?</p>

<p>You could use the <code>stringData</code> format:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Secret
metadata:
  name: app-secret
stringData:
  username: &quot;YWRtaW4=&quot;
  password: &quot;YWRtaW4=&quot;
</code></pre>
<p>From K8s doc:
<a href="https://i.stack.imgur.com/uasIb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uasIb.png" alt="warning about stringData secret type" /></a></p>
<p><a href="https://kubernetes.io/docs/concepts/configuration/secret/" rel="nofollow noreferrer">K8s doc</a></p>
