2 min read

Resize memory/cpu limit without restarting the pod (in-place resizing) in Kubernetes

Pod resource resizing is a work for professional craftsmen. Under estimation / overbooking are big enemies out there. Do you know that you can increase a pod resource without any container(s) restarts needed?
Resize memory/cpu limit without restarting the pod (in-place resizing) in Kubernetes

Tuning pods' resources is a pain of work, we all know.

And another pain is also the fact that once reconfigured even if automatically with vertical pod autoscaler feature, pods automatically get restarted.

But a new feature [alpha in Kubernetes 1.27] is out there...

Ladies and gentlemen, let's say welcome to in place pod vertical autoscaler 🥳🥳🥳
And YES, with this feature you can decide if a container has to be restarted or not on cpu/memory resource change.

⚠️
In order to use this feature check if you have enabled the following feature gate InPlacePodVerticalScaling

Example of usage

InPlacePodVerticalScaling introduces a new configuration under spec.containers.resizePolicy which determinate if the specific container has to be restarted on cpu/memory change:

  • resizePolicy configuration is container specific, so the policy could vary on containers inside the same pod;
  • we probably want to continue having a pod restart on memory request/limit change but get the benefits of in-place pod vertical autoscaler feature only for CPU request/limit change. This is possible using resourceName: cpu/memory.

    This could be essential on runtime (ex. JRE) that does not automatically inherit hot memory extension. Check out your runtime documentation for more details.

Let's see an example..

apiVersion: v1
kind: Pod
metadata:
  name: qos-demo-5
  namespace: qos-example
spec:
  containers:
  - name: qos-demo-ctr-5
    image: nginx
    resizePolicy:
    - resourceName: cpu
      restartPolicy: NotRequired
    - resourceName: memory
      restartPolicy: RestartContainer
    resources:
      limits:
        memory: "200Mi"
        cpu: "700m"
      requests:
        memory: "200Mi"
        cpu: "700m"

Official reference 👇

Resize CPU and Memory Resources assigned to Containers
FEATURE STATE: Kubernetes v1.27 [alpha] This page assumes that you are familiar with Quality of Service for Kubernetes Pods. This page shows how to resize CPU and memory resources assigned to containers of a running pod without restarting the pod or its containers. A Kubernetes node allocates resour…
Tweets by YBacciarini