Operate and shipLesson 3 of 10
  1. Metrics, logs, events and traces, not reconciled
  2. Horizontal pod autoscaling, not reconciled
  3. Right-sizing and in-place resize, not reconciled
    1. Why right-size
    2. In-place resize (GA 1.35)
    3. Resize policy
    4. Resize status
    5. Vertical Pod Autoscaler
    6. HPA and VPA together
    7. Reading usage
  4. A troubleshooting method, not reconciled
  5. kubectl debug and ephemeral containers, not reconciled
  6. Debugging from the node: crictl, journalctl and nsenter, not reconciled
  7. Upgrades and version skew, not reconciled
  8. etcd, backup and disaster recovery, not reconciled
  9. GitOps with Argo CD, not reconciled
  10. Progressive delivery, not reconciled

Right-sizing and in-place resize

Requests decide placement and cost; limits decide how pods fail. Learn to resize a running pod in place, choose which changes restart a container, run the Vertical Pod Autoscaler, and size requests from usage.

  • 25 min
  • 4 objectives
  • 7 scenes

Shows the lesson one block at a time. Arrow keys step, number keys jump to a scene, and Escape returns to the page where you were.

Reconcile, in 7 scenes

Why right-size

A container’s request is what the scheduler reserves for it. A node is full when the requests on it reach its allocatable capacity, however idle the pods actually are, so over-requesting buys empty nodes. Requests also set CPU weight: when a node’s CPU is contended, each container gets spare cycles in proportion to its CPU request. Under-requesting packs pods onto nodes that cannot serve them all at peak.

A limit decides how a container fails. At its CPU limit a container is throttled: the kernel stops scheduling it for the rest of each 100 ms period, and requests queue up behind it. Throttling happens only at the limit; a container above its request but below its limit just competes for spare CPU. At its memory limit the kernel OOM-kills it, and the kubelet restarts it.

Requests and limits together set the pod’s QoS class, which is fixed at creation:

  • Guaranteed: every container sets CPU and memory requests and limits, with each request equal to its limit.
  • BestEffort: no container sets any CPU or memory request or limit.
  • Burstable: any other pod, such as one with requests only.

Throttling has a nasty interaction with probes. timeoutSeconds defaults to 1 second, and a throttled container can miss that deadline on a health endpoint that normally answers in milliseconds. The liveness probe fails, the kubelet restarts the container, and the restart looks like an application crash. kubectl top cannot show it, because the resource metrics API reports usage only. Throttling appears in cAdvisor’s container_cpu_cfs_throttled_periods_total, read as a fraction of container_cpu_cfs_periods_total.

Right-sizing pays off at the other end too. A Deployment scaled to zero, by hand or by an HPA with minReplicas: 0 on an External metric (beta and on by default in Kubernetes 1.37), uses no CPU, memory or compute quota. It still counts toward object-count quotas such as count/deployments.apps, and its objects stay in etcd.

In-place resize (GA 1.35)

Until Kubernetes 1.33 turned the feature on by default, changing a pod’s resources meant deleting it and creating another. In-place pod resize, beta and on by default in 1.33 and GA in 1.35, makes CPU and memory mutable on a running pod. Three fields describe a container’s resources:

  • spec.containers[].resources is the desired state, the field you change.
  • status.containerStatuses[].resources is what the runtime has actually configured for the running container.
  • status.containerStatuses[].allocatedResources is what the kubelet has accepted and reserved on the node. While a resize is incomplete, the scheduler counts the largest of desired, allocated and actual requests.

You do not write resources through the ordinary pod endpoint. A plain patch is still refused:

Resources are not an ordinary pod update
kubectl get pod api -o jsonpath='{.status.qosClass}'
Burstable
kubectl top pod api --containers
POD   NAME   CPU(cores)   MEMORY(bytes)   
api   api    100m         24Mi            
kubectl patch pod api -p '{"spec":{"containers":[{"name":"api","resources":{"requests":{"cpu":"150m"}}}]}}'
The Pod "api" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`,`spec.initContainers[*].image`,`spec.activeDeadlineSeconds`,`spec.tolerations` (only additions to existing tolerations),`spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)

Resizes go through the pod’s resize subresource, a separate endpoint with its own validation and its own RBAC permission (pods/resize). kubectl 1.32 and later can address it:

kubectl patch pod api --subresource resize --patch \
  '{"spec":{"containers":[{"name":"api","resources":{"requests":{"cpu":"200m"}}}]}}'
kubectl edit pod api --subresource resize
kubectl apply -f api.yaml --subresource resize --server-side

The kubelet does the work. When it sees desired resources that differ from allocated ones, it checks whether the requested values fit in the node’s allocatable capacity alongside every other pod’s allocated requests. If they fit, it records them in allocatedResources, asks the runtime through the CRI to update the container’s cgroup limits, and copies the result into status.containerStatuses[].resources. For a CPU change under NotRequired, the process never notices anything except more or less CPU time, and restartCount stays where it was. If they do not fit, the kubelet sets a pending condition instead, covered under resize status.

A resize changes one pod. Editing a Deployment’s pod template still rolls every pod, because the template hash changes; controllers do not resize the pods they already own. In-place resize is for operators and autoscalers acting on individual pods, and the Vertical Pod Autoscaler is its main user.

Resize policy

Each container chooses, per resource, whether a change needs a restart:

apiVersion: v1
kind: Pod
metadata:
  name: api
  labels:
    app: api
spec:
  containers:
    - name: api
      image: ghcr.io/kx-labs/web:1.1
      resizePolicy:
        - resourceName: cpu
          restartPolicy: NotRequired
        - resourceName: memory
          restartPolicy: RestartContainer
      resources:
        requests:
          cpu: 500m
          memory: 256Mi
        limits:
          memory: 256Mi

NotRequired, the default, applies the change to the running container by rewriting its cgroup. RestartContainer restarts the container with the updated values, which suits runtimes that size their heap at startup, such as a JVM with a fixed maximum heap: raising its memory limit in place gives it nothing. If one resize changes several resources and any of them is RestartContainer, the container restarts once and everything applies. A pod whose restartPolicy is Never must use NotRequired for every resource.

The other limits in Kubernetes 1.37:

  • Only CPU and memory can be resized.
  • Lowering a memory limit with NotRequired is best effort. If current usage is above the lower limit, the kubelet skips the resize and it stays in progress; usage can still spike after the check.
  • Requests and limits cannot be removed once set, only changed.
  • Ephemeral containers cannot be resized. Sidecar containers can, and so can running non-restartable init containers, with NotRequired only.
  • Windows pods, pods under the static CPU or memory manager policies, and memory changes on pods that use swap without RestartContainer are not supported.

Resizing memory-backed emptyDir volumes is alpha in 1.37 behind InPlacePodVerticalScalingMemoryBackedVolumes.

Resize status

Two pod conditions report a resize that has not simply succeeded:

  • PodResizePending means the kubelet has not accepted the change. Reason Infeasible: the node can never satisfy it, for example more CPU than the node has. Reason Deferred: it does not fit at the moment, and the kubelet retries, prioritising by priority class, then QoS, then how long a resize has waited. With the alpha InPlacePodVerticalScalingSchedulerPreemption gate in 1.37, the scheduler can also preempt lower-priority pods to make room for a deferred resize.
  • PodResizeInProgress means the kubelet accepted the change and is applying it. If applying fails, the condition carries reason Error and a message.

The message on each condition says what is missing. status.observedGeneration tells you which version of the spec the kubelet has seen, and each condition’s observedGeneration tells you which resize it describes, so a script can wait for its own request rather than an earlier one. While a resize is pending, status.containerStatuses[].resources keeps the old values; compare it with the spec to see what the container is really running with.

Vertical Pod Autoscaler

The Vertical Pod Autoscaler (VPA) is a separate project from SIG Autoscaling, installed as a CRD (autoscaling.k8s.io/v1) and three components:

  • The recommender watches usage history, from metrics-server or Prometheus, and writes recommendations into each VPA’s status: a target, a lowerBound and an upperBound per container.
  • The updater compares running pods with the recommendation and acts on pods outside the bounds, according to the update mode. It respects PodDisruptionBudgets when it evicts.
  • The admission controller is a mutating webhook that sets requests on pods from the recommendation as they are created.

The updatePolicy.updateMode decides how far it goes:

ModeBehaviour
OffRecommendations only, in status. Nothing changes.
InitialRequests set at pod creation only.
RecreatePods outside the bounds are evicted and recreated with the recommended requests. The default.
InPlaceOrRecreateResized in place through the resize subresource; evicted when in place is impossible. GA in VPA 1.6.0.
InPlaceResized in place only, never evicted. Alpha from VPA 1.7.0, behind the VPA’s InPlace feature gate.

VPA 1.5.0 deprecated Auto, an alias of Recreate. resourcePolicy.containerPolicies bounds what the VPA may do per container: minAllowed, maxAllowed, controlledResources to pick CPU, memory or both, and controlledValues to scale requests only or requests and limits in proportion.

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: api
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  updatePolicy:
    updateMode: InPlaceOrRecreate
  resourcePolicy:
    containerPolicies:
      - containerName: api
        controlledResources: ["cpu", "memory"]
        controlledValues: RequestsAndLimits
        minAllowed:
          cpu: 100m
          memory: 128Mi
        maxAllowed:
          cpu: "2"
          memory: 2Gi

The recommender keeps a decaying histogram of each container’s usage, so recent behaviour weighs more than last month’s, and recommends a high percentile of it with a safety margin. An OOM kill counts as evidence that memory was too low and pushes the memory recommendation up. The bounds give the updater room to leave pods alone: a pod whose requests sit between lowerBound and upperBound is not touched, which keeps the VPA from restarting pods over small changes.

The VPA never edits the Deployment. Under Recreate, the updater evicts a pod, the ReplicaSet creates a replacement from the unchanged template, and the admission controller rewrites the replacement’s requests on its way in. kubectl get deployment api -o yaml keeps showing the requests you wrote while the pods run with the VPA’s, which surprises anyone who reads only the manifest. With controlledValues: RequestsAndLimits, the VPA scales each limit by the same factor as its request, preserving the ratio you chose; with RequestsOnly, limits stay as written, and a request can grow until it meets the limit.

Start every VPA in Off and read kubectl describe vpa api for a few days before letting it act. The recommendation is the cheapest right-sizing report you will get.

HPA and VPA together

An HPA on CPU utilization divides usage by the request, and a VPA on CPU changes the request. Put both on the same workload and they chase each other: load rises, the VPA raises the request, utilization falls, the HPA removes pods, the remaining pods get busier, and the VPA moves again. The same holds for memory.

Give each autoscaler its own signal:

  • VPA on memory, HPA on CPU. Set controlledResources: ["memory"] on the VPA and keep the HPA on CPU utilization.
  • VPA on CPU and memory, HPA on a custom or external metric, such as requests per second or queue depth, which a request change does not move.
  • VPA in Off next to any HPA, using its recommendations to set requests by hand.

The HPA side keeps its own pacing: by default a 300-second scale-down stabilization window, scale-up by the larger of 100% or 4 pods per 15 seconds, and a 10% tolerance, which Kubernetes 1.37 lets you set per direction on each HPA.

Reading usage

One kubectl top sample is a snapshot of fifteen seconds of one pod. Requests should come from a distribution: usage across all replicas, over a window that includes your real peaks, at least a representative week with its busiest day.

For CPU, a high percentile of usage is a reasonable request, because short bursts above it borrow spare CPU without harm:

quantile_over_time(0.95,
  sum by (pod) (rate(container_cpu_usage_seconds_total{namespace="shop", container="api"}[5m]))[7d:5m])

For memory, take the maximum working set over the window and add headroom, because memory cannot be borrowed: a container over its limit is killed.

max_over_time(container_memory_working_set_bytes{namespace="shop", container="api"}[7d])

Size each container on its own numbers. A sidecar has its own requests, and a pod-level sum hides a proxy that is starved while the app idles. Treat startup separately as well: a runtime that burns two CPUs for thirty seconds of warm-up and 200m afterwards needs a request near 200m and a CPU limit, if it has one, high enough that warm-up finishes before the startup probe gives up. In-place resize allows a third option, an operator that grants extra CPU during startup and shrinks the container once it is ready.

Check the throttled fraction before and after a change. Some teams leave CPU limits off entirely so containers can use idle CPU, and set memory limits equal to memory requests so a pod never relies on memory it was not promised; whichever policy you choose, measure throttling and OOM kills after every change, because a request that matches last month’s usage is only right until the traffic changes.

Resize a pod in place on kind

  1. kubectl --context kind-kx run resize-demo --image=nginx:1.30 --overrides='{"spec":{"containers":[{"name":"resize-demo","image":"nginx:1.30","resizePolicy":[{"resourceName":"cpu","restartPolicy":"NotRequired"},{"resourceName":"memory","restartPolicy":"RestartContainer"}],"resources":{"requests":{"cpu":"200m","memory":"128Mi"},"limits":{"cpu":"200m","memory":"128Mi"}}}]}}'
  2. kubectl --context kind-kx patch pod resize-demo --subresource resize --patch '{"spec":{"containers":[{"name":"resize-demo","resources":{"requests":{"cpu":"400m"},"limits":{"cpu":"400m"}}}]}}'
  3. kubectl --context kind-kx get pod resize-demo -o jsonpath='{.status.containerStatuses[0].resources}{"\n"}{.status.containerStatuses[0].restartCount}{"\n"}'
  4. kubectl --context kind-kx patch pod resize-demo --subresource resize --patch '{"spec":{"containers":[{"name":"resize-demo","resources":{"requests":{"memory":"256Mi"},"limits":{"memory":"256Mi"}}}]}}'
  5. kubectl --context kind-kx get pod resize-demo -o jsonpath='{.status.containerStatuses[0].restartCount}{"\n"}'
  6. kubectl --context kind-kx patch pod resize-demo --subresource resize --patch '{"spec":{"containers":[{"name":"resize-demo","resources":{"limits":{"cpu":"800m"}}}]}}'
  7. kubectl --context kind-kx delete pod resize-demo

For your own kind cluster kx: copy a command and paste it into your terminal.Nothing on this page touches your machine. The CPU resize applies with a restart count of 0, the memory resize restarts the container once, and the last patch is rejected because the Guaranteed pod's CPU request would no longer equal its limit.

Actual state

Check your understanding

5 checks

Your first answer to each check is the one that counts. After a miss you can answer again; passing every check reconciles the lesson.

  1. Check 1 of 5

    A container's resizePolicy sets cpu to NotRequired and memory to RestartContainer. One resize raises both its CPU request and its memory limit. What happens to the container?

  2. Check 2 of 5

    After a resize, the pod has a PodResizePending condition with reason Deferred. What does that mean?

  3. Check 3 of 5

  4. Check 4 of 5

    You want the Vertical Pod Autoscaler's request recommendations for a payments service, but nothing may change its pods. Which updateMode?

  5. Check 5 of 5

    kubectl patch pod api -p '{"spec":{"containers":[{"name":"api","resources":{"requests":{"cpu":"150m"}}}]}}' fails with Forbidden: pod updates may not change fields other than .... Why?

Lesson not yet reconciled

Desired: 4 objectives, 0 metReconciled: 4 of 4 objectives met

  • Resize a running pod's CPU and memory through the resize subresource, GA in Kubernetes 1.35. (not yet met)
  • Set resizePolicy to choose which resource changes restart a container. (not yet met)
  • Run the Vertical Pod Autoscaler in recommendation-only or in-place modes. (not yet met)
  • Pick requests from observed usage instead of guesses. (not yet met)

Pass every check above to reconcile this lesson.

Every check has passed, so the desired state is met. First-try accuracy: 0 of 5. This lesson's review cards are in your queue.

Practice

Put this lesson to work on the simulated cluster. Everything runs in your browser, with nothing to install.

Changed since the notes

This lesson draws on an earlier set of study notes. Where the documentation contradicts a claim in them, qualifies it or has moved past it, the claim is listed here with the corrected statement and the source it was checked against.

Show 12 corrections
  1. Stale, true once, no longerCost Optimization

    The notes saidstandard HPA has a minimum of 1

    CorrectedThe HPAScaleToZero feature gate is beta and enabled by default in Kubernetes 1.37 (alpha from 1.16 to 1.36). minReplicas: 0 is accepted when the HPA has at least one object or external metric; HPAs scaling only on CPU/memory still need minReplicas >= 1. On clusters older than 1.37, including EKS, where alpha gates can't be enabled, the minimum is 1.

    Sourcekubernetes.io/docs/concepts/workloads/autoscaling/horizontal-pod-autoscale#scaling-to-and-from-zero

  2. Stale, true once, no longerCost Optimization

    The notes saidVPA updateMode values

    CorrectedVPA 1.5.0 deprecated updateMode 'Auto' (equivalent to 'Recreate', which is the default). Valid modes are Off, Initial, Recreate, InPlaceOrRecreate (in-place resize with eviction fallback; its feature gate was on by default from VPA 1.5.0 and removed in 1.7.0) and InPlace (in-place only, never evicts). The most recent VPA release as of 2026-11-19 is 1.8.1.

    Sourcegithub.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/docs/quickstart.md

  3. Stale, true once, no longerCost Optimization

    The notes saidhelm install kubecost kubecost/cost-analyzer --set kubecostToken=…

    CorrectedIBM acquired Kubecost (Sept 2024). Kubecost 3.x installs from the kubecost/kubecost chart (repo https://kubecost.github.io/kubecost) configured with global.clusterId; the cost-analyzer chart command is the 2.x path. Whether kubecostToken is still accepted is unconfirmed. AWS Split Cost Allocation Data for EKS adds pod-level costs to the Cost and Usage Report without a third-party tool.

    Sourcegithub.com/kubecost/kubecost%20;%20https://docs.aws.amazon.com/eks/latest/userguide/cost-monitoring-aws.html

  4. Wrong, not trueCost Optimization

    The notes saidThe eksctl example puts spot: true and instanceTypes under nodeGroups; those fields belong to managedNodeGroups

    CorrectedConfirmed. In eksctl, spot: true and instanceTypes are managedNodeGroups fields. Unmanaged nodeGroups don't support them and configure Spot through instancesDistribution instead.

    Sourcedocs.aws.amazon.com/eks/latest/eksctl/spot-instances.html

  5. Wrong, not trueCost Optimization

    The notes said'Each Service of type LoadBalancer creates an NLB or ALB'

    CorrectedConfirmed. A Service of type LoadBalancer gets an NLB from the AWS Load Balancer Controller (or a Classic Load Balancer from the legacy in-tree provider), never an ALB. ALBs come from Ingress or Gateway API resources handled by the controller.

    Sourcekubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/service/nlb

  6. Wrong, not trueCost Optimization

    The notes saidThe scale-down CronJob has no ServiceAccount or RBAC; scaling back with --replicas=1 discards original counts

    CorrectedConfirmed. The CronJob needs a ServiceAccount with a Role granting get, list and patch on deployments and deployments/scale in each target namespace; the default ServiceAccount gets Forbidden. Record each Deployment's replica count (for example in an annotation) before scaling to zero, and restore from it.

    Sourcekubernetes.io/docs/reference/access-authn-authz/rbac

  7. Nuance, true with conditionsCost Optimization

    The notes said'Deployments scaled to zero still consume namespace resources'

    CorrectedConfirmed. A Deployment at zero replicas runs no pods, so it uses no CPU or memory and no compute ResourceQuota. It still counts toward object-count quotas such as count/deployments.apps, and its objects stay in etcd.

    Sourcekubernetes.io/docs/concepts/policy/resource-quotas

  8. Nuance, true with conditionsPerformance Tuning

    The notes saidHPA behavior defaults implied

    CorrectedDefaults: scale-down stabilization window 300s; scale-up has no stabilization and allows the larger of 100% or 4 pods per 15s; global tolerance 10%. Per-HPA tolerance in spec.behavior (HPAConfigurableTolerance) was alpha in 1.33, beta in 1.35 and GA in 1.37.

    Sourcekubernetes.io/docs/concepts/workloads/autoscaling/horizontal-pod-autoscale

  9. Stale, true once, no longerPerformance Tuning

    The notes saidRight-sizing by changing requests (implies restart)

    CorrectedIn-place pod resize (InPlacePodVerticalScaling) is GA in Kubernetes 1.35 (beta in 1.33). CPU and memory requests and limits can be changed through the pods/resize subresource without recreating the pod, subject to each container's resizePolicy. Editing a Deployment's pod template still rolls the pods.

    Sourcekubernetes.io/docs/tasks/configure-pod-container/resize-container-resources

  10. Wrong, not truePerformance Tuning

    The notes said'kubectl top pods --containers' to 'check for throttling'

    CorrectedConfirmed. kubectl top reports CPU and memory usage only. Throttling shows in cAdvisor's container_cpu_cfs_throttled_periods_total and container_cpu_cfs_periods_total.

    Sourcekubernetes.io/docs/tasks/debug/debug-cluster/resource-metrics-pipeline

  11. Nuance, true with conditionsPerformance Tuning

    The notes saidQoS definitions are oversimplified

    CorrectedConfirmed. Guaranteed: every container sets CPU and memory requests and limits, with requests equal to limits. BestEffort: no container sets any CPU or memory request or limit. Burstable: any pod that is neither, such as one with requests only.

    Sourcekubernetes.io/docs/concepts/workloads/pods/pod-qos

  12. Nuance, true with conditionsPerformance Tuning

    The notes saidProbe example sets timeoutSeconds: 5 but never mentions that the default is 1s

    CorrectedConfirmed. timeoutSeconds defaults to 1 second (minimum 1), a common cause of spurious liveness failures on slow endpoints; state the default next to the example.

    Sourcekubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes

Every correction across the guide, by note and topic.

Sources

Checked against kubernetes.io and AWS documentation for Kubernetes 1.37 on .

  1. kubernetes.io/docs/tasks/configure-pod-container/resize-container-resources
  2. kubernetes.io/docs/tasks/configure-pod-container/resize-pod-resources
  3. kubernetes.io/blog/2025/12/19/kubernetes-v1-35-in-place-pod-resize-ga
  4. kubernetes.io/docs/concepts/configuration/manage-resources-containers
  5. kubernetes.io/docs/concepts/workloads/pods/pod-qos
  6. kubernetes.io/docs/concepts/workloads/autoscaling/vertical-pod-autoscale
  7. kubernetes.io/docs/concepts/workloads/autoscaling/horizontal-pod-autoscale
  8. kubernetes.io/docs/concepts/configuration/liveness-readiness-startup-probes
  9. kubernetes.io/docs/concepts/policy/resource-quotas
  10. github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler
  11. github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/docs/features.md

Right-sizing and in-place resize

↓ ↑ step, 1 to 7 scene, Esc leave

kind cluster kxLast command: Nothing run yet