<p>Is there a way to set a kubernetes secret key name when using <code>--from-file</code> other than the filename?</p>

<p>I have a bunch of different configuration files that I use as <code>secrets.json</code> within my containers. However, to organize my files, none of them are named <code>secrets.json</code> on my host. For example <code>secrets.dev.json</code> or <code>secrets.test.json</code>. My apps only know to read in <code>secrets.json</code>.</p>

<p>When I create a secret with <code>kubectl create secret generic my-app-secrets --from-file=secrets.dev.json</code>, this results in the key name being <code>secrets.dev.json</code> and not <code>secrets.json</code>.</p>

<p>I'm mounting in my secret contents as a file (this is a carry-over from migrating from Docker swarm).</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-deployment
spec:
  template:
    spec:
      volumes:
      - name: my-secret
        secret:
          secretName: my-app-secrets
      containers:
        - name: my-app
          volumeMounts:
            - name: my-secret
              mountPath: "/run/secrets/secrets.json"
              subPath: "secrets.json"
</code></pre>

<p>Because <code>secrets.json</code> doesn't exist as a key because it used the filename (<code>secrets.dev.json</code>), it ends up getting turned into a directory instead. I end up getting this mount path: <code>/run/secrets/secrets.json/secrets.dev.json</code>.</p>

<p>I'd like to be able to set the key name to <code>secrets.json</code> instead of using the filename of <code>secrets.dev.json</code>. </p>

<p>You can specify key name <code>[--from-file=[key=]source]</code></p>

<pre><code>kubectl create secret generic my-app-secrets --from-file=secrets.json=secrets.dev.json
</code></pre>

<p>Here, <code>secrets.json</code> is key name and <code>secrets.dev.json</code> is source</p>
