<p>How can I mount a 'single' file from a secret?</p>

<p>I've created a secret with:</p>

<pre><code>kubectl create secret generic oauth \
        --from-file=./.work-in-progress/oauth_private.key \
        --from-file=./.work-in-progress/oauth_public.key \
</code></pre>

<p>How can I mount the <code>oauth_private.key</code> file as a single file, rather than overriding the entire path with a directory that ONLY contains the two files (and potentially removing files that existed on the container initially)?</p>

<p>You can do as bellow:</p>

<pre><code>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
      items:
      - key: username
        path: my-group/my-username
</code></pre>

<p>Suppose <code>mysecret</code> contains <code>username</code> and <code>password</code>. Above yaml will mount only <code>username</code> in <code>/etc/foo/my-group/my-username</code> directory.</p>

<p>For more details check this: <a href="https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-files-from-a-pod" rel="noreferrer">Using Secrets as Files from a Pod</a></p>
