Problem statement
The storefront API still carries its own configuration: the log level, the feature switches and the properties file are all inside the image, so the only way to change a timeout is to build and ship a new one. Take all of it out. Namespace storefront-config is empty, the two files the service reads at boot are in config/, and nothing runs there yet.
About this exercise
This brings together the topic's three exercises:
- Sources - configuration held in ConfigMaps built from literals and from whole files, read back from the API and changed one key at a time (Literal & File ConfigMaps)
- Environment - single keys as named variables, a whole map behind a prefix, and the difference a required reference makes against an optional one (Env From ConfigMaps)
- Files - a map presented as a directory, selected keys placed at chosen paths and permission bits (ConfigMap Volumes)
One container consumes all of it at once, which is where the two injection styles stop looking interchangeable. Environment variables are resolved when the container starts and are frozen for its lifetime; a mounted volume is kept in sync by the kubelet, so a change to the object reaches the running process without a restart. The sync is periodic rather than instant - allow up to two minutes. The last step is the drill that shows both halves of that at the same moment: one edit, two different outcomes inside one running container.
kubectl create configmap --help, kubectl explain pod.spec.containers.env, kubectl explain pod.spec.containers.envFrom and kubectl explain pod.spec.volumes.configMap are the reference.
How this project is graded
The grader reads the ConfigMaps out of the live cluster and compares them against the values and source files below, byte for byte. It then asserts from inside the running container - the process environment it really has, the files that really exist at each mount path, their contents and their permission bits - so nothing counts because your manifest says so. For the pod that cannot start it reads the status the cluster recorded and compares it against the reason you saved. The update is re-read in a bounded wait loop. Nothing you create is modified or removed by the grader.
What you will build
Three ConfigMaps, two pods and one answer file in namespace storefront-config:
ConfigMap storefront-settings from literals
log.level info (later: debug)
max.retries 4
ConfigMap storefront-flags from literals
BETA_CHECKOUT on
NEW_PRICING off
DARK_MODE on
ConfigMap storefront-files from the files in config/
app.properties the full contents of config/app.properties
routes.json the full contents of config/routes.json
Pod storefront-api container name: app, image busybox:1.36, stays alive
LOG_LEVEL from key log.level of storefront-settings
every key of storefront-flags, each prefixed FLAG_
AUDIT_MODE from key audit.mode of ConfigMap audit-settings, optional
audit-settings does not exist and you must not create it
/etc/storefront the WHOLE of storefront-settings, one file per key
/etc/appfiles one chosen key of storefront-files, and nothing else
app.properties -> path app.conf mode 0444
Pod strict-api container name: app, image busybox:1.36, stays alive
AUDIT_MODE the same reference, required
answers/missing-reason.txt the reason the cluster records for strict-api's
container, exactly that word and nothing else
then: change log.level in storefront-settings from info to debug,
without deleting or recreating storefront-api
Step 1 - the configuration leaves the image
Create the three ConfigMaps. The two settings maps come from literals; storefront-files carries both source files, each key named after its file and holding that file's entire content - every line, nothing trimmed, nothing reformatted.
Sources_every_map_reads_back_exactly_as_defined and Sources_file_key_holds_the_whole_source_file should pass
Step 2 - the app consumes it
Bring storefront-api up. One container carries all of it: the named variable, the whole flag map behind its prefix, the settings map as a directory of files, and the one selected file key at its own path and mode. routes.json is not selected and must not appear under that mount.
Env_named_and_prefixed_values_reach_the_container, Files_whole_map_mounts_every_key_as_a_file and Files_selected_key_mounts_at_its_path_and_mode should pass
Step 3 - required versus optional
storefront-api also refers to audit.mode of audit-settings, a map that is not in the namespace - marked optional, so the pod runs and AUDIT_MODE is simply not in its environment. strict-api makes the identical reference required, and will not start at all. Find what the cluster says about it and save that reason into answers/missing-reason.txt.
Env_optional_reference_lets_the_app_run and Env_missing_required_reference_blocks_the_container should pass
Step 4 - one edit, two outcomes
Change log.level to debug. max.retries must survive it untouched, and storefront-api must not be deleted or recreated. Within the sync window the file under /etc/storefront reads debug; LOG_LEVEL in that same running container still reads info, and will until the pod is replaced.
Sources_updated_key_changes_only_itself, Composition_mounted_file_follows_the_update and Composition_environment_stays_frozen_after_the_update should pass
The tests
- Sources_every_map_reads_back_exactly_as_defined - the three maps hold exactly the defined keys and values
- Sources_file_key_holds_the_whole_source_file - each file-sourced value is its file's entire content, byte for byte
- Sources_updated_key_changes_only_itself - log.level reads debug while everything beside it is unmoved
- Env_named_and_prefixed_values_reach_the_container - the named variable and every prefixed flag, read out of the running process
- Env_missing_required_reference_blocks_the_container - strict-api is held back, and the saved reason is the one the cluster recorded
- Env_optional_reference_lets_the_app_run - the same reference, optional, leaves the pod running and the variable unset
- Files_whole_map_mounts_every_key_as_a_file - the settings directory holds one file per key with its value
- Files_selected_key_mounts_at_its_path_and_mode - the chosen key alone, at its path, with its permission bits
- Composition_mounted_file_follows_the_update - the mounted copy catches up with the edited map, with no restart
- Composition_environment_stays_frozen_after_the_update - the variable in the same container still holds the old value
When every test passes
You have:
- Every setting, switch and configuration file of the service living in the cluster instead of in its image
- One container consuming all three forms at once - a named variable, a prefixed map, a mounted directory
- A missing dependency that is fatal in one form and harmless in the other, seen both ways
- The update drill that tells you which half of your configuration a live edit can reach, and which half needs a new pod
Verify
Click Test.
