<p><strong>Kubernetes</strong> <strong>Secrets</strong> create files that are mounted as a <strong>volumeMount</strong>.</p>

<p>There is possibility to put multiple files in a single Secret.</p>

<p>Is there a way to create a Secret that would put files in a <strong>directory structure</strong> (i.e. in a folder) ?</p>

<p>There is no sign of it in the docs, and using <code>/</code> is not allowed in the key name, so it seems like it is not possible (except for making multiple secrets and mounting them in different volumes)</p>

<p>Does anyone know better?</p>

<p>This is actually possible now: You need to use the <code>items</code> field to project the key/value pairs in the secret to specific paths that you want. See the example in the section titled "Projection of secret keys to specific paths" in the secrets documentation, which I've linked and copied below: <a href="https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-files-from-a-pod" rel="noreferrer">https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-files-from-a-pod</a></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>This will place the secret with key "username" at the path <code>/my_secret_volume/my-group/my-username</code></p>
