Using ConfigMap via environment variables

To use ConfigMap inside a pod, you'll have to use configMapKeyRef as the value source in the env section. This will populate whole ConfigMap pairs to environment variables:

# cat 3-2-3_pod_ev_configmap.yaml
apiVersion: v1

kind: Pod
metadata:
name: configmap-ev
spec:
containers:
- name: configmap
image: centos
command: ["/bin/sh", "-c", "while : ;do echo $DATABASE_ENDPOINT; sleep 10; done"]
env:
- name: DATABASE_ENDPOINT
valueFrom:
configMapKeyRef:
name: example
key: database.properties
// create configmap
# kubectl create -f 3-2-3_pod_ev_configmap.yaml
pod/configmap-ev created
// check out the logs
# kubectl logs configmap-ev
endpoint=k8s.us-east-1.rds.amazonaws.com port=1521

The Kubernetes system itself also uses ConfigMap to do some authentication. Check out the system ConfigMap by adding --namespace=kube-system in the kubectl describe configmap command.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset