Pod environment vars from configmap
Create a configmap:
kubectl create configmap env-config \ --from-literal=ENV_VAR_1=FOO --from-literal=ENV_VAR_2=BAR
Create a pod to use this config map
cat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: test-pod spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh", "-c", "env" ] envFrom: - configMapRef: name: env-config restartPolicy: Never EOF
This pod will print it's env and then exit
View the pod env variables with:
kubectl logs test-pod -c test-container
This will provide something similar to the following output:
KUBERNETES_PORT=tcp://10.96.0.1:443 KUBERNETES_SERVICE_PORT=443 HOSTNAME=test-pod SHLVL=1 HOME=/root EXAMPLE_SERVICE_PORT_8080_TCP_ADDR=10.100.105.233 EXAMPLE_SERVICE_SERVICE_HOST=10.100.105.233 EXAMPLE_SERVICE_PORT_8080_TCP_PORT=8080 ENV_VAR_1=FOO ENV_VAR_2=BAR EXAMPLE_SERVICE_PORT_8080_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1 EXAMPLE_SERVICE_PORT=tcp://10.100.105.233:8080 EXAMPLE_SERVICE_SERVICE_PORT=8080 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin KUBERNETES_PORT_443_TCP_PORT=443 KUBERNETES_PORT_443_TCP_PROTO=tcp EXAMPLE_SERVICE_PORT_8080_TCP=tcp://10.100.105.233:8080 KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443 PWD=/ KUBERNETES_SERVICE_HOST=10.96.0.1