Create a configMap:
kubectl create configmap env-config --from-literal=ENV_VAR_1=FOO --from-literal=ENV_VAR_2=BAR
you can view the result with
kubectl get configmap env-config -o yaml
Create a pod to use this configMap
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
kubectl create -f test-pod.yaml
This pod will print it's env and then exit. You can view the output as follows
kubectl logs test-pod -c test-container
You should see something like...
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
Hey Bob hope your well
ReplyDelete