Is it possible to source a `.env` file to create Kubernetes secrets?

7/19/2018

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
-- martins
kubernetes

1 Answer

7/19/2018

Yes, use the option --from-env-file

kubectl create secret generic person --from-env-file=.test-secret
-- Ignacio Millán
Source: StackOverflow