Part 1 · The objects you debug and how they connect
Desired state and the controllers that chase it
Kubernetes runs your containers on a group of machines and keeps them running the way you described. Debugging it is mostly working out which object has fallen out of step with which.
A cluster is a control plane plus nodes, the machines that run containers. You do not tell Kubernetes what to do step by step. You create objects that describe what you want, called the desired state, and controllers inside the control plane compare it with what exists, the observed state, and act until the two agree. Every object has a spec that you write and a status that the system fills in. Reading both is the first move in any debugging session.
A Pod is the smallest unit Kubernetes schedules: one or more containers that share a network address and run on one node. You rarely create Pods yourself. Other objects create them, and each layer has its own failure signs.
Object
What it does
First question when it misbehaves
Deployment
owns ReplicaSets and rolls out a new Pod template gradually
is the new ReplicaSet progressing?
ReplicaSet
keeps a set number of identical Pods running
how many Pods are wanted, created and ready?
Pod
runs containers on one node
which node, which phase, which container state?
Service
gives a stable name and address to a set of Pods chosen by label
which Pods does the selector match?
EndpointSlice
lists the addresses of ready Pods behind a Service, kept by a controller
is the list empty?
Gateway and HTTPRoute
Gateway API objects that accept outside traffic and route it to Services
is the route accepted and pointing at a Service?
Read the table from top to bottom and you have the order of a rollout: a Deployment makes a ReplicaSet, which makes Pods, which a Service finds by label.
A manifest set for a small service
A manifest is a YAML file describing one or more objects. This one runs three copies of an orders API behind a Service. The names are made up and the registry is example.com.
Three details here cause most of the trouble later. The Deployment's selector must match the labels in its Pod template, or the Deployment is invalid. The requests are what the scheduler reserves for the Pod, and the memory limit is the ceiling the kernel enforces. The readinessProbe is how Kubernetes decides whether the Pod should receive traffic.
The Service selects Pods labelled app: orders and forwards port 80 to port 8080 in the Pod. A client never learns individual Pod addresses. It talks to the Service, and Kubernetes keeps the list of matching ready Pods behind it.
Validate before you apply
No cluster is needed to catch a whole class of mistakes. kubernetes-validate checks a manifest against the official API schema of a chosen Kubernetes version. Here the target is 1.37, and --strict also rejects fields the schema does not know.
INFO manifests/deployment.yaml passed for resource deployment/orders
against version 1.37
Output
Two copies of the Deployment were then damaged on purpose. In one, replicas: 3 became the string "3". In the other, containerPort was misspelled.
text
ERROR manifests/bad-type.yaml did not validate for resource
deployment/orders against version 1.37: spec.replicas: '3' is not of
type 'integer', 'null'
ERROR manifests/bad-field.yaml did not validate for resource
deployment/orders against version 1.37:
spec.template.spec.containers.0.ports.0: 'containerPort' is a
required property
Output, both exit with status 1
The first error is a type error, the second a field the schema requires. Both would have failed at kubectl apply anyway, but here they fail in a pull request, in seconds.
A schema check has a hard limit. A Service whose selector names a label that no Pod carries is perfectly valid YAML, so it passes.
text
INFO manifests/service-wrong-selector.yaml passed for resource
service/orders against version 1.37
service-wrong-selector.yaml: selector app: order, a typo
That Service will be created, accepted and silently send traffic nowhere. Catching it needs a check that reads two objects together, which the services lesson builds. Keep the distinction in mind: validation proves a manifest is well formed, not that it does what you meant.
Which object keeps a fixed number of identical Pods running, and which object owns it?
A ReplicaSet keeps the number of Pods; a Deployment owns the ReplicaSet and creates a new one for each new Pod template.
A Service does not own Pods. It selects them by label.
replicas: "3" was rejected with spec.replicas: '3' is not of type 'integer', 'null'. What does that tell you about the check?
The check compares each field with the schema of the target version, here 1.37, and reports the path of the field and the type it expected.
It needs no cluster, so it can run in a pull request.
Why did a Service with the selector app: order pass validation?
The schema only knows that selector is a map of strings. It cannot know which labels your Pods carry.
Matching a selector to Pod labels needs a check across objects or a look at the live endpoints.
Part 2 · Pods that never schedule
What Pending means
A new Pod starts in the Pending phase. The Kubernetes documentation defines it as accepted by the cluster but with one or more containers not yet set up and made ready, which includes time spent waiting to be scheduled and time spent pulling images. A Pod that stays Pending for minutes with no image pull going on is usually not schedulable.
The scheduler is the control-plane component that picks a node for each new Pod. It first filters out nodes where the Pod cannot run, then ranks the rest. If every node is filtered out, the Pod stays Pending and the scheduler records a FailedScheduling event that lists the reasons, with a count of nodes for each reason. That event is the first thing to read.
The most common filter is resources. Each node reports its allocatable amount of CPU and memory: the machine's capacity minus what is held back for the system and for Kubernetes itself. Each Pod declares requests, the amounts it needs reserved. The documentation states the rule plainly: the sum of the requests of the Pods placed on a node must fit within the node's capacity, which in practice means its allocatable amount, and the scheduler refuses to place a Pod when that check fails, even if the real usage on the node is low.
That has a consequence people miss. The scheduler looks at requests, not at what the processes actually use. A node whose CPU graph is flat at 10 percent can still be full if its Pods asked for all of it.
Units cause real mistakes. A CPU of 250m means 250 millicores, a quarter of a core, and 0.25 means the same. For memory, the documentation warns that M means megabytes and m means millibytes, so 400m is 0.4 bytes. Write 400Mi or 400M.
Taints, tolerations and the other filters
A taint on a node repels Pods. A toleration on a Pod lets it ignore a matching taint. The effects differ.
Taint effect
What it does
NoSchedule
no new Pods are scheduled on the node unless they tolerate the taint; running Pods stay
PreferNoSchedule
the scheduler tries to avoid the node but may still use it
NoExecute
Pods that do not tolerate the taint are evicted immediately
A toleration matches a taint when the key and effect agree and either the operator is Exists, or it is Equal and the values match. Teams use taints to keep a pool of nodes for one purpose, such as batch jobs, so ordinary Pods do not land there.
Kubernetes also taints nodes itself. When a node stops reporting, it gets node.kubernetes.io/not-ready or node.kubernetes.io/unreachable with the NoExecute effect. Pods get a default toleration for each with tolerationSeconds=300, so they stay bound to a failing node for five minutes before eviction.
Other filters work the same way: a nodeSelector or node affinity that names labels no node has, a topology spread rule that cannot be satisfied, a quota that is used up, and a PersistentVolumeClaim that is not bound yet, which keeps the Pod Pending until storage exists in a suitable zone. Each of them also shows up in the FailedScheduling message.
A fit check you can run
There is no cluster in this course, so the scheduler's resource and taint rules are reproduced as a small model in TypeScript. It is a model of the rules above, not the real scheduler, and the message format is the model's own. It has three made-up nodes: node-a is nearly out of CPU, node-b is tainted dedicated, and node-c is nearly out of memory.
Pod A asks for 500m CPU and 512Mi. node-a has 300m CPU left, node-b refuses it for the taint, and node-c has 148Mi of memory left. Every node fails for a different reason, and the summary says so. Pod B adds a toleration and fits on node-b. Pod C asks for less and fits on node-a and node-c. Pod D asks for more CPU than any node offers, so no toleration can help.
The point of the output is the shape of the message: how many nodes failed, and why each did. The fix depends on the reason. If every node says Insufficient cpu, you lower the requests, add nodes or use bigger ones. If most say untolerated taint, the Pod belongs on a different pool or needs a toleration. Treat the numbers in requests as a budget you spend, not a guess to be made large for safety.
A node runs at 10 percent CPU use, yet a new Pod cannot be scheduled for lack of CPU. How?
The scheduler compares the Pod's requests with the node's allocatable CPU minus the requests of Pods already placed. It does not look at real usage.
The Pods on the node have asked for nearly all of it, even though they use little.
In the model, why did Pod B fit on node-b while Pod A did not?
Pod B tolerates the dedicated taint, and node-b has 3500m CPU and 7 GiB of memory unclaimed.
Pod A has no toleration, so node-b was filtered out by the taint before resources mattered.
What does 0/3 nodes available: 3 Insufficient cpu tell you to do first?
Lower the Pod's CPU request if it is larger than needed, or add capacity: more nodes or larger ones.
A toleration or label change would not help because the failure is resources on every node.
Part 3 · Containers that crash or never become ready
Container states and the back-off
Once a Pod is on a node, each of its containers is in one of three states, according to the documentation: Waiting, when it is still doing start-up work such as pulling its image; Running; or Terminated, when it ran to completion or failed. A terminated container shows a reason, an exit code and start and finish times.
The restartPolicy of a Pod defaults to Always, so the kubelet, the agent on each node, restarts a container that exits. If it keeps exiting, restarts are spaced by an exponential back-off: 10 seconds, then 20, then 40, doubling up to a cap of 300 seconds. The timer resets once a container has run for 10 minutes without trouble. These are the defaults; an alpha feature gate, ReduceDefaultCrashLoopBackOffDecay, changes them to start at 1 second and cap at 60. While a container waits for its next attempt, kubectl shows the reason CrashLoopBackOff. A short model of the schedule shows why a crashing Pod feels slow to recover.
ts
// Restart delay after each crash: 10 s, doubling, capped at 300 s.let total = 0
console.log(' crash delay total')
for (let n = 1; n <= 8; n++) {
const delay = Math.min(10 * 2 ** (n - 1), 300)
total += delay
const row = [n, `${delay}s`, `${total}s`]
console.log(row.map((v) => String(v).padStart(6)).join(' '))
}
By the sixth crash the Pod has spent over ten minutes just waiting. Deleting the Pod does not help if the cause is still there, and waiting does not help either, because the delay does not shrink while the container keeps failing.
Image problems look similar. When a container's image cannot be pulled, the container stays Waiting with ErrImagePull, then ImagePullBackOff as retries slow down. The usual causes are a typo in the image name or tag, a tag that does not exist, a private registry without a pull secret, or a node with no route to the registry. The event text names which.
Exit codes and out-of-memory kills
A terminated container reports an exit code, and the code usually tells you who ended it. A process that exits by itself returns its own code, with 0 meaning success. A process killed by a signal reports 128 plus the signal number. This is a Linux convention, so it can be checked in any shell.
Exit code 137 is SIGKILL, signal 9, and in Kubernetes it often means the container was killed for exceeding its memory limit. The reason shows as OOMKilled. The documentation explains the mechanism: when a container goes over its memory limit, the Linux kernel's out-of-memory handling stops a process in it. The Linux chapter showed that kernel side with a real kill. The Deployment above has a memory limit of 256Mi, so a leak or a large request in the API would end that way.
Exit code 143 is SIGTERM, which Kubernetes sends first when it stops a Pod. By default a Pod gets 30 seconds to finish, set by terminationGracePeriodSeconds, and after that the KILL signal ends whatever remains. A service that ignores SIGTERM therefore shows 137 after 30 seconds on every deploy, which is slow and rough on in-flight requests.
CPU is different. The documentation says CPU limits are enforced by throttling, so a container over its CPU limit slows down and is not killed. A service that is slow but never restarts, on a node with plenty of idle CPU, may be throttled by a limit set too low.
Probes: ready, alive and started
A probe is a check the kubelet runs against a container, by running a command, making an HTTP or TCP request, or calling a gRPC health endpoint. There are three kinds, and their failures mean three different things.
Probe
Question
When it fails
startup
has the app finished starting?
the container is killed and handled by its restart policy; liveness and readiness probes do not run until it succeeds
liveness
is it stuck?
the kubelet restarts the container
readiness
can it take traffic now?
the Pod is taken out of the ready endpoints of every matching Service; the container keeps running
Readiness probes run for the whole life of the container, so a Pod can leave and rejoin a Service many times without a restart. The mistakes cluster around liveness. A liveness probe that calls the database turns a slow database into a restart of every Pod, which makes the incident larger. A liveness probe that is stricter than the app can meet during a slow start kills it before it is ready. The documentation's advice is to use initialDelaySeconds or, better, a startup probe when a service needs time.
A Pod that is Running but not Ready is a normal state to the cluster: the container runs and is only left out of the endpoints. That is why a rollout can stall with Pods that never become Ready while nothing crashes.
Getting evidence from a failing container
The commands for this, which a cluster would run and this course does not, follow the same order as a good triage.
kubectl describe pod shows the container state, the last state with its reason and exit code, and the Events at the bottom.
kubectl logs <pod> --previous shows the output of the previous container instance, which is the one that crashed. Plain logs after a restart shows the new, usually empty, one.
kubectl debug adds an ephemeral container to a running Pod. Stable since Kubernetes 1.25, it is meant for the case where kubectl exec is not enough because the container crashed or its image has no shell. --target shares the process namespace of another container.
kubectl debug node/<name> starts a Pod on a node with the node's file system mounted under /host.
Animated sceneA container in a crash loop0:16
Watch for the waits growing between crashes, then a fix that holds
Read it as steps
A container crashes, waits longer each time, and stays up once fixed.
In the real API the back-off wait is a Waiting state with the reason CrashLoopBackOff; the scene separates it to show the cycle. The lesson is that the fix is a changed container or configuration, never a faster restart.
A container exits with code 137 shortly after a traffic spike. What do you check first?
Its memory limit and the reason on the last state. 137 is SIGKILL, and OOMKilled means the kernel enforced the memory limit.
Raise the limit only after checking whether the process leaks or simply needs more.
After six crashes in a row, how long has the kubelet spent waiting, by the documented schedule?
610 seconds in total: 10, 20, 40, 80, 160 and 300 seconds, as the run above printed.
The delay doubles each time and stops growing at 300 seconds.
Which probe failure removes a Pod from a Service without restarting it?
Readiness. The Pod is taken out of the Service's ready endpoints and the container keeps running.
A liveness failure restarts the container, and a startup failure kills it.
Part 4 · Services that do not answer
How a Service finds Pods
A Service gives a changing set of Pods one stable name and address. The documentation describes the mechanism in two parts. The Service holds a label selector. A controller continuously scans for Pods that match it and keeps the Service's EndpointSlices up to date, one list of the addresses it should send traffic to. When the set of Pods changes, the slices change.
A Service has two port numbers, and mixing them up is the commonest fault. port is the one clients connect to. targetPort is the port the container listens on inside the Pod. If targetPort is left out it defaults to port. It can also be the name of a container port. In the Service from the first lesson, clients use port 80 and the container listens on 8080.
The default Service type, ClusterIP, assigns an address that is reachable only inside the cluster. A Service with no selector gets no automatic endpoints at all, so you must create the EndpointSlices yourself.
A Service that does not answer has one of a short list of faults. Work through them in order.
The selector matches no Pod, because of a label typo or a label that changed. The endpoint list is empty.
The selector matches Pods, but none is Ready, so the list is empty. This is the readiness probe from the previous lesson.
The endpoints exist, but targetPort points at a port the container is not listening on. Connections fail or reset.
The Service is fine and something between the client and the Pod blocks it: a network policy, or DNS giving the wrong answer.
Finding a mismatch before it ships
The first two faults leave the manifest valid, so the schema check from the first lesson cannot see them. A small script can: it reads a Deployment and a Service together and checks that the Service selector matches the Pod template labels and that targetPort is a declared container port. It is a check on manifests, not on live Pods, so a Pod that never becomes Ready is outside its reach.
ts
const docs = process.argv.slice(2).flatMap((f) =>
parseAllDocuments(readFileSync(f, 'utf8')).map((d) => d.toJS()))
const deployments = docs.filter((d) => d.kind === 'Deployment')
let problems = 0const report = (msg: string) => { console.log(msg); problems++ }
for (const svc of docs.filter((d) => d.kind === 'Service')) {
const name = `service/${svc.metadata.name}`const sel = svc.spec.selector ?? {}
const hits = deployments.filter((d) => {
const labels = d.spec.template.metadata.labels ?? {}
return Object.entries(sel).every(([k, v]) => labels[k] === v)
})
if (!hits.length) {
report(`${name}: selector ${JSON.stringify(sel)} matches no pod`)
}
for (const d of hits) {
const ports = d.spec.template.spec.containers
.flatMap((c: any) => c.ports ?? [])
.map((p: any) => p.containerPort)
for (const p of svc.spec.ports) {
const target = p.targetPort ?? p.port
if (typeof target === 'number' && !ports.includes(target)) {
report(`${name}: targetPort ${target} is not in ${ports}`)
}
}
}
}
if (!problems) console.log('ok: every Service selects a pod and a port')
process.exitCode = problems ? 1 : 0
endpoints-check.mts, the main loop
It was run on the good pair, on a Service with the selector typo, and on a Service with targetPort: 8000.
text
$ node endpoints-check.mts deployment.yaml service.yaml
ok: every Service selects a pod and a port
$ node endpoints-check.mts deployment.yaml service-wrong-selector.yaml
service/orders: selector {"app":"order"} matches no pod
$ node endpoints-check.mts deployment.yaml service-wrong-port.yaml
service/orders: targetPort 8000 is not in 8080
Output
On a live cluster the same questions are answered by listing the EndpointSlices for the Service and by describing the Pod for its readiness. An empty list with Running Pods points at the selector or at readiness. A full list with failing requests points at targetPort, the container, or the network.
Animated sceneA Service with no endpoints0:16
Watch for the request ending at the Service while three Pods sit healthy
Read it as steps
The selector matches nothing, so requests die at the Service until the label is fixed.
The Pods were healthy the whole time. The break was a one-letter label difference in a different object, which is why the diagnosis starts at the Service and works toward the Pods.
DNS inside the cluster
Pods usually reach a Service by name. The Service orders in namespace shop has the name orders.shop.svc.cluster.local, and the Pod's /etc/resolv.conf is set up so shorter names work. The documentation's example shows the shape.
A Pod's resolv.conf, as in the Kubernetes documentation
The search list is a set of suffixes the resolver adds to a name. The ndots option sets how many dots a name needs before the resolver tries it as is first. With ndots:5, any name with fewer than five dots is tried with each search suffix before the plain name. So orders and orders.shop resolve inside the cluster, which is the point. The cost is that an outside name like api.example.com, with two dots, is tried three times with cluster suffixes, and each of those lookups fails, before the real lookup is made. The default dnsPolicy is ClusterFirst, which is what gives Pods this file.
ts
// The resolver's search rule: a name with fewer dots than ndots is// tried with each search suffix first, otherwise as written first.const search = [
'shop.svc.cluster.local',
'svc.cluster.local',
'cluster.local',
]
const ndots = 5const exists = new Set([
'orders.shop.svc.cluster.local',
'api.example.com',
])
function candidates(name: string): string[] {
if (name.endsWith('.')) return [name.slice(0, -1)]
const dots = name.split('.').length - 1const expanded = search.map((s) => `${name}.${s}`)
return dots >= ndots ? [name, ...expanded] : [...expanded, name]
}
const names = [
'orders',
'orders.shop',
'api.example.com',
'api.example.com.',
]
for (const name of names) {
const tried = candidates(name)
const hit = tried.findIndex((c) => exists.has(c))
console.log(`${name}: ${hit} failed lookups before the answer`)
console.log(` answer: ${tried[hit]}`)
}
dns-expand.mts: the search rule as a model
text
orders: 0 failed lookups before the answer
answer: orders.shop.svc.cluster.local
orders.shop: 1 failed lookups before the answer
answer: orders.shop.svc.cluster.local
api.example.com: 3 failed lookups before the answer
answer: api.example.com
api.example.com.: 0 failed lookups before the answer
answer: api.example.com
Output of the model
A dot at the end of a name makes it absolute and skips the search list, and lowering ndots in the Pod's dnsConfig is the other fix. If lookups for outside names are slow or flood the cluster DNS, this is the first place to look.
Network policies
By default every Pod can talk to every other Pod. A NetworkPolicy restricts that. A Pod is isolated for ingress when any policy selects it and lists Ingress in its policyTypes, and then only traffic that some policy allows can reach it. Policies do not conflict: they are additive, and the allowed traffic is the union of what they permit.
This policy selects every Pod in its namespace, since an empty podSelector selects all, and allows no ingress. It is a common first step before adding rules for each service. Two traps follow from the documentation. A NetworkPolicy has no effect unless the cluster's network plugin implements it. And a default-deny policy for egress also blocks DNS, so workloads then need a rule allowing traffic to the cluster DNS service or every name lookup times out.
A Service has three Running Pods but requests fail immediately. Which two checks come first?
List the Service's endpoints. An empty list means the selector matches no Ready Pod.
If the list is full, compare targetPort with the port the container listens on.
With ndots:5, how many lookups are made for api.example.com before the plain name is tried, given the three search suffixes above?
Three, one for each suffix, and each fails. Then the plain name is tried, as the model run showed.
A trailing dot on the name, or a lower ndots, avoids them.
You add a policy that denies all egress from a namespace and name lookups start timing out. Why?
DNS is traffic too, and a deny-all egress policy blocks it along with everything else.
Add an egress rule that allows the cluster DNS service.
Part 5 · Rollouts, disruptions and autoscaling
Rolling updates and their limits
A Deployment replaces Pods gradually. It creates a new ReplicaSet for the new Pod template, scales it up and scales the old one down, within two limits. maxSurge is how many Pods above the desired count may exist during the update. maxUnavailable is how many Pods may be missing. Both default to 25 percent. The documentation fixes the rounding: a percentage for maxSurge is rounded up, and one for maxUnavailable is rounded down. Neither may be zero if the other is zero, or no progress would be possible.
rollout.mts: the limits as a model of the documented rules
text
replicas surge unavail maxPods minReady (25% and 25%)
11021210323104341153103213815431912
Output
Read the rows. With one replica the surge is 1 and nothing may be unavailable, so the update starts a second Pod and waits for it to be ready before removing the first. With ten replicas the update may run up to 13 Pods and must keep at least 8 ready. The defaults suit most services, but a small count rounds in a surprising way, so check it when you tune them.
A rollout that cannot finish does not fix itself. progressDeadlineSeconds defaults to 600. When the deadline passes, the Deployment's Progressing condition becomes false with the reason ProgressDeadlineExceeded, and the documentation notes that Kubernetes takes no action beyond reporting it. The usual causes are exactly the earlier lessons: Pods that cannot be scheduled, crash, or never become Ready.
kubectl rollout undo deployment/<name> returns to the previous revision, and --to-revision=N picks one. Revisions are ReplicaSets, and revisionHistoryLimit defaults to 10 of them. A paused Deployment cannot be rolled back until it is resumed.
Disruptions and PodDisruptionBudgets
Kubernetes separates involuntary disruptions, such as a hardware failure, from voluntary ones: deleting a Deployment, or an administrator draining a node for maintenance. A PodDisruptionBudget (PDB) limits voluntary disruptions of a set of Pods by saying how many must stay available.
You can set minAvailable or maxUnavailable, one of the two, each as a number or a percentage. For percentages Kubernetes rounds up, so with 7 Pods and minAvailable: 50% four must stay. kubectl drain works through the Eviction API, and an eviction that would break the budget is refused. The drain then retries and waits, and the documentation says it blocks when the budget cannot be met, until someone adds capacity.
The classic mistake is a budget that can never be satisfied. With three replicas and minAvailable: 3, no Pod may ever be evicted, so every node drain hangs. A budget of minAvailable: 1 on a one-replica Deployment blocks every drain for the same reason. Keep the budget below the replica count, and spread Pods across zones so a drain of one node still leaves the budget room.
Horizontal autoscaling
The HorizontalPodAutoscaler (HPA) changes a Deployment's replica count from a metric. The documentation gives the formula: desired replicas equals the ceiling of current replicas times the current metric value divided by the desired value. For CPU the metric is utilisation, a percentage of the container's request, so a container with no CPU request gives the HPA nothing to work with.
The control loop runs every 15 seconds by default. It skips any change when the ratio is close to 1, with a default tolerance of 10 percent. Scale-up is immediate by default, limited by two policies, 100 percent or 4 Pods per 15 seconds with the larger one chosen. Scale-down waits behind a stabilisation window of 300 seconds and uses the highest recommendation in it, so a brief dip does not remove Pods. Not-ready Pods and missing metrics are handled conservatively. With several metrics, the largest desired count wins.
ts
// desired = ceil(current * metric / target), skipped inside tolerance.// Scale-up per sync is capped by the default policies: the larger of// 4 pods or 100% of the current count (selectPolicy Max).const TOLERANCE = 0.1const MIN = 3const MAX = 12function desired(current: number, metric: number, target: number) {
const ratio = metric / target
if (Math.abs(ratio - 1) <= TOLERANCE) return current
return Math.ceil(current * ratio)
}
function step(current: number, metric: number, target: number) {
const raw = desired(current, metric, target)
const want = Math.min(MAX, Math.max(MIN, raw))
const cap = current + Math.max(4, current) // scale-up policiesreturn want > current ? Math.min(want, cap) : want
}
hpa.mts: the formula, tolerance and default scale-up limit
text
4 replicas, 90% vs 60% -> 610 replicas, 63% vs 60% -> 10 (inside tolerance)
sync 1: 3 replicas at 280% -> 7
sync 2: 7 replicas at 120% -> 12
sync 3: 12 replicas at 70% -> 12
Output, with the load held constant across syncs
The two first lines apply the formula. The three syncs show a spike: 3 replicas at 280 percent want 14, are held to 7 by the scale-up policy, then reach 12 at the next sync, and stop there because maxReplicas is 12, even though 70 percent is above the 60 percent target. A cap in the HPA is a ceiling you chose, so alerts should fire when it is reached.
Animated sceneHow many replicas the HPA asks for0:16
Replicas after this sync: 6 (the same answer as hpa.mts printed)
Read it as steps
Replicas times the ratio of observed to target use, rounded up, then limited.
The scene is the formula and the limits in one place. The calculation gives 6, the cap allows up to 8, so the answer is 6.
Changing size without a restart
Changing a Pod's CPU or memory used to mean recreating the Pod. In-place resize lets you change the requests and limits of a running container without recreating it. It reached stable in Kubernetes 1.35. You patch the Pod's resize subresource, and the desired values live in spec while the values actually applied appear in status.
Each resource has a resizePolicy. NotRequired, the default, applies the change to the running container. RestartContainer restarts the container to apply it. A resize the kubelet cannot grant right away sets a PodResizePending condition, and one being applied shows PodResizeInProgress. Two limits matter in practice. The Pod's QoS class is fixed at creation and a resize cannot change it. And lowering memory is a best effort: the kubelet tries to avoid an OOM kill but there are no guarantees.
This is a tool for the Pod you already have and for vertical changes. It does not replace the HPA, which changes how many Pods you run.
With 10 replicas and the default rolling update, how many Pods can exist at most, and how many must be ready?
At most 13: a surge of 3, since 25 percent of 10 rounds up. At least 8 must stay ready, since 25 percent rounds down to 2 unavailable.
The model printed the same row.
A drain of one node hangs. The Deployment has three replicas and a PDB with minAvailable: 3. Why?
No Pod may be evicted without breaking the budget, so every eviction is refused and the drain waits.
Lower minAvailable below the replica count, or add replicas.
Why did the HPA stop at 12 replicas while utilisation was still 70 percent against a 60 percent target?
maxReplicas was 12, and the HPA never goes above it. The formula wanted 14.
The cap is a decision to make visible, so alert when the HPA sits at its maximum.
Part 6 · Running on Amazon EKS
What AWS runs and what you run
Amazon EKS is AWS's managed Kubernetes service. AWS runs the control plane, the API server and its data store. You run the data plane, the nodes, unless you choose a mode where AWS manages them as well. The EKS best practices guide puts the consequence plainly: when you start a cluster upgrade AWS upgrades the control plane, and you upgrade the nodes, the add-ons and your own workloads.
Support follows the upstream project. At the time of writing, the Kubernetes releases page lists 1.37, 1.36 and 1.35 as maintained, and 1.34 reached its end of life on 27 October 2026. EKS adds its own windows: a minor version has standard support for 14 months after release, then extended support for 12 more, and a cluster still on a version at the end of that lifecycle is upgraded automatically. EKS gives at least 60 days of notice before standard support ends.
Three EKS topics decide most debugging sessions: how a Pod gets AWS credentials, how many Pods a node can hold because of IP addresses, and how upgrades go wrong. The next pages take them in that order.
IAM for pods
A Pod that calls AWS APIs needs credentials, and the safest source is a role tied to the Pod's service account, not the node's role. The guide describes two mechanisms.
IRSA (IAM roles for service accounts)
EKS Pod Identity
How it works
the Pod gets a projected service account token, and AWS STS exchanges it for role credentials through an OIDC provider you configure per cluster
an agent running as a DaemonSet on each node hands the Pod credentials using a token EKS mounts and refreshes
Needs an OIDC provider per cluster
yes
no
Needs an agent DaemonSet on nodes
no
yes
Guide's advice
both are preferred ways
recommended unless you have a use case for IRSA
Application code does not change for either: supported AWS SDKs find the credentials through their normal provider chain.
The easy mistake is leaving the node role reachable. Even when a Pod uses IRSA or Pod Identity, it can still inherit the rights of the node's instance profile through the instance metadata service. The guide recommends blocking that for Pods that do not need it, by requiring IMDSv2 and setting the hop limit to 1, rather than disabling the metadata service, which breaks node components. Give each service account its own role with only the permissions that workload needs, and when you diagnose an AccessDenied from a Pod, check which role the Pod is actually using before you read any policy.
Pods use VPC addresses
With the default Amazon VPC CNI plugin, each Pod gets an address from your VPC, taken from network interfaces (ENIs) attached to the node. The consequence is a hard ceiling per node. The guide gives the formula for the maximum number of Pods: the number of network interfaces for the instance type times the number of IP addresses per interface minus one, plus two for Pods that use host networking, such as kube-proxy and the CNI itself.
ts
// Pod limit on a node with the VPC CNI in its default mode:// ENIs * (IPs per ENI - 1) + 2, from the EKS best practices guide.function maxPods(enis: number, ipsPerEni: number) {
return enis * (ipsPerEni - 1) + 2
}
// The guide's example node: 3 network interfaces, 10 IPs each.
console.log('3 ENIs x 10 IPs per ENI ->', maxPods(3, 10), 'pods')
// A made-up smaller node: 2 ENIs, 4 IPs each.
console.log('2 ENIs x 4 IPs per ENI ->', maxPods(2, 4), 'pods')
maxpods.mts: the guide's formula and its example node
text
3 ENIs x 10 IPs per ENI -> 29 pods
2 ENIs x 4 IPs per ENI -> 8 pods
Output
The first line is the guide's own example, an instance with 3 interfaces and 10 addresses each: 29 Pods. The second is a made-up smaller node. A node can therefore be full while CPU and memory are free, and the Pod stays Pending with a FailedScheduling event that reads Too many pods for those nodes, not Insufficient cpu. Google's GKE troubleshooting guide documents that phrase as the "maximum Pods per node limit reached" symptom. The Kubernetes documentation does not list scheduler message strings, so treat the exact wording as version dependent.
Addresses also come from your subnets. The CNI keeps a warm pool of spare addresses and interfaces so new Pods start quickly, and those warm addresses are taken from the subnet before any Pod uses them. A cluster of many small nodes in small subnets can run out of addresses, which stops both Pod starts and cluster upgrades, because EKS itself needs up to five free addresses in the cluster's subnets to upgrade. The remedies are larger subnets or extra CIDR blocks on the VPC, and a prefix mode that assigns blocks of addresses.
Upgrades and node scaling
An in-place EKS upgrade moves one minor version at a time, so going from 1.34 to 1.36 means two upgrades in sequence. The guide gives this order: read the release notes, fix deprecated and removed API usage in your manifests, upgrade the control plane, upgrade add-ons such as the VPC CNI, kube-proxy and CoreDNS, then the nodes. EKS does not update add-ons for you after a control plane upgrade.
Nodes may lag the control plane within the version skew rule: from Kubernetes 1.28 up, kubelets may be up to three minor versions behind the API server on managed node groups, Fargate and self-managed nodes, where older versions allowed two. Lagging is permitted, not recommended: older kubelets carry older security fixes.
Removed APIs are the upgrade failure you can see coming. The guide suggests EKS Cluster Insights, and open-source scanners such as kubent and pluto, ideally run against rendered manifests in CI, which is more accurate than scanning a live cluster. The schema check from the first lesson, run against the next version, is another cheap guard: a manifest that uses an API removed in that version fails validation.
Node capacity needs something to add and remove nodes. Cluster Autoscaler scales node groups up and down, is tightly coupled to the scheduler, and must be upgraded with the cluster. Karpenter provisions nodes directly, sized to the pending Pods' requirements, and by default launches the latest compatible EKS-optimised image, with node expiry to replace old nodes. Either respects PodDisruptionBudgets when it drains, so the budget from the previous lesson is what keeps a node upgrade safe.
A Pod uses IRSA but still reaches AWS with the node's permissions. How?
It can read the node role's credentials from the instance metadata service.
Require IMDSv2 and a hop limit of 1 on the nodes so Pods cannot reach it, without disabling metadata for node components.
A node has free CPU and memory but is not accepting new Pods. Give one EKS reason.
With the VPC CNI each Pod uses a VPC address, so the instance type's network interfaces and addresses per interface cap the Pod count, here 29 for 3 interfaces of 10 addresses.
Prefix mode or a larger instance type raises the cap.
A cluster is on 1.34 and the target is 1.36. What is the sequence?
Upgrade the control plane to 1.35, update add-ons and nodes, then repeat for 1.36. In-place upgrades move one minor version at a time.
Check for removed APIs first, and keep PodDisruptionBudgets in place so node replacement does not cause an outage.