[Create a ConfigMap from a directory]
$ mkdir -p configure-pod-container/configmap/

[Download the sample files into `configure-pod-container/configmap/` directory]
$ wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties
$ wget https://kubernetes.io/examples/configmap/ui.properties -O configure-pod-container/configmap/ui.properties

[Create the ConfigMap]
$ kubectl create configmap game-config --from-file=configure-pod-container/configmap/

$ kubectl describe configmaps game-config

$ kubectl get configmaps game-config -o yaml

[Create a ConfigMaps from files]
$ kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties --from-file=configure-pod-container/configmap/ui.properties

$ kubectl describe configmaps game-config-2

$ wget https://kubernetes.io/examples/configmap/game-env-file.properties -O configure-pod-container/configmap/game-env-file.properties
$ wget https://kubernetes.io/examples/configmap/ui-env-file.properties -O configure-pod-container/configmap/ui-env-file.properties
$ cat configure-pod-container/configmap/game-env-file.properties
enemies=aliens
lives=3
allowed="true"

$ kubectl create configmap game-config-env-file --from-env-file=configure-pod-container/configmap/game-env-file.properties

$ kubectl get configmap game-config-env-file -o yaml

$ kubectl create configmap config-multi-env-files --from-env-file=configure-pod-container/configmap/game-env-file.properties --from-env-file=configure-pod-container/configmap/ui-env-file.properties

$ kubectl get configmap config-multi-env-files -o yaml

$ kubectl create configmap game-config-3 --from-file=game-special-key=configure-pod-container/configmap/game.properties

$ kubectl get configmaps game-config-3 -o yaml

[Create a ConfigMaps from literal values]
$ kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm

$ kubectl get configmaps special-config -o yaml

$ kubectl delete configmap special-config


➤ Define container environment variables using ConfigMap data

$ kubectl create configmap special-config --from-literal=special.how=very

$ kubectl create -f pod-env_1.yaml
$ kubectl create -f https://kubernetes.io/examples/pods/pod-single-configmap-env-variable.yaml

Now, the Pods output includes environment variable "SPECIAL_LEVEL_KEY=very".


➤ Define container environment variables with data from multiple ConfigMaps

[Create the ConfigMap]
$ kubectl create -f ConfigMap_1.yaml
$ kubectl create -f https://kubernetes.io/examples/configmap/configmaps.yaml

[Create the Pod]
$ kubectl create -f pod-env_2.yaml
$ kubectl create -f https://kubernetes.io/examples/pods/pod-multiple-configmap-env-variable.yaml

Now, the Pods output includes environment variables "SPECIAL_LEVEL_KEY=very" and "LOG_LEVEL=INFO".

[Delete that Pod]
$ kubectl delete pod dapi-test-pod --now

[Delete the ConfigMaps]
$ kubectl delete configmap special-config
$ kubectl delete configmap env-config


➤ Configure all key-value pairs in a ConfigMap as container environment variables

[Create the ConfigMap]
$ kubectl create -f ConfigMap_2.yaml
$ kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml

[Create the Pod]
$ kubectl create -f pod-envFrom.yaml
$ kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-envFrom.yaml

Now, the Pods output includes environment variables "SPECIAL_LEVEL=very" and "SPECIAL_TYPE=charm".

[Delete that Pod]
$ kubectl delete pod dapi-test-pod --now


➤ ConfigMap-defined environment variables in Pod commands

[Create that Pod]
$ kubectl create -f pod-env_3.yaml
$ kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-env-var-valueFrom.yaml

$ kubectl logs dapi-test-pod
very charm

[Delete that Pod]
$ kubectl delete pod dapi-test-pod --now


➤ Add a ConfigMap data to a Volume

[Create the ConfigMap]
$ kubectl create -f ConfigMap_2.yaml
$ kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml

[Create the Pod]
$ kubectl create -f pod-volume_1.yaml
$ kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-volume.yaml

When the pod runs, the command ls /etc/config/ produces the output below:
SPECIAL_LEVEL
SPECIAL_TYPE

[Delete that Pod]
$ kubectl delete pod dapi-test-pod --now


➤ Add a ConfigMap data to a specific path in the Volume

[Create the Pod]
$ kubectl create -f pod-volume_2.yaml
$ kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-volume-specific-key.yaml

When the pod runs, the command cat /etc/config/keys produces the output below:
very

[Delete that Pod]
$ kubectl delete pod dapi-test-pod --now

[Delete the ConfigMaps]
$ kubectl delete configmaps/special-config configmaps/env-config
$ kubectl delete configmaps/game-config configmaps/game-config-2 configmaps/game-config-3 configmaps/game-config-env-file

If created a directory configure-pod-container and no longer need it, should remove that too, or move it into the trash can / deleted files location.
$ rm -r configure-pod-container
