Skip to content

Commit d22bd09

Browse files
committed
Placeholder documentation for in-place pod resize feature
1 parent a6b1df5 commit d22bd09

File tree

1 file changed

+244
-0
lines changed

1 file changed

+244
-0
lines changed
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
---
2+
title: Resize CPU and Memory Resources assigned to Containers of a Pod
3+
content_type: task
4+
weight: 30
5+
---
6+
7+
8+
<!-- overview -->
9+
10+
THIS IS A PLACEHOLDER DOC - A WIP.
11+
12+
This page shows how to resize a CPU and memory resources assigned to containers
13+
of a running pod without restarting the pod or its containers.
14+
15+
Kubernetes allocates resources on a node when a pod is started, and limits its
16+
resource use based on requests and limits specified in the pod's containers.
17+
18+
A container's resource **requests** and **limits** are now **mutable** for CPU
19+
and memory resource types. They now represent **desired** CPU and memory values.
20+
21+
This page assumes you are familiar with Quality of Service for Pods.
22+
23+
24+
## {{% heading "prerequisites" %}}
25+
26+
27+
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
28+
29+
30+
31+
<!-- steps -->
32+
33+
34+
## Container Resize Policies
35+
36+
Resize policies allow for a more fine-grained control over how pod's containers
37+
are resized for CPU and memory resource types. For example, the container's
38+
application may be able to handle CPU resources resized while it continues to
39+
run, but resizing memory limits may require that the container be restarted.
40+
41+
To enable this, container specification allows specifying **resizePolicy**.
42+
The following container resize policies can be specified for CPU and memory:
43+
* *RestartNotRequired*: Resize the container's resources while it is running.
44+
* *Restart*: Restart the container and apply the new resources on restart.
45+
46+
If resizePolicy is not specified, it defaults to *RestartNotRequired*.
47+
48+
{{< note >}}
49+
If the pod's restartPolicy is 'Never', resize policy must be set to RestartNotRequired
50+
for all containers in the pod.
51+
{{< /note >}}
52+
53+
Below example shows a pod whose container's CPU can be resized live, but memory
54+
resize memory requires that the container be restarted.
55+
56+
```yaml
57+
apiVersion: v1
58+
kind: Pod
59+
metadata:
60+
name: qos-demo
61+
namespace: qos-example
62+
spec:
63+
containers:
64+
- name: qos-demo-ctr
65+
image: nginx
66+
resizePolicy:
67+
- policy: RestartNotRequired
68+
resourceName: cpu
69+
- policy: Restart
70+
resourceName: memory
71+
resources:
72+
limits:
73+
memory: "200Mi"
74+
cpu: "700m"
75+
requests:
76+
memory: "200Mi"
77+
cpu: "700m"
78+
```
79+
80+
{{< note >}}
81+
In the above example, if desired resources for both CPU and memory have changed,
82+
the container will be restarted in order to resize its memory.
83+
{{< /note >}}
84+
85+
86+
## Create a pod with resources
87+
88+
You can create a Guaranteed or Burstable QoS class pod by specifying requests
89+
and/or limits for a pod's containers.
90+
91+
Consider the following configuration file for a pod that has one container.
92+
93+
{{< codenew file="pods/qos/qos-pod.yaml" >}}
94+
95+
Create the pod in qos-example namespace:
96+
97+
```shell
98+
kubectl create namespace qos-example
99+
kubectl create -f https://k8s.io/examples/pods/qos/qos-pod.yaml
100+
```
101+
102+
This is classified as a Guaranteed QoS class pod requesting 700m CPU and 200Mi
103+
memory.
104+
105+
View detailed information about the pod:
106+
107+
```shell
108+
kubectl get pod qos-demo --output=yaml --namespace=qos-example
109+
```
110+
111+
Also notice that the values of resizePolicy defaulted to RestartNotRequired,
112+
indicating that CPU and memory can be resized while container is running.
113+
114+
```yaml
115+
spec:
116+
containers:
117+
...
118+
resizePolicy:
119+
- policy: RestartNotRequired
120+
resourceName: cpu
121+
- policy: RestartNotRequired
122+
resourceName: memory
123+
resources:
124+
limits:
125+
cpu: 700m
126+
memory: 200Mi
127+
requests:
128+
cpu: 700m
129+
memory: 200Mi
130+
...
131+
containerStatuses:
132+
...
133+
name: qos-demo-ctr
134+
ready: true
135+
...
136+
resourcesAllocated:
137+
cpu: 700m
138+
memory: 200Mi
139+
resources:
140+
limits:
141+
cpu: 700m
142+
memory: 200Mi
143+
requests:
144+
cpu: 700m
145+
memory: 200Mi
146+
restartCount: 0
147+
started: true
148+
...
149+
qosClass: Guaranteed
150+
```
151+
152+
153+
## Updating the pod's resources
154+
155+
Let's say the CPU needs have increased, and 800m CPU is now desired. This is
156+
typically determined, and may be programmatically applied, by an entity such as
157+
Vertical Pod Autoscaler.
158+
159+
{{< note >}}
160+
While you can change a pod's requests and limits to express new desired
161+
resources, you cannot change the QoS class in which the pod was created.
162+
{{< /note >}}
163+
164+
Now, patch the pod's container with CPU requests & limits of 800m:
165+
166+
```shell
167+
kubectl -n qos-example patch pod qos-demo --patch '{"spec":{"containers":[{"name":"qos-demo-ctr", "resources":{"requests":{"cpu":"800m"}, "limits":{"cpu":"800m"}}}]}}'
168+
```
169+
170+
Query the pod's detailed information after the pod has been patched.
171+
172+
```shell
173+
kubectl get pod qos-demo --output=yaml --namespace=qos-example
174+
```
175+
176+
The pod's spec below reflects the updated CPU requests and limits.
177+
178+
```yaml
179+
spec:
180+
containers:
181+
...
182+
resources:
183+
limits:
184+
cpu: 800m
185+
memory: 200Mi
186+
requests:
187+
cpu: 800m
188+
memory: 200Mi
189+
...
190+
containerStatuses:
191+
...
192+
resourcesAllocated:
193+
cpu: 800m
194+
memory: 200Mi
195+
resources:
196+
limits:
197+
cpu: 800m
198+
memory: 200Mi
199+
requests:
200+
cpu: 800m
201+
memory: 200Mi
202+
restartCount: 0
203+
started: true
204+
```
205+
206+
Observe that resourcesAllocated values has been updated to reflect the new
207+
desired CPU requests. This indicates that node was able to accommodate the
208+
increased CPU resource needs.
209+
210+
In the container's status, updated CPU resource values shows that new CPU
211+
resources have been applied. The container's restart count remains unchanged,
212+
indicating that container's CPU resources were resized without restarting it.
213+
214+
215+
## Clean up
216+
217+
Delete your namespace:
218+
219+
```shell
220+
kubectl delete namespace qos-example
221+
```
222+
223+
224+
## {{% heading "whatsnext" %}}
225+
226+
227+
228+
### For app developers
229+
230+
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
231+
232+
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
233+
234+
### For cluster administrators
235+
236+
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
237+
238+
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
239+
240+
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
241+
242+
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
243+
244+
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)

0 commit comments

Comments
 (0)