Problem statement
Every team ships into the same place. The namespace shared-workspace holds whatever anyone happened to create there, and it is the only place anything lives, so a name that is already taken is somebody else's problem: two teams cannot both have a checkout, nobody can list "just ours", and deleting a team's leftovers means picking their objects out of the pile by hand. Give three environments a namespace each and watch what changes.
About this exercise
A namespace is the scope Kubernetes keeps most objects in. Two facts follow from it, and everything in this exercise is one of the two:
- Names are unique per namespace, not per cluster. A pod called checkout in one namespace and a pod called checkout in another are two different objects with two different UIDs. They do not overwrite each other, and neither one can see the other.
- Almost every command is namespace-scoped. A listing shows one namespace at a time - by default whichever one your context points at - which is why an object you know exists can look missing. Listings also have a form that crosses every namespace at once, and that form has to say which namespace each row came from, so it prints the namespace as a column of its own.
Objects come in two flavours. Namespaced kinds - pods, ConfigMaps, Services - live inside a namespace and are deleted with it: deleting a namespace is a cascade, not a rename, and the API marks the namespace Terminating while it removes the contents. Cluster-scoped kinds - nodes, namespaces themselves - belong to no namespace at all.
kubectl create --help, kubectl get --help and kubectl delete --help are the reference for the flags.
shared-workspace is seeded with two pods, web and worker. Leave them alone; they are there so a cluster-wide listing has more than one namespace to attribute.
How this project is graded
The grader compares the live cluster with your saved listings: the objects must exist in the namespaces they belong to and nowhere else, and the listings must be the real output of the commands that produced them. Re-running the tests does not reset your work.
What you will build
Three namespaces, the objects inside them, and three listings in answers/:
namespace platform-dev pod checkout image nginx:alpine configmap app-settings key environment = devnamespace platform-staging pod checkout image nginx:alpine pod nightly-batch image busybox:1.36, any long-running command configmap app-settings key environment = staging
namespace platform-scratch pod checkout image nginx:alpine pod spike image busybox:1.36, any long-running command
answers/dev-listing.txt the pods and configmaps of platform-dev, that namespace only answers/all-pods.txt every pod in every namespace, each row naming its namespace answers/scratch-before.txt the pods of platform-scratch, taken before you delete it answers/after-delete.txt the namespace listing, taken after you delete platform-scratch
Step 1 - a namespace per environment
Create the three namespaces, then create each object listed above inside the namespace it is listed under. The same pod name appears in all three; that is the point.
namespaces_exist_and_are_active, objects_created_in_each_namespace and same_object_name_coexists_in_two_namespaces should pass
Step 2 - list within, and list across
Save the two listings. The first must show platform-dev and nothing else - nightly-batch lives next door and must not appear in it. The second must cover every namespace in the cluster and attribute each pod to the namespace it is in.
namespaced_listing_shows_only_that_namespace and all_namespaces_listing_attributes_each_object should pass
Step 3 - delete a namespace and watch the cascade
Record what platform-scratch contains - both of its pods - then delete the namespace itself, not the pods inside it. Save the namespace listing afterwards. The namespace may still be Terminating when you look; that is the cascade running.
scratch_namespace_held_its_own_copy and deleting_the_namespace_removes_its_objects should pass
When every test passes
You have:
- One namespace per environment, each with its own copy of the same names
- A listing that answers "just ours" instead of showing the whole cluster
- A cluster-wide listing that says which namespace every object came from
- A one-command teardown that takes an environment's objects with it
You do not have yet:
- Any protection against running the right command in the wrong namespace. Scoping every command deliberately is the next exercise.
Verify
Click Test after every step.
