-
Notifications
You must be signed in to change notification settings - Fork 9
docs(workloads): add in-place Pod resize guidance #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| --- | ||
| weight: 95 | ||
| --- | ||
|
|
||
| # Adjust Pod Resource Levels Without Pod Disruption | ||
|
|
||
| Use in-place Pod resizing when you need to adjust CPU or memory requests and limits for a running Pod without recreating the Pod. This task uses the Kubernetes Pod `resize` subresource. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Ensure that the target Kubernetes cluster supports the Pod `resize` subresource. Use Kubernetes v1.33 or later with the `InPlacePodVerticalScaling` feature gate enabled on the control plane and nodes. In Kubernetes v1.35, this feature is stable and enabled by default. | ||
|
|
||
| ## About In-place Pod Resizing | ||
|
|
||
| In-place Pod resizing lets you change CPU and memory resource requests and limits for containers in a running Pod. Standard resource changes usually require the Pod to be recreated, which can interrupt applications or lose runtime state. In-place Pod resizing applies supported resource changes through the Kubernetes Pod `resize` subresource. | ||
|
|
||
| You can control whether a container restarts during the resize by configuring `resizePolicy` in the Pod specification. For example, you can allow CPU changes without a restart and require a container restart for memory changes. | ||
|
|
||
| ## Configure In-place Pod Resizing | ||
|
|
||
| Configure `resizePolicy` before you resize a running Pod. You cannot add or modify `resizePolicy` on an existing Pod. If the Pod is managed by an owner object, such as a Deployment or StatefulSet, add or update `resizePolicy` in the owner object's Pod template. | ||
|
|
||
| ```yaml title="deployment-resize-policy.yaml" | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: resize-demo | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: resize-demo | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: resize-demo | ||
| spec: | ||
| containers: | ||
| - name: app | ||
| image: nginx:latest | ||
| resizePolicy: | ||
| - resourceName: cpu | ||
| restartPolicy: NotRequired | ||
| - resourceName: memory | ||
| restartPolicy: RestartContainer | ||
| resources: | ||
| requests: | ||
| cpu: 100m | ||
| memory: 128Mi | ||
| limits: | ||
| cpu: 500m | ||
| memory: 512Mi | ||
| ``` | ||
|
|
||
| For CPU and memory resources, use one of the following `restartPolicy` values: | ||
|
|
||
| | Value | Description | | ||
| | --- | --- | | ||
| | `NotRequired` | Apply supported resource changes without restarting the container. | | ||
| | `RestartContainer` | Apply supported resource changes and restart the container. | | ||
|
|
||
| When decreasing memory limits with `NotRequired` or no memory `resizePolicy`, the kubelet applies the change on a best-effort basis and does not guarantee that the container avoids an out-of-memory kill. If current memory usage is higher than the requested limit, the resize can be skipped and remain in progress. Use `RestartContainer` for memory changes when you need more predictable behavior. | ||
|
|
||
| ## Resize a Running Pod | ||
|
|
||
| Use the `resize` subresource when editing Pod resources. Run the commands from a workstation that can access the target cluster. | ||
|
|
||
| ::: tip | ||
| Use `kubectl` v1.32.0 or later, or another API client that supports the Pod `resize` subresource. Older `kubectl` clients might reject `--subresource=resize` with errors such as `invalid subresource value: "resize"` or might not provide the `--subresource` flag for some commands, even when the Kubernetes API server supports `pods/resize`. | ||
| ::: | ||
|
|
||
| Edit the Pod resources interactively: | ||
|
|
||
| ```bash | ||
| kubectl edit pod <pod_name> -n <namespace> --subresource=resize | ||
| ``` | ||
|
|
||
| Apply an updated Pod manifest through the `resize` subresource by using server-side apply: | ||
|
|
||
| ```bash | ||
| kubectl apply --server-side -f <file_name>.yaml --subresource=resize | ||
| ``` | ||
|
|
||
| Patch the target container resources directly: | ||
|
|
||
| ```bash | ||
| kubectl patch pod <pod_name> \ | ||
| -n <namespace> \ | ||
| --subresource=resize \ | ||
| --patch '{"spec":{"containers":[{"name":"<container_name>","resources":{"requests":{"cpu":"800m"},"limits":{"cpu":"800m"}}}]}}' | ||
| ``` | ||
|
|
||
| Replace `<pod_name>`, `<namespace>`, and `<container_name>` with the target Pod, namespace, and container names. | ||
|
|
||
| Because this operation requires the Pod `resize` subresource, use `kubectl` or an API client version that supports the subresource. | ||
|
|
||
| ## Verify Restart Behavior | ||
|
|
||
| Check whether the Pod restarted after the resize: | ||
|
|
||
| ```bash | ||
| kubectl get pods -n <namespace> | ||
| ``` | ||
|
|
||
| If `restartPolicy` is `NotRequired` for the changed resource, the Pod should remain running without a container restart. | ||
|
|
||
| ```text | ||
| NAME READY STATUS RESTARTS AGE | ||
| resize-pod 1/1 Running 0 5s | ||
| ``` | ||
|
|
||
| If `restartPolicy` is `RestartContainer` for the changed resource, the container restarts while the Pod remains running. | ||
|
|
||
| ```text | ||
| NAME READY STATUS RESTARTS AGE | ||
| resize-pod 1/1 Running 1 (5s ago) 5s | ||
| ``` | ||
|
|
||
| ## Check Resize Status | ||
|
|
||
| Check the resources currently applied to the running container: | ||
|
|
||
| ```bash | ||
| kubectl get pod <pod_name> \ | ||
| -n <namespace> \ | ||
| -o jsonpath='{.status.containerStatuses[?(@.name=="<container_name>")].resources}' | ||
| ``` | ||
|
|
||
| Check resize conditions and events: | ||
|
|
||
| ```bash | ||
| kubectl describe pod <pod_name> -n <namespace> | ||
| ``` | ||
|
|
||
| Resize conditions include: | ||
|
|
||
| - `PodResizeInProgress`: kubelet can allocate the requested resources and is applying the change. | ||
| - `PodResizePending`: kubelet cannot apply the change immediately. | ||
| - `Infeasible`: The requested resize cannot be executed on the current node. | ||
| - `Deferred`: The requested resize is not currently possible, but might become possible later. | ||
| - `Error`: kubelet reports an error during resource allocation. | ||
|
Comment on lines
+134
to
+140
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: In Kubernetes, the status of in-place Pod resizing is managed through two primary Pod conditions: PodResizePending and PodResizeInProgress [1][2]. This mechanism replaces the older, deprecated status.resize field [1][3]. PodResizePending This condition indicates that the Kubelet has received a request to resize a Pod but cannot immediately grant the resources [3][2]. The reason and message fields provide specific details [3]: 1. Infeasible: The requested resize is impossible to fulfill on the current node [4][3]. This occurs if the node lacks total capacity, the Pod is a static Pod, or the requested configuration (such as certain combinations of swap or static resource manager policies) is not supported [4]. Once marked Infeasible, the Kubelet will not re-evaluate the request [4]. 2. Deferred: The resize is theoretically feasible on the node but cannot be granted at the moment, typically due to temporary resource contention [4][3]. The Kubelet will periodically re-evaluate these requests, prioritizing them based on Pod priority (PriorityClass), Quality of Service (QoS) class, and the duration the request has been in the Deferred state [5][3]. PodResizeInProgress This condition indicates that the Kubelet has accepted the resize request and is in the process of applying the changes [3][2]. It is active whenever the allocated resources differ from the actuated (applied) resources [4]. If an error occurs during the actuation phase, this condition is set with reason: Error, and the message field contains the specific error details [4][3]. Under normal operations, this condition is typically short-lived while the runtime applies the new resource limits [3]. Summary of Key States: - PodResizePending: Kubelet cannot resize now. - Reason: Infeasible (permanent, will not retry) [4][3]. - Reason: Deferred (temporary, will retry) [4][3]. - PodResizeInProgress: Kubelet has accepted and is applying the resize [3][2]. - Reason: Error (actuation failure) [4][3]. Citations:
Fix/verify Kubernetes in-place Pod resizing documents 🤖 Prompt for AI Agents |
||
|
|
||
| ## Limitations | ||
|
|
||
| - Only CPU and memory requests and limits can be resized. | ||
| - In-place Pod resizing is not supported for non-restartable init containers or ephemeral containers. | ||
| - The resize must not violate other Pod mutability constraints, such as changing the Pod QoS class. | ||
| - Pods managed by static `cpuManagerPolicy` or `memoryManagerPolicy` cannot be resized in place. | ||
| - Pods that use swap memory must use `RestartContainer` for memory requests. | ||
|
Comment on lines
+147
to
+148
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Kubernetes in-place Pod resize (CPU/memory) behavior with cpuManagerPolicy, memoryManagerPolicy, and swap is constrained as follows. 1) What “in-place Pod resize” can change - Kubernetes supports in-place resizing of CPU and memory resources for running Pods (Pod vertical scaling). Pod-level aggregate CPU/memory in spec.resources can be updated in place without requiring a restart; container-level resizePolicy still governs whether the specific container is restarted for the resource change. [1] 2) cpuManagerPolicy (CPU Manager static policy) limitations - In-place resize is not supported for Guaranteed Pods when CPU Manager policy is set to static. This is explicitly called out by the in-place resize KEP logic via a “guaranteed_pod_cpu_manager_static_policy” condition. [2] - Practical implication: if you run Guaranteed pods (i.e., meet Guaranteed QoS conditions) with cpuManagerPolicy=static, Kubernetes will mark the resize as infeasible rather than trying to update cpusets live. [2][3] 3) memoryManagerPolicy (Memory Manager static policy) limitations - In-place resize is not supported for Guaranteed Pods when Memory Manager static policy is configured. This is explicitly called out via “guaranteed_pod_memory_manager_static_policy” condition. [2] - Practical implication: if you run Guaranteed pods with memoryManagerPolicy=Static, Kubelet will treat resize requests as unsupported/infeasible for those pods. [2][4] 4) Swap limitations for in-place resize - Kubernetes explicitly limits memory resizing for Pods that use swap: Pods utilizing swap memory cannot resize memory requests unless the memory resizePolicy restartPolicy is RestartContainer. [5] - If swap is enabled/used in the pod/container, in-place memory resize without a container restart is not allowed because swap settings (cgroup memory.swap.max) must be recalculated/aligned with updated memory requests. [6][5] 5) ResizePolicy details that drive restarts - Container spec.containers[*].resizePolicy controls restart behavior per resource type. - resizePolicy restartPolicy NotRequired applies the resource change without restarting the container. [5] - resizePolicy restartPolicy RestartContainer restarts the container when applying the new resource values (often required for memory). [5] - If both CPU and memory are being resized and memory’s policy requires a restart, the container will be restarted. [7] 6) Memory limit decrease behavior (additional relevant limitation) - For memory limit decreases, Kubernetes enforces that memory limits cannot be decreased unless the memory resize policy is RestartContainer. (So NotRequired is not sufficient for shrinking memory limits.) [8] Bottom line / quick matrix - cpuManagerPolicy=static + Guaranteed pod: in-place resize is not supported. [2] - memoryManagerPolicy=Static + Guaranteed pod: in-place resize is not supported. [2] - swap enabled (Pod “utilizing swap”): memory resize requires memory resizePolicy restartPolicy=RestartContainer (can’t be done purely in-place). [5] - Otherwise: container resizePolicy determines whether CPU/memory changes are applied live or via container restart. [1][5] Citations:
Update the wording to match Kubernetes’ exact conditions for in-place resize (CPU/memory managers + swap)
docs/en/developer/building_application/application_workloads/resize_pod_resources_in_place.mdx (lines 141-142) 🤖 Prompt for AI Agents |
||
| - ResourceQuota, LimitRange, and admission policies can still reject the resize request. | ||
|
|
||
| ::: note | ||
| Because this operation requires the Pod `resize` subresource, it might not be available through web console resource editing. Use `kubectl` or an API client version that supports the `resize` subresource. | ||
| ::: | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| - [Pods](./pod.mdx) | ||
| - [Resource Units](../concepts/unit.mdx) | ||
| - [Configuring VerticalPodAutoscaler (VPA)](../operation_maintaining/add_vpa.mdx) | ||
| - [Pod API Reference](../../../apis/kubernetes_apis/workload/pod.mdx) | ||
Uh oh!
There was an error while loading. Please reload this page.