<p>As the title says, im trying to mount a secret, as a volume, into a deployment.</p>
<p>I found out i can do it in this way if <code>kind: Pod</code> but couldnt replicate it on <code> kind: Deployment</code></p>
<pre><code>apiVersion: apps/v1
kind: Deployment

volumeMounts:
     - name: certs-vol
       mountPath: &quot;/certs&quot;
       readOnly: true
volumes:
      - name: certs-vol
        secret:
        secretName: certs-secret
</code></pre>
<p>the error shows as follows <code>ValidationError(Deployment.spec.template.spec.volumes[1]): unknown field &quot;secretName&quot; in io.k8s.api.core.v1.Volume, ValidationError(Deployment.spec.template.spec.volumes[2]</code></p>
<p>is there a way to do this, exclusivelly on deployment?</p>

<p>As <a href="https://stackoverflow.com/users/10008173/david-maze">David Maze</a> mentioned in the comment:</p>
<blockquote>
<p>Does  <code>secretName:</code>  need to be indented one step further (a child of  <code>secret:</code>)?</p>
</blockquote>
<p>Your yaml file should be as follow:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment

volumeMounts:
     - name: certs-vol
       mountPath: &quot;/certs&quot;
       readOnly: true
volumes:
      - name: certs-vol
        secret:
          secretName: certs-secret
</code></pre>
<p>You can read more about <a href="https://medium.com/avmconsulting-blog/secrets-management-in-kubernetes-378cbf8171d0" rel="nofollow noreferrer">mounting secret as a file</a>. This could be the most interesing part:</p>
<blockquote>
<p>It is possible to create  <code>Secret</code>  and pass it as a  <strong>file</strong>  or multiple  <strong>files</strong>  to  <code>Pods</code>.<br />
I've created a simple example for you to illustrate how it works. Below you can see a sample  <code>Secret</code>  manifest file and  <code>Deployment</code>  that uses this Secret:<br />
<strong>NOTE:</strong>  I used  <code>subPath</code>  with  <code>Secrets</code>  and it works as expected.</p>
</blockquote>
<pre><code>apiVersion: v1  
kind: Secret  
metadata:  
  name: my-secret  
data:  
  secret.file1: |  
    c2VjcmV0RmlsZTEK  
  secret.file2: |  
    c2VjcmV0RmlsZTIK  

---  

apiVersion: apps/v1  
kind: Deployment  
metadata:  
...  
    spec:  
      containers:  
      - image: nginx  
        name: nginx  
        volumeMounts:  
        - name: secrets-files  
          mountPath: &quot;/mnt/secret.file1&quot;  # &quot;secret.file1&quot; file will be created in &quot;/mnt&quot; directory  
          subPath: secret.file1  
        - name: secrets-files  
          mountPath: &quot;/mnt/secret.file2&quot;  # &quot;secret.file2&quot; file will be created in &quot;/mnt&quot; directory  
          subPath: secret.file2  
      volumes:  
        - name: secrets-files  
          secret:  
            secretName: my-secret # name of the Secret

</code></pre>
<blockquote>
<p><strong>Note:</strong>  <code>Secret</code>  should be created before  <code>Deployment</code>.</p>
</blockquote>
