Raz Buchnik
Raz Buchnik

Reputation: 8411

How to create secret with data from file?

I want to create a simple Secret API Object in K8S that its data comes from a file, for example:

kubectl create secret generic mongo-key --from-file=mongodb-keyfile

But I want to create it using a config file instead of a direct kubectl command, like this:

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

Upvotes: 1

Views: 2944

Answers (1)

Emile P.
Emile P.

Reputation: 3962

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. Here are some docs.

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 stringData.

Upvotes: 1

Related Questions