Problem statement
Traffic on checkout doubled last quarter. The operator on shift answered it by copying the pod manifest, changing the name to checkout-api-2 and applying it - so namespace capacity now runs a Deployment called checkout-api and one loose pod that answers to nothing and nobody will ever remember to delete. Retire the copy, and drive the tier's size the way it was meant to be driven.
About this exercise
The size of a Deployment is one number in its spec, and everything else follows from it. Change the number and the ReplicaSet notices the gap between what it has and what it was told to have, and closes it - creating pods when the number goes up, deleting pods when it goes down. Nothing else about the workload changes: the same ReplicaSet keeps serving, because the pod template was not touched. Editing the template is a different operation with different consequences, and it produces a second ReplicaSet; changing the count does not.
There are two ways to write that number and they end up in the same place. One changes the live object directly, which is what you reach for during an incident. The other changes the declared count in the manifest you keep, and applies it - slower to type, but the file and the cluster still agree afterwards, which the first way quietly breaks.
What makes scaling worth watching is the status, because the gap between what you asked for and what you have is real for a while:
- spec.replicas is what you asked for
- status.replicas is how many the ReplicaSet currently has
- status.readyReplicas is how many are passing their readiness check
- status.availableReplicas is how many have been ready long enough to be counted on
Immediately after a scale-up those four disagree, and a scale-up is not finished until they converge. That transient is the whole point of reading status instead of counting lines of get pods.
kubectl scale --help and kubectl explain deployment.status are the reference.
How this project is graded
The grader reads the live Deployment - its declared count, its status, its generation and the ReplicaSet behind it - and checks that the pods you recorded at the smaller size are still the ones running, so a tier that was deleted and rebuilt does not pass as a tier that was scaled. Your saved answers are compared against the cluster, and the last recorded step must match what the Deployment reports at grading time. The namespace is re-seeded before each run.
What you will build
Everything lives in namespace capacity. manifest.yaml on disk describes the Deployment exactly as it is running now.
1. The pod checkout-api-2 must no longer exist.
2. The tier is taken through three size changes, in this order:
up to 6 changed on the live object, without editing manifest.yaml down to 3 the same way to 4 by changing the declared count in manifest.yaml and applying it
Change only the replica count in manifest.yaml. Everything else in that file describes the running object and must stay as it is.
3. Three answers in answers/:
pods-at-6.txt the six pod names once the tier has settled at six, one per line
pods-at-3.txt the three pod names once it has settled at three, one per line
status.txt one line per step above, in that order:
<desired> <replicas> <ready> <available>
Each line of status.txt is read once that step has converged, so all four numbers on a line agree.
Step 1 - retire the copy
Remove the pod somebody added by hand. Everything the tier runs must come from the Deployment.
hand_copied_pod_is_retired should pass
Step 2 - up
Take the live Deployment to six and wait for all six to be ready before you record anything. Save the pod names and the step's status line.
scale_up_reaches_the_new_count_all_ready should pass
Step 3 - down
Take it to three the same way. The cluster removes the surplus and leaves the survivors running - the three you record here are three of the six you recorded before, and they are still there at the end.
scale_down_removes_exactly_the_surplus should pass
Step 4 - from the file this time
Set the declared count in manifest.yaml to four and apply it, so the file and the cluster agree on the tier's size.
declared_replica_count_reconciles_the_live_count should pass
Step 5 - the numbers you watched
status.txt now holds the three steps in order. The last line has to still be true of the Deployment when the grader looks.
status_fields_track_each_scaling_step and one_replicaset_serves_every_scaling_step should pass
When every test passes
You have:
- Capacity changed by a number the cluster enforces, instead of another copied manifest
- The same tier driven both ways: live during an incident, and declared in the file you keep
- Surplus pods removed without disturbing the ones that were serving
- The four status counters read at each step, including while they disagreed
You do not have yet:
- Any guard on which pods a Deployment will claim. What happens when the selector and the template stop agreeing, and what happens to a pod that is labelled out from under its owner, is the next exercise.
Verify
Click Test after every step.
