<p>I'm currently migrating my docker deployment to k8s manifests and I was wondering about the handling of secretes. Currently my docker container fetches /run/secrets/app_secret_key to get the sensitive information inside the container as env var. but does that have any benefit in comparison to k8s secrets handling as on the other side I can also do something like this in my manifest.yaml:</p>
<pre><code>env:
- name: MYSQL_PASSWORD
  valueFrom:
    secretKeyRef:
      name: mysql-password
      key: password
</code></pre>
<p>which than directly brings the secret as a env-variable inside the container ...
The only difference I was able to notice is that if I fetch /run/secrets/app_secret_key inside the container like so (docker-entrypoint.sh):</p>
<pre><code>export APP_SECRET_KEY=&quot;$(cat /run/secrets/app_secret_key)&quot;
</code></pre>
<p>the env var is not visible when I access the container after deployment, it seems that the env var is only available at the &quot;session&quot; where docker-entrypoint.sh gets initially triggered (at container/pod startup).</p>
<p>So my question now is what does make more sense here: simply go with the env: statement shown above or stay with manual fetching /run/secrets/app_secret_key inside the container ...</p>
<p>Thanks in advance</p>

<p>Exposing secret as env var or file is just a flavor to use the secret the k8s way.</p>
<p>Some secret like password is just a one line long string, so it’s convenient to use it as env var. Other secret like ssh private key or TLS certificate can be multiple line, that’s why you can mount the secret as volume instead.</p>
<p>Still, it’s recommended to declare your secret as k8s secret resources. That way you can fetch the value needed via kubectl without having to go inside the container. You can also make a template like helm chart that generate the secret manifests at deployment. With RBAC, you can also control who can read the secret manifests.</p>
<p>As per your comments, yes any user that can go inside the container will have access to the resource available to the shell user.</p>
