This is a stable feature in Kubernetes, and has been since version v1.38. It was first available in the v1.35 release. You can no longer disable or opt out of this feature or behavior (it is locked); if you explicitly set a value for the associated feature gate InPlacePodLevelResourcesVerticalScaling, Kubernetes ignores it but does not report any error.
This page explains how to change the CPU and memory resources set at the Pod level without recreating the Pod.
The In-place Pod Resize feature allows modifying resource allocations for a running Pod, avoiding application disruption. The process for resizing individual container resources is covered in Resize CPU and Memory Resources assigned to Containers.
This page highlights in-place Pod-level resources resize. Pod-level resources
are defined in spec.resources and act as the upper bound on the aggregate resources
consumed by all containers in the Pod. In-place Pod-level resize lets you change
these aggregate CPU and memory allocations for a running Pod directly.
Key Concepts:
spec.resources): The mutable Pod-level CPU and memory
requests and limits updated through the Pod's /resize subresource.status.resources): The Pod-level resource requests and
limits currently configured for the running Pod on the node (including any
spec.overhead; for limits, overhead is added only to non-zero limits).status.allocatedResources): The total resource
requests admitted and allocated for the Pod by the kubelet on the node
(including any spec.overhead). When a resize is pending or in progress, the
scheduler accounts for the maximum of desired, allocated, and actual requests.You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as control plane hosts. If you do not already have a cluster, you can create one by using minikube or you can use one of these Kubernetes playgrounds:
Your Kubernetes server must be at or later than version 1.36.To check the version, enter kubectl version.
kubectl client version must be at least v1.32 to use the --subresource=resize flag.UpdatePodSandboxResources API
(such as containerd v2.3.0 or later, or CRI-O v1.33.0 or later) on Linux worker nodes is
recommended so the runtime stays in sync with Pod-level resource updates (on runtimes that
do not implement it yet, kubelet proceeds best-effort).The mechanism the kubelet uses to track and retry resource changes is shared between container-level and Pod-level resize requests.
The statuses, reasons, and retry priorities are identical to those defined for container resize:
Status Conditions: The kubelet uses PodResizePending (with reasons Infeasible or Deferred) and PodResizeInProgress to communicate the state of the request.
Retry Priority: Deferred resizes are retried based on PriorityClass, then QoS class (Guaranteed over Burstable), and finally by the duration they have been deferred.
Tracking: You can use the observedGeneration fields to track which Pod specification (metadata.generation) corresponds to the status of the latest processed resize request.
For a full description of these conditions and retry logic, refer to the Pod resize status section in the container resize documentation.
Pod-level resource resize does not support or require its own restart policy.
No Pod-Level Policy: Changes to the Pod's aggregate resources (spec.resources) are always applied in-place without triggering a Pod-wide restart. This is because Pod-level resources act as an overall constraint on the Pod's cgroup and do not directly manage the application runtime within containers.
Container Policy Still Governs: The resizePolicy must still be configured at the container level (spec.containers[*].resizePolicy, and spec.initContainers[*].resizePolicy for sidecar containers). This policy governs whether an individual container is restarted when its effective resource requests or limits change, regardless of whether that change was initiated by a direct container-level resize or by an update to the Pod-level resource specification.
For Kubernetes 1.38, resizing Pod-level resources in-place is subject to all the limitations described for container-level resource resize, which you can find here: Resize CPU and Memory Resources assigned to Containers: Limitations.
Additionally, the following constraints are specific to Pod-level resource resize:
Container Requests Validation: A resize is only permitted if the resulting
Pod-level resource requests (spec.resources.requests) are greater than or equal to
the effective aggregate resource requests of the containers in the Pod (including
init and sidecar containers). This maintains the minimum guaranteed resource
availability for the Pod.
Container Limits Validation: A resize is permitted only if each individual
container's limit (including init and sidecar containers) is less than or equal to
the Pod-level resource limit (spec.resources.limits). The Pod-level limit serves
as a boundary that no single container may exceed, while the sum of container CPU
or memory limits is permitted to exceed the Pod-level limit, enabling resource
sharing across containers within the Pod.
Resource Removal: You can add or modify Pod-level CPU and memory requests and
limits on a running Pod without changing its QoS class, but once spec.resources
or an individual Pod-level request or limit is set, it cannot be removed.
Swap (LimitedSwap): On nodes configured with LimitedSwap, a swap-eligible
Pod's cgroup swap limit is configured at Pod creation rather than resized in place.
Resizes that change Pod swap eligibility, change effective Pod memory requests for a
swap-eligible Pod, or add Pod-level resources to a running swap-enabled container-only
Pod are rejected as Infeasible, even if containers set RestartContainer as their
memory resize policy. (CPU-only resizes, memory limit changes that preserve swap
eligibility, and resizes on non-swap-eligible Pods remain allowed.)
Exclusive CPUs: If your nodes use the
static CPU manager policy
and both the InPlacePodVerticalScalingExclusiveCPUs and the PodLevelResourceManagers
feature gates are enabled,
the kubelet rejects as infeasible any resize that changes the number of exclusive CPUs
of a Guaranteed pod with pod-level resources. This affects the pod-level CPU request and
the CPU request of each container whenever the previous or the new value is an integer
number of CPUs. For example, resizes from 2 to 3 CPUs, from 800m to 2, or from
2 to 1500m are infeasible. Fractional-to-fractional resizes, such as 200m to 300m,
are unaffected. Adding or removing a container that uses exclusive CPUs is also infeasible
even when you do not enable the PodLevelResourceManagers feature gate.
For more information, see
Resize CPU Resources of Pods with Exclusive CPUs.
First, create a Pod with pause configured for in-place CPU resize (NotRequired) and nginx-server configured to restart on CPU resize (RestartContainer) without explicit container-level limits.
apiVersion: v1
kind: Pod
metadata:
name: pod-level-resize-demo
spec:
containers:
- name: pause
image: registry.k8s.io/pause:3.9
resizePolicy:
- resourceName: cpu
restartPolicy: NotRequired # Default, but explicit here
- resourceName: memory
restartPolicy: RestartContainer
resources:
requests:
cpu: 100m
memory: 100Mi
- name: nginx-server
image: registry.k8s.io/nginx:latest
resizePolicy:
- resourceName: cpu
restartPolicy: RestartContainer
- resourceName: memory
restartPolicy: RestartContainer
resources: # Pod-level resources
requests:
cpu: 200m
memory: 200Mi
limits:
cpu: 200m
memory: 200Mi
Create the pod:
kubectl create -f pod-level-resize.yaml
This pod starts in the Guaranteed QoS class as pod-level requests are equal to limits. Verify its initial state:
# Wait a moment for the pod to be running
kubectl get pod pod-level-resize-demo --output=yaml
Observe spec.resources, status.resources, and status.allocatedResources
(200m CPU, 200Mi memory). Note that
status.containerStatuses[0].restartCount (pause) and
status.containerStatuses[1].restartCount (nginx-server) are both 0.
Now, increase the pod-level CPU request and limit to 300m. You use kubectl patch with the --subresource resize command line argument.
kubectl patch pod pod-level-resize-demo --subresource resize --patch \
'{"spec":{"resources":{"requests":{"cpu":"300m"}, "limits":{"cpu":"300m"}}}}'
# Alternative methods:
# kubectl edit pod pod-level-resize-demo --subresource resize
# kubectl apply -f <updated-manifest> --subresource resize --server-side
--subresource resize command line argument requires kubectl client version v1.32.0 or later.
Older versions will report an invalid subresource error.Check the pod status again after patching:
kubectl get pod pod-level-resize-demo --output=yaml
You should see:
spec.resources.requests and spec.resources.limits now show cpu: 300m.status.resources and status.allocatedResources
reflect cpu: 300m.status.containerStatuses[0].restartCount (pause) remains 0, because its
CPU resizePolicy is NotRequired.status.containerStatuses[1].restartCount (nginx-server) increased to 1,
indicating the container was restarted to apply the CPU change. Because
nginx-server did not define an explicit container-level CPU limit, it
inherited the Pod-level CPU limit as its effective limit. Updating
spec.resources.limits.cpu from 200m to 300m changed that effective limit,
so the kubelet honored nginx-server's RestartContainer CPU resize policy
and restarted the container.Delete the pod:
kubectl delete pod pod-level-resize-demo