Skip to content

Instantly share code, notes, and snippets.

@raprasad
Created June 1, 2018 15:53
Show Gist options
  • Save raprasad/a195ad5fea7eb7c757ef8df3ffc94cf5 to your computer and use it in GitHub Desktop.
Save raprasad/a195ad5fea7eb7c757ef8df3ffc94cf5 to your computer and use it in GitHub Desktop.
secrets from file; to env variable

example of putting file contents in a secrets

@cloudshell:~ (raven2-186120)$ echo husky > dogs.txt

@cloudshell:~ (raven2-186120)$  kubectl create secret generic test-env-variable --from-file=TEST_ENV_VARIABLE=./dogs.txt                                                      
secret "test-env-variable" created


@cloudshell:~ (raven2-186120)$ kubectl get secrets
NAME                  TYPE                                  DATA      AGE
apikey                Opaque                                1         23h
default-token-j9xm1   kubernetes.io/service-account-token   3         197d
test-env-variable     Opaque                                   1         19h

@cloudshell:~ (raven2-186120)$ kubectl get secret test-env-variable -o yaml
apiVersion: v1
data:
  TEST_ENV_VARIABLE: aHVza3kK
kind: Secret
metadata:
  creationTimestamp: 2018-06-01T15:43:37Z
  name: test-env-variable
  namespace: default
  resourceVersion: "22992407"
  selfLink: /api/v1/namespaces/default/secrets/test-env-variable
  uid: 8cfd80a2-65b2-11e8-9157-42010a800057
type: Opaque

@cloudshell:~ (raven2-186120)$ echo 'aHVza3kK' | base64 --decode
husky

in yml file

For the appropriate container, read the contents from the secret

         name: TEST_ENV_VARIABLE
           valueFrom:
             secretKeyRef:
               name: test-env-variable
               key: TEST_ENV_VARIABLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment