Skip to content

Commit f8db38b

Browse files
authored
Merge pull request #30066 from sftim/20211012_tidy_manage_resources_tasks
Tidy task pages within Manage Memory, CPU, and API Resources
2 parents 1d77a88 + 3dd1eb1 commit f8db38b

File tree

6 files changed

+241
-155
lines changed

6 files changed

+241
-155
lines changed

content/en/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace.md

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
title: Configure Minimum and Maximum CPU Constraints for a Namespace
33
content_type: task
44
weight: 40
5+
description: >-
6+
Define a range of valid CPU resource limits for a namespace, so that every new Pod
7+
in that namespace falls within the range you configure.
58
---
69

710

811
<!-- overview -->
912

10-
This page shows how to set minimum and maximum values for the CPU resources used by Containers
11-
and Pods in a namespace. You specify minimum and maximum CPU values in a
12-
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
13+
This page shows how to set minimum and maximum values for the CPU resources used by containers
14+
and Pods in a {{< glossary_tooltip text="namespace" term_id="namespace" >}}. You specify minimum
15+
and maximum CPU values in a
16+
[LimitRange](/docs/reference/kubernetes-api/policy-resources/limit-range-v1/)
1317
object. If a Pod does not meet the constraints imposed by the LimitRange, it cannot be created
1418
in the namespace.
1519

@@ -19,11 +23,13 @@ in the namespace.
1923
## {{% heading "prerequisites" %}}
2024

2125

22-
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
23-
24-
Your cluster must have at least 1 CPU available for use to run the task examples.
26+
{{< include "task-tutorial-prereqs.md" >}}
2527

28+
You must have access to create namespaces in your cluster.
2629

30+
Your cluster must have at least 1.0 CPU available for use to run the task examples.
31+
See [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
32+
to learn what Kubernetes means by “1 CPU”.
2733

2834

2935
<!-- steps -->
@@ -39,7 +45,7 @@ kubectl create namespace constraints-cpu-example
3945

4046
## Create a LimitRange and a Pod
4147

42-
Here's the configuration file for a LimitRange:
48+
Here's an example manifest for a LimitRange:
4349

4450
{{< codenew file="admin/resource/cpu-constraints.yaml" >}}
4551

@@ -72,23 +78,23 @@ limits:
7278
type: Container
7379
```
7480
75-
Now whenever a Container is created in the constraints-cpu-example namespace, Kubernetes
76-
performs these steps:
81+
Now whenever you create a Pod in the constraints-cpu-example namespace (or some other client
82+
of the Kubernetes API creates an equivalent Pod), Kubernetes performs these steps:
7783
78-
* If the Container does not specify its own CPU request and limit, assign the default
79-
CPU request and limit to the Container.
84+
* If any container in that Pod does not specify its own CPU request and limit, the control plane
85+
assigns the default CPU request and limit to that container.
8086
81-
* Verify that the Container specifies a CPU request that is greater than or equal to 200 millicpu.
87+
* Verify that every container in that Pod specifies a CPU request that is greater than or equal to 200 millicpu.
8288
83-
* Verify that the Container specifies a CPU limit that is less than or equal to 800 millicpu.
89+
* Verify that every container in that Pod specifies a CPU limit that is less than or equal to 800 millicpu.
8490
8591
{{< note >}}
8692
When creating a `LimitRange` object, you can specify limits on huge-pages
8793
or GPUs as well. However, when both `default` and `defaultRequest` are specified
8894
on these resources, the two values must be the same.
8995
{{< /note >}}
9096

91-
Here's the configuration file for a Pod that has one Container. The Container manifest
97+
Here's a manifest for a Pod that has one container. The container manifest
9298
specifies a CPU request of 500 millicpu and a CPU limit of 800 millicpu. These satisfy the
9399
minimum and maximum CPU constraints imposed by the LimitRange.
94100

@@ -100,7 +106,7 @@ Create the Pod:
100106
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod.yaml --namespace=constraints-cpu-example
101107
```
102108

103-
Verify that the Pod's Container is running:
109+
Verify that the Pod is running and that its container is healthy:
104110

105111
```shell
106112
kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example
@@ -112,7 +118,7 @@ View detailed information about the Pod:
112118
kubectl get pod constraints-cpu-demo --output=yaml --namespace=constraints-cpu-example
113119
```
114120

115-
The output shows that the Container has a CPU request of 500 millicpu and CPU limit
121+
The output shows that the Pod's only container has a CPU request of 500 millicpu and CPU limit
116122
of 800 millicpu. These satisfy the constraints imposed by the LimitRange.
117123

118124
```yaml
@@ -131,7 +137,7 @@ kubectl delete pod constraints-cpu-demo --namespace=constraints-cpu-example
131137

132138
## Attempt to create a Pod that exceeds the maximum CPU constraint
133139

134-
Here's the configuration file for a Pod that has one Container. The Container specifies a
140+
Here's a manifest for a Pod that has one container. The container specifies a
135141
CPU request of 500 millicpu and a cpu limit of 1.5 cpu.
136142

137143
{{< codenew file="admin/resource/cpu-constraints-pod-2.yaml" >}}
@@ -142,8 +148,8 @@ Attempt to create the Pod:
142148
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-2.yaml --namespace=constraints-cpu-example
143149
```
144150

145-
The output shows that the Pod does not get created, because the Container specifies a CPU limit that is
146-
too large:
151+
The output shows that the Pod does not get created, because it defines an unacceptable container.
152+
That container is not acceptable because it specifies a CPU limit that is too large:
147153

148154
```
149155
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-2.yaml":
@@ -152,7 +158,7 @@ pods "constraints-cpu-demo-2" is forbidden: maximum cpu usage per Container is 8
152158

153159
## Attempt to create a Pod that does not meet the minimum CPU request
154160

155-
Here's the configuration file for a Pod that has one Container. The Container specifies a
161+
Here's a manifest for a Pod that has one container. The container specifies a
156162
CPU request of 100 millicpu and a CPU limit of 800 millicpu.
157163

158164
{{< codenew file="admin/resource/cpu-constraints-pod-3.yaml" >}}
@@ -163,8 +169,9 @@ Attempt to create the Pod:
163169
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-3.yaml --namespace=constraints-cpu-example
164170
```
165171

166-
The output shows that the Pod does not get created, because the Container specifies a CPU
167-
request that is too small:
172+
The output shows that the Pod does not get created, because it defines an unacceptable container.
173+
That container is not acceptable because it specifies a CPU limit that is lower than the
174+
enforced minimum:
168175

169176
```
170177
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-3.yaml":
@@ -173,8 +180,8 @@ pods "constraints-cpu-demo-3" is forbidden: minimum cpu usage per Container is 2
173180

174181
## Create a Pod that does not specify any CPU request or limit
175182

176-
Here's the configuration file for a Pod that has one Container. The Container does not
177-
specify a CPU request, and it does not specify a CPU limit.
183+
Here's a manifest for a Pod that has one container. The container does not
184+
specify a CPU request, nor does it specify a CPU limit.
178185

179186
{{< codenew file="admin/resource/cpu-constraints-pod-4.yaml" >}}
180187

@@ -190,8 +197,9 @@ View detailed information about the Pod:
190197
kubectl get pod constraints-cpu-demo-4 --namespace=constraints-cpu-example --output=yaml
191198
```
192199

193-
The output shows that the Pod's Container has a CPU request of 800 millicpu and a CPU limit of 800 millicpu.
194-
How did the Container get those values?
200+
The output shows that the Pod's single container has a CPU request of 800 millicpu and a
201+
CPU limit of 800 millicpu.
202+
How did that container get those values?
195203

196204
```yaml
197205
resources:
@@ -201,11 +209,12 @@ resources:
201209
cpu: 800m
202210
```
203211

204-
Because your Container did not specify its own CPU request and limit, it was given the
212+
Because that container did not specify its own CPU request and limit, the control plane
213+
applied the
205214
[default CPU request and limit](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
206-
from the LimitRange.
215+
from the LimitRange for this namespace.
207216

208-
At this point, your Container might be running or it might not be running. Recall that a prerequisite for this task is that your cluster must have at least 1 CPU available for use. If each of your Nodes has only 1 CPU, then there might not be enough allocatable CPU on any Node to accommodate a request of 800 millicpu. If you happen to be using Nodes with 2 CPU, then you probably have enough CPU to accommodate the 800 millicpu request.
217+
At this point, your Pod might be running or it might not be running. Recall that a prerequisite for this task is that your cluster must have at least 1 CPU available for use. If each of your Nodes has only 1 CPU, then there might not be enough allocatable CPU on any Node to accommodate a request of 800 millicpu. If you happen to be using Nodes with 2 CPU, then you probably have enough CPU to accommodate the 800 millicpu request.
209218

210219
Delete your Pod:
211220

content/en/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace.md

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,36 @@
22
title: Configure Default CPU Requests and Limits for a Namespace
33
content_type: task
44
weight: 20
5+
description: >-
6+
Define a default CPU resource limits for a namespace, so that every new Pod
7+
in that namespace has a CPU resource limit configured.
58
---
69

710
<!-- overview -->
811

9-
This page shows how to configure default CPU requests and limits for a namespace.
10-
A Kubernetes cluster can be divided into namespaces. If a Container is created in a namespace
11-
that has a default CPU limit, and the Container does not specify its own CPU limit, then
12-
the Container is assigned the default CPU limit. Kubernetes assigns a default CPU request
13-
under certain conditions that are explained later in this topic.
12+
This page shows how to configure default CPU requests and limits for a
13+
{{< glossary_tooltip text="namespace" term_id="namespace" >}}.
1414

15+
A Kubernetes cluster can be divided into namespaces. If you create a Pod within a
16+
namespace that has a default CPU
17+
[limit](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits), and any container in that Pod does not specify
18+
its own CPU limit, then the
19+
{{< glossary_tooltip text="control plane" term_id="control-plane" >}} assigns the default
20+
CPU limit to that container.
1521

22+
Kubernetes assigns a default CPU
23+
[request](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits),
24+
but only under certain conditions that are explained later in this page.
1625

1726
## {{% heading "prerequisites" %}}
1827

1928

20-
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
29+
{{< include "task-tutorial-prereqs.md" >}}
2130

31+
You must have access to create namespaces in your cluster.
32+
33+
If you're not already familiar with what Kubernetes means by 1.0 CPU,
34+
read [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu).
2235

2336
<!-- steps -->
2437

@@ -33,8 +46,8 @@ kubectl create namespace default-cpu-example
3346

3447
## Create a LimitRange and a Pod
3548

36-
Here's the configuration file for a LimitRange object. The configuration specifies
37-
a default CPU request and a default CPU limit.
49+
Here's a manifest for an example {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}}.
50+
The manifest specifies a default CPU request and a default CPU limit.
3851

3952
{{< codenew file="admin/resource/cpu-defaults.yaml" >}}
4053

@@ -44,12 +57,12 @@ Create the LimitRange in the default-cpu-example namespace:
4457
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults.yaml --namespace=default-cpu-example
4558
```
4659

47-
Now if a Container is created in the default-cpu-example namespace, and the
48-
Container does not specify its own values for CPU request and CPU limit,
49-
the Container is given a default CPU request of 0.5 and a default
60+
Now if you create a Pod in the default-cpu-example namespace, and any container
61+
in that Pod does not specify its own values for CPU request and CPU limit,
62+
then the control plane applies default values: a CPU request of 0.5 and a default
5063
CPU limit of 1.
5164

52-
Here's the configuration file for a Pod that has one Container. The Container
65+
Here's a manifest for a Pod that has one container. The container
5366
does not specify a CPU request and limit.
5467

5568
{{< codenew file="admin/resource/cpu-defaults-pod.yaml" >}}
@@ -66,8 +79,9 @@ View the Pod's specification:
6679
kubectl get pod default-cpu-demo --output=yaml --namespace=default-cpu-example
6780
```
6881

69-
The output shows that the Pod's Container has a CPU request of 500 millicpus and
70-
a CPU limit of 1 cpu. These are the default values specified by the LimitRange.
82+
The output shows that the Pod's only container has a CPU request of 500m `cpu`
83+
(which you can read as “500 millicpu”), and a CPU limit of 1 `cpu`.
84+
These are the default values specified by the LimitRange.
7185

7286
```shell
7387
containers:
@@ -81,9 +95,9 @@ containers:
8195
cpu: 500m
8296
```
8397

84-
## What if you specify a Container's limit, but not its request?
98+
## What if you specify a container's limit, but not its request?
8599

86-
Here's the configuration file for a Pod that has one Container. The Container
100+
Here's a manifest for a Pod that has one container. The container
87101
specifies a CPU limit, but not a request:
88102

89103
{{< codenew file="admin/resource/cpu-defaults-pod-2.yaml" >}}
@@ -95,14 +109,15 @@ Create the Pod:
95109
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-2.yaml --namespace=default-cpu-example
96110
```
97111

98-
View the Pod specification:
112+
View the [specification](/docs/concepts/overview/working-with-objects/kubernetes-objects/#object-spec-and-status)
113+
of the Pod that you created:
99114

100115
```
101116
kubectl get pod default-cpu-demo-2 --output=yaml --namespace=default-cpu-example
102117
```
103118

104-
The output shows that the Container's CPU request is set to match its CPU limit.
105-
Notice that the Container was not assigned the default CPU request value of 0.5 cpu.
119+
The output shows that the container's CPU request is set to match its CPU limit.
120+
Notice that the container was not assigned the default CPU request value of 0.5 `cpu`:
106121

107122
```
108123
resources:
@@ -112,9 +127,9 @@ resources:
112127
cpu: "1"
113128
```
114129

115-
## What if you specify a Container's request, but not its limit?
130+
## What if you specify a container's request, but not its limit?
116131

117-
Here's the configuration file for a Pod that has one Container. The Container
132+
Here's an example manifest for a Pod that has one container. The container
118133
specifies a CPU request, but not a limit:
119134

120135
{{< codenew file="admin/resource/cpu-defaults-pod-3.yaml" >}}
@@ -125,15 +140,16 @@ Create the Pod:
125140
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-3.yaml --namespace=default-cpu-example
126141
```
127142

128-
View the Pod specification:
143+
View the specification of the Pod that you created:
129144

130145
```
131146
kubectl get pod default-cpu-demo-3 --output=yaml --namespace=default-cpu-example
132147
```
133148

134-
The output shows that the Container's CPU request is set to the value specified in the
135-
Container's configuration file. The Container's CPU limit is set to 1 cpu, which is the
136-
default CPU limit for the namespace.
149+
The output shows that the container's CPU request is set to the value you specified at
150+
the time you created the Pod (in other words: it matches the manifest).
151+
However, the same container's CPU limit is set to 1 `cpu`, which is the default CPU limit
152+
for that namespace.
137153

138154
```
139155
resources:
@@ -145,16 +161,22 @@ resources:
145161

146162
## Motivation for default CPU limits and requests
147163

148-
If your namespace has a
149-
[resource quota](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/),
164+
If your namespace has a CPU {{< glossary_tooltip text="resource quota" term_id="resource-quota" >}}
165+
configured,
150166
it is helpful to have a default value in place for CPU limit.
151-
Here are two of the restrictions that a resource quota imposes on a namespace:
167+
Here are two of the restrictions that a CPU resource quota imposes on a namespace:
168+
169+
* For every Pod that runs in the namespace, each of its containers must have a CPU limit.
170+
* CPU limits apply a resource reservation on the node where the Pod in question is scheduled.
171+
The total amount of CPU that is reserved for use by all Pods in the namespace must not
172+
exceed a specified limit.
173+
174+
When you add a LimitRange:
152175

153-
* Every Container that runs in the namespace must have its own CPU limit.
154-
* The total amount of CPU used by all Containers in the namespace must not exceed a specified limit.
176+
If any Pod in that namespace that includes a container does not specify its own CPU limit,
177+
the control plane applies the default CPU limit to that container, and the Pod can be
178+
allowed to run in a namespace that is restricted by a CPU ResourceQuota.
155179

156-
If a Container does not specify its own CPU limit, it is given the default limit, and then
157-
it can be allowed to run in a namespace that is restricted by a quota.
158180

159181
## Clean up
160182

0 commit comments

Comments
 (0)