StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 11 · Resource Requests & Limits

QoS Classes

mediumQoS ClassesEviction Ranking—No data yet

Problem statement

When the node runs short of memory, something has to go, and the kubelet does not pick at random - it evicts by class. In namespace service-tiers the ranking is exactly backwards: payments-api declares nothing at all, so it is the first thing thrown overboard, while metrics-scraper is pinned as hard as the platform can pin anything. report-worker sits between them declaring nothing either. Two more workloads are missing entirely.

About this exercise

Every pod is assigned a quality of service class by the API server, from nothing but the requests and limits its containers declare. You never set it; you compose it, and the class shows up in the pod's status once the object is stored.

There are three classes and the rules are exact:

  • Guaranteed - for every container in the pod, both cpu and memory are declared, and for each of them the limit equals the request. One container falling short of that drops the whole pod out of the class.
  • BestEffort - no container in the pod declares any request or any limit, for any resource. Nothing at all.
  • Burstable - everything else. At least one container declares something, but the pod does not meet the Guaranteed rule.

Remember that a container declaring only limits is stored with its requests filled in from those limits - which is why limits alone, on every container, for both resources, still lands in Guaranteed.

The class is the eviction order. Under memory pressure the kubelet reclaims from BestEffort first, then Burstable pods that are using more than they requested, and Guaranteed pods last. So the class is not a label describing what a workload is - it is a promise about what the node will do to it when things go wrong, and it is composed out of two fields.

kubectl explain pod.status.qosClass and kubectl explain pod.spec.containers.resources are the reference for the fields.

How this project is graded

The grader reads the live cluster: what each container declares and the class the cluster assigned to each pod in its status. Your saved answers are compared against those assigned classes. The namespace is re-seeded before every run, so a pod you never built cannot pass by accident.

What you will build

Five pods in namespace service-tiers. Every container runs busybox:1.36 and stays alive; each pod must end up Running. Three of them exist already with the wrong shape - a pod's resources are immutable, so those are replacements, not edits.

1. payments-api - two containers, api and auth, ranked as high as the platform allows. Both containers:

requests   cpu 200m   memory 128Mi
limits     cpu 200m   memory 128Mi

2. ledger-pair - two containers, where only one of them is fully declared:

container writer    requests cpu 100m memory 64Mi    limits cpu 100m memory 64Mi
container shipper   requests cpu 50m  memory 32Mi    no limits

3. report-worker - one container worker, reserving what it needs and capped by nothing:

requests   cpu 100m   memory 64Mi
no limits

4. batch-loader - one container loader, declaring one half of one resource and nothing else:

limits     memory 128Mi
no cpu request, no cpu limit, no memory request

5. metrics-scraper - one container scraper, declaring nothing whatsoever:

no requests, no limits

6. One answer in answers/:

qos.txt   one line per pod in service-tiers, sorted by pod name:
              <pod> <class>
          each class exactly as the cluster assigned it in the pod's status

Step 1 - the top of the ranking

Compose payments-api so it lands in the class the node evicts last. Every container has to satisfy the rule, not just the important-looking one.

guaranteed_when_every_container_matches_requests_to_limits should pass

Step 2 - one container is enough to break it

ledger-pair declares one container perfectly and leaves the other partly declared. Find out which class the pod as a whole ends up in.

one_unmatched_container_drops_the_pod_to_burstable should pass

Step 3 - the middle of the ranking

report-worker reserves and does not cap; batch-loader caps one resource and says nothing about the other. Both are partial declarations, and partial has exactly one destination.

requests_without_limits_are_burstable and partial_declaration_is_burstable should pass

Step 4 - the bottom of the ranking

metrics-scraper declares nothing. That costs the node nothing on paper and buys the workload nothing at all when memory runs short.

nothing_declared_is_besteffort should pass

Step 5 - read the ranking back

Get all five running and save the class the cluster assigned to each.

every_tier_workload_is_running and assigned_classes_saved_from_status should pass

When every test passes

You have:

  • A payment service the node protects and a scraper it sacrifices, instead of the other way round
  • The Guaranteed rule proven the hard way: one under-declared container in a pod is enough to lose the class
  • Every shape of partial declaration landing in the same middle class
  • The assigned classes read from the cluster's own status rather than assumed

You do not have yet:

  • Any of this reconciled against the node it all runs on. Requests, limits and classes together, against one node's ledger, is the next exercise.

Verify

Click Test after every step.

More in Resource Requests & Limits

See the module
Requests & SchedulingGive workloads the cpu and memory requests the scheduler does its arithmetic with, prove that a request above the node's allocatable memory can never be placed, and read the node's own allocatable and allocated accounting.—No data yetmediumLimits & EnforcementCap a leaking container with cpu and memory limits, watch the kubelet enforce the memory wall with an OOM kill and a restart while its neighbour under the same ceiling runs untouched, and see requests default from limits.—No data yetmediumNode Resource GovernanceRight-size a namespace of ungoverned tenants on one node: honest requests, a ceiling that keeps a leak inside its own container, a deliberate eviction ranking, and a ledger reconciling allocatable against requested.—No data yetmedium

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.