Kubernetes · Chapter 15 of 28
Namespaces and quotas
By the end of this chapter you can give a team its own namespace, cap what the whole team may use with a ResourceQuota, give its containers default requests and limits with a LimitRange, reach a Service in another namespace by its DNS name, and say why a Deployment under a full quota has no pods at all. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Scheduling and teams
- 4 tasks
- Kubernetes
- In the all labs plan
The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.
Why you need this
Jhatpat opens in Kanpur in March. Kanpur gets a team of its own, four developers led by Tushar, who will deploy their own services to the same cluster as Lucknow. Ritika has one worry: Lucknow takes 2,40,000 orders on Dhanteras, and nothing Kanpur does in testing may take CPU or memory from it. Ammar's answer: Kanpur gets 2 CPUs and 4 GiB of requests, no more, whatever its developers apply.
So far every chapter has its own namespace, and you have used it as a folder. A folder does not stop anyone: a Kanpur developer can scale a Deployment to 40 replicas, or start pods with no requests at all, and the scheduler will place them on the same three workers Lucknow uses. Requests (chapter 12) only help if every pod has them. Nothing you know yet sets a budget for a whole team.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
kanpur.yaml: a namespace for Kanpur, with a quota
The Kanpur team gets its own namespace, with a limit on what it can use.
1. Open kanpur.yaml with nano.
2. Give the Namespace the name ch15-kanpur.
3. Make the ResourceQuota named kanpur live in ch15-kanpur. Write the namespace in its metadata.
4. Give the quota these hard limits: pods 10, requests.cpu 2, requests.memory 4Gi, limits.cpu 4, limits.memory 8Gi.
5. Save the file and run kubectl apply -f kanpur.yaml.
To pass: the namespace ch15-kanpur exists, and the quota kanpur is in ch15-kanpur (not in ch15). The quota has exactly these five limits and no other limit.
- Task 2
limits.yaml: defaults so pods without requests start
Give every new container in ch15-kanpur default requests and limits, so the storefront can start.
1. Run kubectl apply -f kanpur-storefront.yaml. Its pods are refused. Read the events in ch15-kanpur to see why.
2. Open limits.yaml. Make a LimitRange named defaults in ch15-kanpur, with one limit for type Container.
3. Set its defaultRequest to cpu 100m and memory 128Mi. Set its default (the limits) to cpu 500m and memory 256Mi.
4. Apply limits.yaml. Then make new storefront pods: apply kanpur-storefront.yaml again, or restart the rollout.
To pass: the LimitRange defaults has these four values. The Deployment storefront in ch15-kanpur runs jhatpat/storefront:1.2 with 2 replicas. 2 of its pods are ready and got these requests and limits. Pods made before the LimitRange do not count.
- Task 3
kanpur-storefront.yaml: use Lucknow's catalog
Kanpur's storefront must use the catalog Service in the namespace ch15.
1. Open kanpur-storefront.yaml. Find CATALOG_URL.
2. The short name catalog finds nothing in ch15-kanpur. Change the value to an http address with a name that reaches the Service catalog in namespace ch15.
3. Save the file and apply it. Wait for the rollout to finish.
4. Open the page / from inside a storefront pod. It should list Lucknow's products.
To pass: CATALOG_URL uses that name, with no port or port 80. Exactly 2 storefront pods run in ch15-kanpur, both ready, both with the new value. Their page / answers 200 with Lucknow's products.
- Task 4 · interview question
Interview: 0/3 under a full quota
Interview question: a Deployment under a full quota shows 0/3, and there are no pods at all. Why?
1. Open answer.txt. Write below the lines that start with #.
2. In two or three sentences of your own, say why there are no pods, not even Pending ones.
3. Say who refuses the pods, and when.
4. Say where you read why it happened.
To pass: your answer mentions the quota, says what happens to each pod when it is created, and names the object whose events show why. Lines that start with # do not count. Ammar will ask: "The Deployment says 0/3 and there are no pods. Where are they?"
What you will learn
- Namespaces for teams and environments, and which objects live in one.
- ResourceQuota: a cap on pods, requests, limits and object counts in a namespace.
- The real exceeded quota and must specify errors, and where they show up.
- LimitRange: default requests and limits for containers, and maximums.
- DNS across namespaces: name.namespace and the full Service name.
- Deleting a namespace deletes everything in it.
More in Scheduling and teams
Build "Namespaces and quotas" yourself
Jhatpat delivers groceries in ten minutes from 14 dark stores across Lucknow, and its hand-run servers fall over on festival evenings. You move it onto Kubernetes. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.