dgil dgil -4 years ago 319
YAML Question

How to set secret files to kubernetes secrets by yaml?

I want to store files in Kubernetes Secrets but I haven't found how to do it using a


I've been able to make it using the cli with

kubectl create secret generic some-secret --from-file=secret1.txt=secrets/secret1.txt

But when I try something similar in a

apiVersion: v1
kind: Secret
name: some-secret
type: Opaque
secret1.txt: secrets/secret1.txt

I´ve got this error:

[pos 73]: json: error decoding base64 binary 'assets/elasticsearch.yml': illegal base64 data at input byte 20

I'm following this guide http://kubernetes.io/docs/user-guide/secrets/. It explains how to create a secret using a
but not how to create a secret from a file using

Is it possible? If so, how can I do it?

Answer Source

When using the CLI format basically you're using a generator of the yaml before posting it to the server-side.

Since Kubernetes is client-server app with REST API in between, and the actions need to be atomic, the posted YAML needs to contain the content of the file, and best way to do that is by embedding it as a base64 format in-line. It would be nice if the file could be otherwise embedded (indentation maybe could be used to create the boundaries of the file), but I haven't seen any example of such until now.

That being said, putting a file reference on the yaml is not possible, there is no pre-flight rendering of the yaml to include the content.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download