QA
Senior LevelDocker & Deployment

How do you configure Vertical Pod Autoscaler (VPA) and Horizontal Pod Autoscaler (HPA) to coexist without feedback loops?

❓ Interview Prompt: Explain VPA/HPA conflicts on CPU/RAM metrics, safe coexistence strategies, and using HPA on custom metrics with VPA in Recommend mode.

The VPA + HPA Conflict:

If both VPA and HPA are configured to scale on CPU utilization, they create a feedback loop:

1
CPU spikes → HPA scales out (more pods).
2
CPU drops (spread across more pods) → VPA decreases CPU requests.
3
Decreased CPU requests → CPU utilization % rises again (same CPU / lower request).
4
Loop repeats → thrashing.

Root Cause:

HPA CPU utilization = actualCPU / requestedCPU. If VPA changes requestedCPU, the HPA metric changes even though actual load hasn't.

Safe Coexistence Strategy 1: VPA Recommend + Manual Apply:

Set VPA to updateMode: Off (or Initial) — VPA only recommends resource values without applying them. Review weekly and manually update requests/limits. No conflict possible.

Safe Coexistence Strategy 2: HPA on Custom Metrics:

•
HPA scales on custom business metrics (e.g., requests-per-second, queue depth via KEDA) — NOT CPU/RAM.
•
VPA manages CPU/RAM requests/limits — no conflict since HPA doesn't look at CPU/RAM.
•
This is the recommended production pattern for high-traffic services.

Safe Coexistence Strategy 3: Separate Workloads:

•
VPA only on batch/scheduled jobs (no horizontal scaling needed).
•
HPA only on stateless services (no vertical sizing needed).

Code Implementation Example

yaml
# VPA in Recommend mode — suggests but doesn't auto-apply
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: api-vpa
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  updatePolicy:
    updateMode: "Off"    # Recommend only — no automatic updates
  resourcePolicy:
    containerPolicies:
      - containerName: api
        minAllowed:
          cpu: 100m
          memory: 128Mi
        maxAllowed:
          cpu: 4000m
          memory: 4Gi

---
# HPA on CUSTOM metrics (requests/sec) — no CPU/RAM conflict with VPA
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 2
  maxReplicas: 50
  metrics:
    # Custom metric from Prometheus — NOT CPU/RAM (avoid VPA conflict)
    - type: Pods
      pods:
        metric:
          name: http_requests_per_second   # from Prometheus adapter
        target:
          type: AverageValue
          averageValue: "100"   # 100 req/s per pod
💡VPA in Recommend mode + HPA on custom RPS metric = no feedback loop. VPA suggests sizes; HPA handles traffic bursts.
🎯 Interview Key Takeaway

Never run VPA and HPA both on CPU/RAM — they create feedback loops. Safe patterns: VPA recommend-only + HPA on custom metrics, or use KEDA for event-driven scaling alongside VPA.

#Kubernetes#VPA#HPA#Autoscaling#Feedback Loop#Senior
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?