Projected Volumes and subPath
Assemble one config directory from a ConfigMap and a Secret with a projected volume, then drop a single file into a directory with subPath — without clobbering what is already there.
Your mission
A container often needs configuration from more than one place at once: some non-secret settings from a ConfigMap, a credential from a Secret, maybe a token. You could give each its own mount path — but then your app has to look in three directories. A projected volume solves this: it merges several sources into a single directory, each key landing as a file side by side.
The second tool here is subPath. Normally, mounting a volume at a path
replaces whatever was at that path — mount a ConfigMap at /etc/nginx and you
wipe every other file nginx shipped. subPath lets you mount one file into an
existing directory instead of the whole volume, leaving the directory's other
contents intact. It is the standard way to drop a single config file into a
populated directory.
In this lab you:
- Build a
/etc/appdirectory from a ConfigMap and a Secret using one projected volume. - Place a single file into
/opt/webwithsubPath, without mounting the whole ConfigMap over that directory.
Useful aliases
In your terminal, k is aliased to kubectl and completion is configured. The
jumpbox also has k9s, jq and yq installed.