ConfigMaps: Environment Variables and Volume Mounts
There are three ways to create a ConfigMap and four ways to consume one, and CKAD tasks use all of them. This puts every consumption style into a single Pod so they can be compared in one log, then shows the failure a missing key produces - a status that is neither Running nor CrashLoopBackOff and that names the exact key it could not find.
Configuration and Security Guide 24 of 44 Beginner
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 16 min
--from-env-file reads KEY=value lines and makes one ConfigMap key per line; --from-file makes ONE key whose name is the filename and whose value is the whole file. Mixing those two up is the usual reason a mounted config file arrives as a directory of fragments or a single unusable blob.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when configuration has to reach a container and the task names one particular way. This matters because there are three ways to create a ConfigMap and four ways to consume one - and a missing key fails differently depending on which you chose.
- creating a ConfigMap three ways - from literals, from a file, and from an env-file
- consuming one four ways inside a single Pod, all visible in one log
- referencing a key that does not exist, and seeing the Pod wait rather than crash
- adding
optional: trueto that same reference and watching it start
Before you start
- A cluster and kubectl.
- The session creates namespace
ckad-cmwith three ConfigMaps built three different ways, and four Pods that consume them.
-
Three ways to create one
-
Four ways to consume one
-
The key that is not there
-
optional makes it tolerable