Skip to content

VPA resource policy containerPolicies

containerPolicies is a configuration field within the resourcePolicy section of a Vertical Pod Autoscaler (VPA) manifest.^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md] It allows administrators to define granular rules and constraints for how the VPA manages resources for specific containers within a target workload^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md].

Configuration Fields

The containerPolicies field accepts a list of policy objects. Each object can contain the following sub-fields to control autoscaling behavior^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md]:

  • containerName: Specifies the scope of the policy. It can be set to the name of a specific container or use the wildcard * to target all containers within the Pod^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md].
  • minAllowed: Defines the minimum amount of resources (CPU or Memory) that the VPA will recommend^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md]. This sets a floor for resource requests.
  • maxAllowed: Defines the maximum amount of resources (CPU or Memory) that the VPA will recommend^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md]. This sets a ceiling to prevent over-provisioning.
  • controlledResources: A list indicating which specific resource types (e.g., cpu and/or memory) are subject to monitoring and adjustment by the VPA^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md].

Example Usage

In a practical scenario, containerPolicies is used to ensure that recommended values stay within a safe operating range. The following example demonstrates a policy applied to all containers (*), setting CPU constraints and monitoring both CPU and memory^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md]:

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: hamster-vpa
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: hamster
  resourcePolicy:
    containerPolicies:
      - containerName: '*'
        minAllowed:
          cpu: 100m
          memory: 50Mi
        maxAllowed:
          cpu: 1
          memory: 500Mi
        controlledResources: ["cpu", "memory"]

Impact on Recommendations

The values defined in containerPolicies directly affect the VPA's status output. When bounds are set, the VPA generates different recommendation types^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md]:

  • Target: The recommended value that falls within the minAllowed and maxAllowed range^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md].
  • Uncapped Target: The recommended value calculated without considering the minAllowed and maxAllowed constraints^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md].
  • Lower Bound: The lower limit of the recommended range. If a Pod's current request is below this, the VPA may initiate eviction (in Auto or Recreate modes) to resize it^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md].
  • Upper Bound: The upper limit of the recommended range. If a Pod's current request exceeds this, the VPA may initiate eviction to resize it^[400-devops__06-Kubernetes__k8s-ithelp__Day27__README.md].

Sources