Problem statement
Dev and staging are the same application, so they were given the same object names, and because there is only one namespace - shop-shared - there is only one storefront. Every dev experiment overwrites the staging copy, and rolling one back rolls back the other. Give each environment a namespace and the collision disappears: the names stay the same, and there are three of them.
About this exercise
Running one application several times over is the ordinary reason namespaces exist. Because names are unique per namespace and not per cluster, the same manifests apply cleanly into shop-dev, shop-staging and shop-prod; each apply produces a distinct object, and none of them can see or overwrite the others. What changes between the copies is not the names but the namespace they live in, plus the values that make each copy say which environment it is.
Two things make a copy addressable once there are three of them:
- The namespace answers "which copy" for any single command: a namespaced listing shows one environment and never leaks a neighbour's rows.
- A label - a key/value pair carried on the object - answers "which copies" across the cluster: environment=prod selects the prod copy wherever it is, and a listing that crosses namespaces can be filtered down to it. Labels are metadata the object carries; deleting the environment deletes the objects that carry the label.
Tearing an environment down is the same cascade you already know: delete the namespace, and the namespaced objects inside it go with it, while the other namespaces are untouched. Deletion is asynchronous - the namespace reports Terminating while the contents are removed.
kubectl run --help, kubectl get --help and kubectl create configmap --help are the reference for the flags. The seeded shop-shared holds the single contested storefront pod; leave it alone.
How this project is graded
The grader compares the live cluster with your saved listings: the copies must exist in their own namespaces with their own label values, each listing must show only what it claims to show, and after the teardown the surviving environments must still be Running. Namespace deletion is asynchronous, so the grader waits for it rather than assuming.
What you will build
The same two objects in three namespaces, three listings, and one teardown:
in EACH of shop-dev, shop-staging and shop-prod:pod storefront image nginx:alpine labels app=storefront environment=<dev|staging|prod>, matching the namespace configmap storefront-config key environment = <dev|staging|prod>, matching the namespace
answers/three-up.txt every storefront pod in the cluster with the namespace named on each row, taken while all three environments are up answers/labels.txt one line per environment, "<namespace> <environment label value>", read back from the pod in that namespace - three lines, in any order answers/prod-only.txt every pod and configmap of the prod copy, that namespace only
then: tear down the dev environment - the namespace, not the objects one by one - leaving shop-staging and shop-prod running
Step 1 - three copies, one set of names
Stand the same pod and configmap up in all three namespaces, each copy labelled and configured for its own environment.
three_environments_stood_up_at_once and identical_names_run_side_by_side should pass
Step 2 - address one copy at a time
Save the three listings. prod-only.txt must contain the prod copy and no trace of another environment; labels.txt must read the label back off each pod in its own namespace.
each_environment_is_addressable_on_its_own, label_readback_shows_each_environment and label_query_returns_only_that_environment should pass
Step 3 - remove one environment
Tear down shop-dev. Nothing in shop-staging or shop-prod may be touched, and both must still be Running when you are done.
tearing_down_dev_leaves_the_others_running should pass
When every test passes
You have:
- Three copies of one application under one set of names, none of them able to overwrite another
- A per-environment label that selects a copy no matter which namespace it is in
- Listings that show one environment without leaking the others
- A teardown that removes an environment and nothing else
You do not have yet:
- A repeatable way to do this for people who are not you. Building the estate and the tooling for several tenants at once is the next exercise.
Verify
Click Test after every step.
