StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 4 · Namespaces & Resource Organization

Tenant Estate Setup

easyNamespacesMulti-Tenant Organization—No data yet

Problem statement

Three tenant teams - atlas, borealis and cypress - move onto the cluster in the same week. Each needs its own space, its own copy of the shared stack under the same names everyone else uses, day-to-day operations that cannot land in the wrong tenant by accident, and a way out that leaves nothing behind. estate.sh does nothing yet.

The namespace estate-shared holds the reference copy of the stack - one storefront pod and one storefront-config ConfigMap. It is not a tenant. Leave it alone.

About this exercise

This brings together the topic's three exercises:

  • Namespaces - one space per tenant, the same object names in each, and a delete that cascades (Namespace Basics)
  • Scoping - every operation naming its namespace, on the command or through the context, and the difference between namespaced and cluster-scoped kinds (Context & Scoping Discipline)
  • Per-copy identity - a label that says which tenant an object belongs to, so a copy can be found and attributed wherever it is (Per-Environment Stacks)

An estate is what those three become when there is more than one of everything: names collide by design and the namespace is what keeps them apart, so a tool that operates on the estate has to say which tenant it means on every single call - and there are exactly two honest ways to say it. An inventory has the same obligation in reverse: a list of object names means nothing without the namespace each name came from.

kubectl config --help, kubectl get --help and kubectl run --help are the reference for the flags.

How this project is graded

The grader runs estate.sh itself - the inventory, the per-tenant query, and both placement commands - and checks the live cluster after each one: which namespace the object landed in, what your current context records, and what the inventory attributes to whom. It also creates a scratch tenant of its own, evicts it with your tool, and waits for the cascade before checking that the three real tenants are still Running. Namespace deletion is asynchronous, so nothing is assumed to be instant. The pods the tool creates are removed by the grader afterwards; nothing else in your estate is touched.

What you will build

The estate, and one tool that operates on it:

namespace tenant-atlas, tenant-borealis, tenant-cypress
  each labelled  tenant=<atlas|borealis|cypress>

in EACH tenant namespace: pod storefront image nginx:alpine labels app=storefront, tenant=<tenant> configmap storefront-config key tenant = <tenant> label tenant=<tenant>

estate.sh <command> [tenant] tenant is the bare name: atlas, borealis, cypress the namespace it means is tenant-<name>

estate.sh inventory INVENTORY <namespace> <name> one line per pod and per configmap carrying a tenant label, in the tenant namespaces only, sorted SCOPES <resource> namespaced one line for each of exactly these six resource names: <resource> cluster configmaps, namespaces, nodes, persistentvolumes, pods, services each marked with the scope the API reports for that kind

estate.sh show <tenant> <name> <tenant> one line per pod and per configmap carrying a tenant label in that tenant's namespace, sorted - the second field is the object's own tenant label, read off the object

estate.sh place <tenant> creates pod probe, image busybox:1.36, any long-running command, in that tenant's namespace, with the namespace named on the command itself

estate.sh adopt <tenant> points the current context's default namespace at that tenant's namespace, then creates pod adopted, image busybox:1.36, any long-running command, with NO namespace named anywhere on the command

estate.sh evict <tenant> deletes that tenant's namespace, and with it everything inside

The tests

  • Namespaces_tenant_namespaces_exist_and_are_labelled - three namespaces, each carrying its tenant label
  • Namespaces_identical_object_names_coexist_across_tenants - one set of names, three separate copies
  • Inventory_attributes_every_object_to_its_tenant - every object listed with the namespace it came from, and no one else's
  • Inventory_partitions_kinds_by_scope - the six kinds split by what the API says about each
  • Scoping_per_tenant_query_returns_only_that_tenant - one tenant asked for, one tenant answered
  • Scoping_explicit_namespace_flag_places_only_in_target - the placement lands where the command said and nowhere else
  • Scoping_context_default_routes_unflagged_operations - the context is set, and an unflagged create follows it
  • Eviction_removes_exactly_the_evicted_tenant - the evicted tenant cascades away, the others keep Running
  • Composition_tooling_reads_the_estate_on_every_run - a second run reports what changed, rather than repeating itself

Step 1 - move the tenants in

Create the three namespaces with their labels, and give each one its own copy of the stack.

Namespaces_tenant_namespaces_exist_and_are_labelled and Namespaces_identical_object_names_coexist_across_tenants should pass

Step 2 - the estate inventory

Teach estate.sh to report the estate: every tenant object attributed to its namespace, and the six resource names split by scope.

Inventory_attributes_every_object_to_its_tenant, Inventory_partitions_kinds_by_scope and Composition_tooling_reads_the_estate_on_every_run should pass

Step 3 - operations that cannot miss

Teach it to answer for one tenant, and to place a pod two ways: once with the namespace on the command, once through the context default. Both must land in the tenant asked for and in no other.

Scoping_per_tenant_query_returns_only_that_tenant, Scoping_explicit_namespace_flag_places_only_in_target and Scoping_context_default_routes_unflagged_operations should pass

Step 4 - the way out

Teach it to evict a tenant. The grader will try this on a scratch tenant of its own, and expects the three real ones untouched.

Eviction_removes_exactly_the_evicted_tenant should pass

When every test passes

You have:

  • Three tenants sharing one set of object names without ever colliding
  • One tool whose every operation names the tenant it means, explicitly or through a context you set on purpose
  • An inventory that says who owns what, and which kinds have an owner at all
  • An eviction that removes one tenant completely and disturbs nobody else

Verify

Click Test.

More in Namespaces & Resource Organization

See the module
Namespace BasicsGive three environments a namespace each, put the same object names in all of them, list within and across namespaces, and delete a namespace to see the cascade.—No data yeteasyContext & Scoping DisciplineMake every command say which namespace it means - explicit flags, a deliberate context default, namespaced versus cluster-scoped kinds, and the wall a ConfigMap reference cannot cross.—No data yeteasyPer-Environment StacksRun one application three times over - dev, staging and prod in their own namespaces under identical names, each labelled for its environment, and tear one down without touching the rest.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.