I want to store files in Kubernetes Secrets but I haven't found how to do it using a yaml
file.
I've been able to make it using the cli with kubectl
:
kubectl create secret generic some-secret --from-file=secret1.txt=secrets/secret1.txt
But when I try something similar in a yaml
:
apiVersion: v1
kind: Secret
metadata:
name: some-secret
type: Opaque
data:
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 yaml
but not how to create a secret from a file using yaml
.
Is it possible? If so, how can I do it?
When using the CLI
format you're using a generator of the YAML before posting it to the server-side.
Since Kubernetes is a client-server app with a REST API in between, and all actions need to be atomic, the posted YAML needs to contain the content of the linked file(s), and the best way to do that is by embedding them in base64 encoded 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 working examples of that.
That said, putting a file reference on the YAML is not possible, there is no pre-flight rendering of the YAML to include the content.