The docs states that
To create a Secret from one or more files, use --from-file. You specify files in any plaintext format, such as .txt or .env, as long as the files contain key-value pairs.
.test-secret
NAME=martin GENDER=male
Testing to create a secret based on my .test-secret file.
kubectl create secret generic person --from-file .test-secret -o yml $ kubectl get secret person -o yaml apiVersion: v1 data: .test-secret: TkFNRT1tYXJ0aW4KR0VOREVSPW1hbGUK kind: Secret metadata: creationTimestamp: 2018-07-19T09:23:05Z name: person namespace: default resourceVersion: "229992" selfLink: /api/v1/namespaces/default/secrets/person uid: 579198ab-8b35-11e8-8895-42010a840008 type: Opaque
Is it possible to read a list of key / values like that? Is it even possible to do so from an .env
file? kubectl get pods
returns CreateContainerConfigError
my-app.yml
77 - name: NAME 78 valueFrom: 79 secretKeyRef: 80 name: person 81 key: NAME
To create a Kubernetes secret, apply one of the following methods: Use kubectl for a command-line based approach. Create a configuration file for the secret. Use a generator, such as Kustomize to generate the secret.
To use a Secret in an environment variable in a Pod: Create a Secret (or use an existing one). Multiple Pods can reference the same Secret. Modify your Pod definition in each container that you wish to consume the value of a secret key to add an environment variable for each secret key you wish to consume.
When using definition files, you can add the data in a base64 encoded format or plain text form. Kubernetes encodes the Secret data in base64 format. When you need to reveal a Secret text, you must base64-decode it. To enable containers to access Secrets, you have the option to mount the Secret as a volume.
Yes, use the option --from-env-file
kubectl create secret generic person --from-env-file=.test-secret
To consume the secrets from the initial .env file in a pod, you can use the following :
apiVersion: v1 kind: Pod metadata: name: some-meta spec: containers: - name: xyz image: abc envFrom: - secretRef: name: person # <--
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With