Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 416 of 8026. Kubernetes Traffic and ScalingFree lesson

Managing Pod Eviction Constraints During Vertical Scaling

You will configure update policies to control how and when the Vertical Pod Autoscaler restarts pods to apply new resource recommendations.

In this lesson, you will learn how to prevent service disruption by configuring updatePolicy settings to control how the Vertical Pod Autoscaler (VPA) restarts your pods.

The Challenge of Automatic Scaling

When the VPA Recommender suggests new resource requests for a container, Kubernetes must restart the existing pod to apply these changes. If your workload consists of a single replica, a sudden restart could cause downtime. If you have many replicas, restarting them all at once can overwhelm the remaining capacity of your cluster.

Controlling the Update Lifecycle

To manage these interruptions, we use the updatePolicy field within the VPA configuration. This allows you to define exactly when and how the VPA applies its recommendations.

There are two primary modes for the updateMode field:

  • Auto: The VPA automatically updates pod resources and triggers restarts.
  • Off: The VPA only provides recommendations; you must manually update the pod configuration.

If you choose Auto, you can use evictionRequirements (or specific updatePolicy constraints) to ensure your application stays available during these transitions. For example, by setting a minReplicas requirement, you can ensure that the VPA never terminates a pod if it would drop your active replica count below a safe threshold.

Example: Defining an Update Policy

Here is how you define a VPA that balances automatic resource management with availability:

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: my-app-vpa
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: my-app
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
      - containerName: '*'
        minAllowed:
          cpu: "100m"
          memory: "50Mi"

By default, the VPA respects your PodDisruptionBudgets (PDBs). If you have a PDB defined for your deployment, the VPA will not restart more pods than the PDB allows. This creates a safety net, ensuring that even when the VPA is configured for automatic scaling, it cannot violate your defined availability constraints.

Key Takeaway: Use updateMode: "Auto" in conjunction with PodDisruptionBudgets to allow the VPA to scale your resources dynamically without compromising application availability.