Explain resource requests and limits, QoS classes and autoscaling (HPA, VPA, cluster autoscaler, KEDA).
Requests and limits
- Requests: what the scheduler reserves on a node; they determine placement and the CPU share under contention.
- Limits: hard caps. Exceeding memory gets the container OOMKilled; exceeding CPU throttles it (it is never killed for CPU).
QoS classes (eviction order under node pressure)
- Guaranteed: every container has requests equal to limits for CPU and memory. Evicted last.
- Burstable: some requests set, lower than limits.
- BestEffort: nothing set. Evicted first. For Java services: memory request = limit (memory is not compressible, and the heap is sized from it); CPU request set from measurement, CPU limit often omitted to avoid throttling.
Autoscaling
- HPA (Horizontal Pod Autoscaler): changes replica count to keep a metric at a target: CPU utilisation relative to requests, memory, or custom and external metrics (requests per second, Kafka lag) via the metrics APIs (Prometheus Adapter, cloud adapters). Configure
behaviorto scale up fast and down slowly. - VPA (Vertical Pod Autoscaler): recommends or applies request sizes; do not combine with HPA on the same CPU/memory metric. Use recommendation mode to right-size.
- Cluster Autoscaler / Karpenter: add nodes when pods are pending for lack of capacity, remove underused nodes.
- KEDA: event-driven autoscaling on queue length, Kafka lag, cron schedules and more, including scale to zero.
Availability during scaling and maintenance
PodDisruptionBudgets (minAvailable), topology spread across zones, and pod priority classes for critical workloads.
Example
yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata: { name: orders }
spec:
scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: orders }
minReplicas: 3
maxReplicas: 30
metrics:
- type: Resource
resource: { name: cpu, target: { type: Utilization, averageUtilization: 60 } }
behavior:
scaleDown: { stabilizationWindowSeconds: 300 }Follow-up questions interviewers ask
Try answering each one before you open it.
Why is CPU-based HPA sometimes a poor fit for Java services?
JVM startup and JIT warm-up burn CPU, so new pods look busy and can trigger further scale-ups; GC activity adds noise; and I/O-bound services may saturate thread or connection pools while CPU stays low. Scaling on request rate per pod, latency, or queue/Kafka lag (via KEDA or custom metrics) usually tracks real load better. Add warm-up (CDS, readiness gated until warm) so new pods help quickly.