To use this feature, you (or a cluster administrator) will need to enable the InPlacePodVerticalScalingExclusiveCPUs feature gate for all relevant components in your cluster.
See Enable Or Disable Feature Gates for more information.
This page explains how to change the number of CPUs assigned to a running container without restarting it, when the container uses CPUs that the kubelet allocated exclusively for that container.
This page covers in-place resize for containers that use exclusive CPUs. For general in-place resizing of CPU and memory, see Resize CPU and Memory Resources assigned to Containers.
The InPlacePodVerticalScalingExclusiveCPUs feature gate was introduced in
Kubernetes 1.32. The kubelet implements the behavior described on this page
starting with Kubernetes 1.38.
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.38.To check the version, enter kubectl version.
You need the following for the exercise on this page:
InPlacePodVerticalScalingExclusiveCPUs feature gate
enabled for all nodes in your cluster.kubectl client at version v1.32 or later, to use the --subresource=resize flag.kube-system Pods.With the static CPU manager policy, the kubelet assigns CPUs exclusively to containers in Guaranteed Pods that request an integer number of CPUs. In a Guaranteed Pod, the CPU request equals the CPU limit. A container that uses exclusive CPUs runs only on these CPUs and does not share them with other containers. The kubelet runs all other containers on the remaining CPUs of the node, which are called the shared pool.
The baseline CPUs of a container are the exclusive CPUs that the kubelet assigned to that container when it started. The kubelet keeps the baseline CPUs assigned to the container across resizes.
You change the CPU request and limit of a container that uses exclusive CPUs by
updating the Pod's resize subresource, for example with kubectl patch. The
kubelet changes the CPU assignment of the running container. For the default CPU
resizePolicy of NotRequired, the container does not restart, and
status.containerStatuses[*].restartCount does not change.
Depending on the direction of the resize, the kubelet behaves as follows:
none, the new CPUs also match the Pod's NUMA affinity.In most cases, when the kubelet cannot fulfill a resize, it rejects the resize
as infeasible and does not retry it. The Pod gets a PodResizePending condition
with reason: Infeasible, and the kubelet increments the
kubelet_pod_infeasible_resizes_total metric. The following resize requests are
infeasible for a container that uses exclusive CPUs:
full-pcpus-only
option and the requested CPU count does not satisfy the SMT alignment: the
count is not a multiple of the CPUs per physical core, or the node does not
have enough free physical CPUs.In one case the kubelet defers a resize instead of rejecting it: the CPU Manager
can allocate the requested CPUs, but the total CPU requests of the Pods on the
node, including the resized Pod, exceed the allocatable CPU of the node, for
example because of the requests of Pods in the shared pool.
The Pod gets a PodResizePending condition with reason: Deferred, and the
kubelet retries the resize when other Pods release capacity.
Pods that request fractional CPUs, such as 800m, run in the shared pool. When
the InPlacePodVerticalScalingExclusiveCPUs feature gate is enabled, the kubelet
resizes these Pods in-place as usual. For example, a Guaranteed Pod with a CPU
request of 800m can resize to 1500m in-place. This resize path does not use
exclusive CPUs.
If you configure a
Topology Manager policy
other than none, the kubelet considers the NUMA affinity when it allocates the
new CPUs:
pod scope, the kubelet aligns the CPUs of all containers of the Pod
together. With the container scope, the kubelet aligns only the CPUs of the
resized container.pod scope and the restricted or single-numa-node policy, a
single resize request can change the exclusive CPUs of only one container. To
resize several containers, send one resize request per container.PodResizePending condition of reason: Infeasible and the message
Resources cannot be allocated with Topology locality. The kubelet does not
retry such a resize. With the restricted or single-numa-node policy, this
can also affect a scale-down. A scale-down only keeps CPUs that the container
already uses, but the preferred NUMA affinity is the narrowest one that fits
the new CPU count. If the CPUs that the container keeps do not fit into that
affinity, the kubelet rejects the scale-down.Create a namespace for this exercise:
kubectl create namespace cpu-exclusive-example
apiVersion: v1
kind: Pod
metadata:
name: resize-exclusive-cpus-demo
namespace: cpu-exclusive-example
spec:
containers:
- name: app-container
image: busybox:1.28
command:
- sh
- -c
- while true; do sleep 3600; done
resizePolicy:
- resourceName: cpu
restartPolicy: NotRequired # the default, but explicit here
resources:
requests:
cpu: "2"
memory: "200Mi"
limits:
cpu: "2"
memory: "200Mi"
The container in this Pod has no workload of its own. You verify its CPU
assignment by reading the Cpus_allowed_list field from the container's
/proc filesystem.
Create the Pod:
kubectl apply -f https://k8s.io/examples/pods/resource/pod-resize-exclusive-cpus.yaml \
-n cpu-exclusive-example
Wait for the Pod to become ready:
kubectl wait --for=condition=Ready pod/resize-exclusive-cpus-demo -n cpu-exclusive-example
The output is similar to this:
pod/resize-exclusive-cpus-demo condition met
Check the container's CPUs:
kubectl exec resize-exclusive-cpus-demo -n cpu-exclusive-example -- \
grep Cpus_allowed_list /proc/1/status
The output is similar to this:
Cpus_allowed_list: 1-2
The exact CPUs depend on your node. Verify the CPU assignment in the Pod status:
kubectl get pod resize-exclusive-cpus-demo -n cpu-exclusive-example --output=yaml
The output shows:
spec.containers[0].resources with a CPU request and limit of 2.status.containerStatuses[0].allocatedResources with cpu set to 2.status.containerStatuses[0].resources with cpu set to 2.status.containerStatuses[0].restartCount equal to 0.Increase the CPU request and limit from 2 to 3:
kubectl -n cpu-exclusive-example patch pod resize-exclusive-cpus-demo --subresource resize --patch \
'{"spec":{"containers":[{"name":"app-container","resources":{"requests":{"cpu":"3"},"limits":{"cpu":"3"}}}]}}'
Check the Pod status again:
kubectl get pod resize-exclusive-cpus-demo -n cpu-exclusive-example --output=yaml
The output shows:
spec.containers[0].resources with a CPU request and limit of 3.status.containerStatuses[0].allocatedResources with cpu set to 3.status.containerStatuses[0].resources with cpu set to 3.status.containerStatuses[0].restartCount still 0.Check the container's CPUs again:
kubectl exec resize-exclusive-cpus-demo -n cpu-exclusive-example -- \
grep Cpus_allowed_list /proc/1/status
The output is similar to this:
Cpus_allowed_list: 1-3
The container kept its baseline CPUs 1-2 and received the additional CPU 3 from the shared pool.
Decrease the CPU request and limit to 2500m. A container that uses exclusive CPUs cannot move to the shared pool, so the kubelet rejects this resize:
kubectl -n cpu-exclusive-example patch pod resize-exclusive-cpus-demo --subresource resize --patch \
'{"spec":{"containers":[{"name":"app-container","resources":{"requests":{"cpu":"2500m"},"limits":{"cpu":"2500m"}}}]}}'
Check the Pod status:
kubectl get pod resize-exclusive-cpus-demo -n cpu-exclusive-example --output=yaml
The output shows:
PodResizePending condition with reason: Infeasible. The condition's
message contains cannot move container from exclusive to shared pool, (requested CPUs = 2500m).spec.containers[0].resources with cpu set to 2500m, the desired state of
the pending resize request.status.containerStatuses[0].resources still with cpu set to 3.status.containerStatuses[0].restartCount still 0.Verify that the container still runs on its previous CPUs:
kubectl exec resize-exclusive-cpus-demo -n cpu-exclusive-example -- \
grep Cpus_allowed_list /proc/1/status
The output is similar to this:
Cpus_allowed_list: 1-3
The pending resize request stays in the Pod spec until you send another resize request.
Decrease the CPU request and limit from 3 back to 2:
kubectl -n cpu-exclusive-example patch pod resize-exclusive-cpus-demo --subresource resize --patch \
'{"spec":{"containers":[{"name":"app-container","resources":{"requests":{"cpu":"2"},"limits":{"cpu":"2"}}}]}}'
Check the container's CPUs again:
kubectl exec resize-exclusive-cpus-demo -n cpu-exclusive-example -- \
grep Cpus_allowed_list /proc/1/status
The output is similar to this:
Cpus_allowed_list: 1-2
The container keeps its baseline CPUs 1-2. The kubelet returned the extra CPU to the shared pool, where other Pods can use it.
Delete the namespace. This deletes the Pod from this exercise:
kubectl delete namespace cpu-exclusive-example
When the kubelet cannot apply a resize, the Pod gets a PodResizePending
condition. The condition reason is Deferred when the resize can succeed
later, and Infeasible when it cannot succeed. The message field of the
condition explains the reason. For an infeasible resize, the kubelet also
increments the kubelet_pod_infeasible_resizes_total metric, with a
reason_detail label that identifies the reason. For more information about
resize status conditions, see
Pod resize status.
Common reasons why the kubelet does not apply a CPU resize of a container that uses exclusive CPUs:
InPlacePodVerticalScalingExclusiveCPUs feature gate. The
condition message contains Resize is infeasible for Guaranteed Pods. Enable
the feature gate on your nodes.message contains Unable to resize container exclusively allocated pool and not enough cpus available to satisfy request, and the kubelet does not retry the resize. Free CPUs and then send
the resize request again, or send a resize request for fewer CPUs. With the
restricted or single-numa-node Topology Manager policy, the Topology
Manager rejects the resize before the CPU Manager allocates CPUs, and the
condition's message is Resources cannot be allocated with Topology locality instead.reason is Deferred, and the kubelet retries the resize when
other Pods release capacity.message contains not allowed to reduce container exclusively allocated pool below baseline.full-pcpus-only static policy option, the
condition's message contains SMT Alignment Error when the requested CPU
count is not a multiple of the CPUs per physical core, or the node does not
have enough free physical CPUs. The kubelet does not retry the resize. Send a
new resize request for a multiple of the CPUs per physical core, or free
physical CPUs and then send the resize request again.message is Resources cannot be allocated with Topology locality, and the
kubelet does not retry the resize. For a scale-up, free CPUs that give the
topology room to align and then send the resize request again. For a
scale-down, freeing CPUs does not help, because the container keeps only CPUs
that it already uses. Send a resize request for a different CPU count
instead. In both cases, you can also use a less restrictive Topology Manager
policy.pod scope and the
restricted or single-numa-node policy, the condition's message contains
not allowed to resize exclusive CPUs of more than one container in a single operation. Send one resize request per container.