This example assumes you have a Kubernetes cluster installed and running, and that you have
installed the kubectl command line tool somewhere in your path. Please see the getting
started for installation instructions for your platform.
A ConfigMap contains a set of named strings.
Use the configmap.yaml file to create a ConfigMap:
$ kubectl create -f docs/user-guide/configmap/configmap.yamlYou can use kubectl to see information about the ConfigMap:
$ kubectl get configmap
NAME DATA AGE
test-configmap 2 6s
$ kubectl describe configMap test-configmap
Name: test-configmap
Labels: <none>
Annotations: <none>
Data
====
data-1: 7 bytes
data-2: 7 bytesView the values of the keys with kubectl get:
$ kubectl get configmaps test-configmap -o yaml
apiVersion: v1
data:
data-1: value-1
data-2: value-2
kind: ConfigMap
metadata:
creationTimestamp: 2016-02-18T20:28:50Z
name: test-configmap
namespace: default
resourceVersion: "1090"
selfLink: /api/v1/namespaces/default/configmaps/test-configmap
uid: 384bd365-d67e-11e5-8cd0-68f728db1985Use the env-pod.yaml file to create a Pod that consumes the
ConfigMap in environment variables.
$ kubectl create -f docs/user-guide/configmap/env-pod.yamlThis pod runs the env command to display the environment of the container:
$ kubectl logs config-env-test-pod | grep KUBE_CONFIG
KUBE_CONFIG_1=value-1
KUBE_CONFIG_2=value-2Use the command-pod.yaml file to create a Pod with a container
whose command is injected with the keys of a ConfigMap
$ kubectl create -f docs/user-guide/configmap/command-pod.yamlThis pod runs an echo command to display the keys:
$ kubectl logs config-cmd-test-pod
value-1 value-2Pods can also consume ConfigMaps in volumes. Use the volume-pod.yaml file to create a Pod that consume the ConfigMap in a volume.
$ kubectl create -f docs/user-guide/configmap/volume-pod.yamlThis pod runs a cat command to print the value of one of the keys in the volume:
$ kubectl logs config-volume-test-pod
value-1Alternatively you can use mount-file-pod.yaml file to mount
only a file from ConfigMap, preserving original content of /etc directory.