Kubernetes interview question · Most asked
How does autoscaling work in Kubernetes? Compare HPA, VPA, Cluster Autoscaler and Karpenter.
Summary
The Horizontal Pod Autoscaler changes the number of replicas based on metrics (CPU, memory, or custom and external metrics); the Vertical Pod Autoscaler recommends or sets CPU and memory requests; the Cluster Autoscaler and Karpenter add and remove nodes so pending pods can be scheduled and empty nodes are removed.
Longer Answer
- HPA needs the metrics server (or a metrics adapter such as Prometheus Adapter or KEDA for queue length and other event sources). CPU-based HPA only works if CPU requests are set and CPU reflects load.
- VPA and HPA should not both act on the same resource metric for the same workload.
- Cluster Autoscaler scales predefined node groups; Karpenter provisions right-sized nodes directly from pending pods' requirements and consolidates under-used nodes, which is often faster and cheaper (mainly on AWS, also on other clouds through providers).
Scaling chains add latency: a traffic spike must be detected, pods created, nodes provisioned (minutes) and images pulled, so keep headroom or over-provision with low-priority placeholder pods.
Key Points
- HPA: replicas; VPA: requests; CA/Karpenter: nodes.
- HPA needs metrics and requests.
- KEDA for event-driven scaling.
- Node scaling takes minutes; keep headroom.
More most-asked Kubernetes questions
- ConfigMaps and Secrets: how do they differ, and how should secrets really be handled?
- How does the scheduler place pods? Explain resource requests, node affinity, taints and tolerations.
- Describe the Kubernetes architecture: what runs on the control plane and what runs on the nodes?
- How do rolling updates work in a Deployment, and how do you roll back?
- Explain the Service types: ClusterIP, NodePort, LoadBalancer, ExternalName and headless.
- What happens, step by step, when you run kubectl apply for a Deployment?
- Deployment, StatefulSet, DaemonSet, Job and CronJob: when do you use each?
- What is the difference between resource requests and limits, and what are the QoS classes?