May 2018
Intermediate to advanced
554 pages
13h 51m
English
In terms of accessing Secrets inside a Pod, add env section inside the container spec as follows:
// using access-token Secret inside a Pod# cat 2-7-2_env.yamlapiVersion: v1kind: Podmetadata: name: secret-example-envspec: containers: - name: ubuntu image: ubuntu command: ["/bin/sh", "-c", "while : ;do echo $ACCESS_TOKEN; sleep 10; done"] env: - name: ACCESS_TOKEN valueFrom: secretKeyRef: name: access-token key: 2-7-1_access-token// create a pod# kubectl create -f 2-7-2_env.yamlpod "secret-example-env" created
In the preceding example, we expose 2-7-1_access-token key in access-token Secret as ACCESS_TOKEN environment variable, and print it out through a while infinite loop. Check the stdout via kubectl log command: ...