<p>I've created a secret and when I deploy an application intended to read the secret, the application complains that the secret is a directory.</p>
<p>What am I doing wrong? The file is intended to be read as, well, a file.</p>
<pre><code>kc logs &lt;pod&gt;
(error) /var/config/my-file.yaml: is a directory.
</code></pre>
<p>The secret is created like this.</p>
<pre><code>kubectl create secret generic my-file.yaml --from-file=my-file.yaml
</code></pre>
<p>And here is the deployment.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: a-name
spec:
  replicas: 1
  selector:
    matchLabels:
      name: a-name
  template:
    metadata:
      labels:
        name: a-name
    spec:
      volumes:
        - name: my-secret-volume
          secret:
            secretName: my-file.yaml
      containers:
        - name: a-name
          image: test/image:v1.0.0
          volumeMounts:
            - name: my-secret-volume
              mountPath: /var/config/my-file.yaml
              subPath: my-file.yaml
              readOnly: true
          ports:
            - containerPort: 1234
            - containerPort: 5678
          imagePullPolicy: Always
          args:
            - run
            - --config
            - /var/config/my-file.yaml 
  revisionHistoryLimit: 1

</code></pre>

<p>You are using <code>subPath</code> in the volume mount section. According to Kubernetes <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer">volume doc</a>, when you need same volume for different purpose in the same pod then you should use <code>subPath</code>.</p>
<p>But here you are using the volume for only single use. But I'll give you both yaml file with subPath and without subPath.</p>
<p><b>With SubPath</b></p>
<pre><code>          volumeMounts:
            - name: my-secret-volume
              mountPath: /var/config
              subPath: config
              readOnly: true
</code></pre>
<p><b>WithOut SubPath</b></p>
<pre><code>          volumeMounts:
            - name: my-secret-volume
              mountPath: /var/config
              readOnly: true
</code></pre>
<p>Rest of the manifest file will be same in both cases.</p>
