During this tutorial you'll learn how to manage ConfigMaps on Kubernetes.
- Level: beginner
- Requirements: none
- Previous Tutorials: deployments
- Can run on Cluster: any
- Can run on Namespace: any
- Images used:
ConfigMaps allow you to decouple configuration from container images, so that your applications are easily portable.
ConfigMaps do not provide secrecy or encryption. If the data you want to store are confidential, use a Secret rather than a ConfigMap.
# Nginx with ConfigMap as Env Variables
We 'll be running an Nginx instance that we'll pass some environment variables, but instead of configuring the environment variables on the same workload (e.g. Deployment) we'll reference them from a ConfigMap.
First let's go and create a ConfigMap with some values.
- Data: [
Now that we have created the ConfigMap, let's create the Nginx instance and configure two environment variables that take their value from the ConfigMap.
- Env: [
Once created we can open a terminal and check the environment variables by running
env. Their values should appear on screen
$ env ... COLOR=blue DAY=monday
# Nginx with ConfigMap as Volume
We can also use ConfigMaps as volumes. We'll re-use the previous ConfigMap and create a new deployment
- Volumes: [
Once created we can open a terminal and check the path
/storage. It should contain two files
DAY, each one with the content of value.
~ # cd /storage/ /storage # ls COLOR DAY /storage # cat COLOR blue /storage # cat DAY monday
Remember to delete the following resources after you finish this tutorial:
- on active namespace: