<p>I want to create a simple Secret API Object in K8S that its data comes from a file, for example:</p>
<pre><code>kubectl create secret generic mongo-key --from-file=mongodb-keyfile
</code></pre>
<p>But I want to create it using a config file instead of a direct kubectl command, like this:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mongo-key
type: Opaque
stringData:
  # how to convert the above mentioned --from-file
  # to here? so it will be something like this: 
  # fromFile: './mongodb-keyfile' or something
</code></pre>

<p>You can add a read-only volume mount that references a directory. Then, the keys of your secrets will reference files in that mounted path. <a href="https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-files-from-a-pod" rel="nofollow noreferrer">Here</a> are some docs.</p>
<p>Alternatively, you can rely on a templating (for example with Helm), and then have your build environment read the file and set the value as <code>stringData</code>.</p>
