Problem statement
This service reads nothing from its environment. It opens /etc/appconf/app.properties at boot and re-reads it later, which is why the whole configuration directory is currently copied into the image at build time - and why a one-word change still costs a rebuild. Namespace appconf-files already holds the ConfigMap app-config with four keys; no pod consumes it yet.
About this exercise
A ConfigMap can be presented to a container as a volume: a directory the kubelet builds and mounts, where each key becomes a file whose name is the key and whose content is the value. A program that only knows how to read files needs no changes at all - the directory just appears at the mount path you choose.
You are not forced to take the whole map. A volume can instead list items: the specific keys you want, each with the path it should appear under inside the mount - a path, so a key can be renamed, or placed in a subdirectory. Keys you do not list are simply not there. Each item can also carry a mode, the permission bits of the file the kubelet writes, which is how a file with a secret-ish value ends up readable only by its owner. Note that the mount path's entries are managed by the kubelet: what appears there is a rendered view of the map, and anything else in that directory is replaced by it.
The important difference from environment injection is when the values are resolved. Environment variables are computed once, when the container starts, and nothing can change them afterwards - a pod restart is the only way. A mounted volume is different: the kubelet keeps it in sync with the object, so editing the ConfigMap updates the files in the running container, without a restart. That sync is periodic, not instant - allow up to two minutes for a change to appear.
kubectl explain pod.spec.volumes.configMap and kubectl explain pod.spec.containers.volumeMounts are the reference.
How this project is graded
The grader inspects the container's own filesystem - the files that exist at each mount path, their contents compared byte for byte against the ConfigMap's values, and their permission bits. For the update it re-reads the mounted file in a bounded wait loop, and reads the process environment of the same still-running container to compare. Nothing you create is modified by the grader.
What you will build
One pod in namespace appconf-files running busybox:1.36 and staying alive, and one change to the ConfigMap:
Pod file-reader container name: app/etc/appconf the WHOLE of ConfigMap app-config one file per key, named after the key /etc/selected two chosen keys of app-config, and nothing else app.properties -> path settings/app.conf mode 0444 banner.txt -> path motd mode 0400 RELEASE_CHANNEL from key release.channel of app-configthen: change release.channel in app-config from stable to canary
Step 1 - the whole map as a directory
Bring file-reader up with app-config mounted at /etc/appconf. All four keys are files there, each holding its value exactly - including the multi-line ones.
whole_map_mounts_every_key_as_a_file and mounted_files_carry_the_map_values should pass
Step 2 - only what you asked for, exactly where you asked for it
Mount the same map a second time at /etc/selected, this time listing only the two keys above, each at its own path and with its own mode. routes.json and release.channel must not exist under that path.
selected_items_mount_only_the_chosen_keys and selected_files_carry_the_defined_modes should pass
Step 3 - change the map, watch what moves
Change release.channel to canary in app-config. Do not delete or restart the pod. Within the sync window the mounted file under /etc/appconf reads canary; RELEASE_CHANNEL in that same container still reads stable, and will until the pod is recreated.
map_update_reaches_the_mounted_file and env_value_does_not_move_with_the_map should pass
When every test passes
You have:
- A configuration directory served by the cluster instead of baked into the image
- Selected keys placed at the paths and permissions a program expects
- A live demonstration of which injection follows the map and which one freezes at container start
You do not have yet:
- An application actually wired end to end. Putting all of it together - settings, flags, a config file and the update drill - is the next exercise.
Verify
Click Test after every step.
