Add weights, move files: Tasks>AdminClust>MemCPU (#8635)
* Add weights, move files: Tasks>AdminClust>MemCPU * Move yaml files.
This commit is contained in:
committed by
k8s-ci-robot
parent
8b5226434b
commit
cbc950b6b2
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: Manage Memory, CPU, and API Resources
|
||||
weight: 20
|
||||
---
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
---
|
||||
title: Configure Minimum and Maximum CPU Constraints for a Namespace
|
||||
content_template: templates/task
|
||||
weight: 40
|
||||
---
|
||||
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
This page shows how to set minimum and maximum values for the CPU resources used by Containers
|
||||
and Pods in a namespace. You specify minimum and maximum CPU values in a
|
||||
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
|
||||
object. If a Pod does not meet the constraints imposed by the LimitRange, it cannot be created
|
||||
in the namespace.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
Each node in your cluster must have at least 1 CPU.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## Create a namespace
|
||||
|
||||
Create a namespace so that the resources you create in this exercise are
|
||||
isolated from the rest of your cluster.
|
||||
|
||||
```shell
|
||||
kubectl create namespace constraints-cpu-example
|
||||
```
|
||||
|
||||
## Create a LimitRange and a Pod
|
||||
|
||||
Here's the configuration file for a LimitRange:
|
||||
|
||||
{{< code file="cpu-constraints.yaml" >}}
|
||||
|
||||
Create the LimitRange:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-constraints.yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
View detailed information about the LimitRange:
|
||||
|
||||
```shell
|
||||
kubectl get limitrange cpu-min-max-demo-lr --output=yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
The output shows the minimum and maximum CPU constraints as expected. But
|
||||
notice that even though you didn't specify default values in the configuration
|
||||
file for the LimitRange, they were created automatically.
|
||||
|
||||
```yaml
|
||||
limits:
|
||||
- default:
|
||||
cpu: 800m
|
||||
defaultRequest:
|
||||
cpu: 800m
|
||||
max:
|
||||
cpu: 800m
|
||||
min:
|
||||
cpu: 200m
|
||||
type: Container
|
||||
```
|
||||
|
||||
Now whenever a Container is created in the constraints-cpu-example namespace, Kubernetes
|
||||
performs these steps:
|
||||
|
||||
* If the Container does not specify its own CPU request and limit, assign the default
|
||||
CPU request and limit to the Container.
|
||||
|
||||
* Verify that the Container specifies a CPU request that is greater than or equal to 200 millicpu.
|
||||
|
||||
* Verify that the Container specifies a CPU limit that is less than or equal to 800 millicpu.
|
||||
|
||||
{{< note >}}
|
||||
**Note:** When creating a `LimitRange` object, you can specify limits on huge-pages
|
||||
or GPUs as well. However, when both `default` and `defaultRequest` are specified
|
||||
on these resources, the two values must be the same.
|
||||
{{< /note >}}
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container manifest
|
||||
specifies a CPU request of 500 millicpu and a CPU limit of 800 millicpu. These satisfy the
|
||||
minimum and maximum CPU constraints imposed by the LimitRange.
|
||||
|
||||
{{< code file="cpu-constraints-pod.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-constraints-pod.yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
Verify that the Pod's Container is running:
|
||||
|
||||
```shell
|
||||
kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
View detailed information about the Pod:
|
||||
|
||||
```shell
|
||||
kubectl get pod constraints-cpu-demo --output=yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
The output shows that the Container has a CPU request of 500 millicpu and CPU limit
|
||||
of 800 millicpu. These satisfy the constraints imposed by the LimitRange.
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
limits:
|
||||
cpu: 800m
|
||||
requests:
|
||||
cpu: 500m
|
||||
```
|
||||
|
||||
## Delete the Pod
|
||||
|
||||
```shell
|
||||
kubectl delete pod constraints-cpu-demo --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
## Attempt to create a Pod that exceeds the maximum CPU constraint
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container specifies a
|
||||
CPU request of 500 millicpu and a cpu limit of 1.5 cpu.
|
||||
|
||||
{{< code file="cpu-constraints-pod-2.yaml" >}}
|
||||
|
||||
Attempt to create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-constraints-pod-2.yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
The output shows that the Pod does not get created, because the Container specifies a CPU limit that is
|
||||
too large:
|
||||
|
||||
```
|
||||
Error from server (Forbidden): error when creating "docs/tasks/administer-cluster/cpu-constraints-pod-2.yaml":
|
||||
pods "constraints-cpu-demo-2" is forbidden: maximum cpu usage per Container is 800m, but limit is 1500m.
|
||||
```
|
||||
|
||||
## Attempt to create a Pod that does not meet the minimum CPU request
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container specifies a
|
||||
CPU request of 100 millicpu and a CPU limit of 800 millicpu.
|
||||
|
||||
{{< code file="cpu-constraints-pod-3.yaml" >}}
|
||||
|
||||
Attempt to create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-constraints-pod-3.yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
The output shows that the Pod does not get created, because the Container specifies a CPU
|
||||
request that is too small:
|
||||
|
||||
```
|
||||
Error from server (Forbidden): error when creating "docs/tasks/administer-cluster/cpu-constraints-pod-3.yaml":
|
||||
pods "constraints-cpu-demo-4" is forbidden: minimum cpu usage per Container is 200m, but request is 100m.
|
||||
```
|
||||
|
||||
## Create a Pod that does not specify any CPU request or limit
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container does not
|
||||
specify a CPU request, and it does not specify a CPU limit.
|
||||
|
||||
{{< code file="cpu-constraints-pod-4.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-constraints-pod-4.yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
View detailed information about the Pod:
|
||||
|
||||
```
|
||||
kubectl get pod constraints-cpu-demo-4 --namespace=constraints-cpu-example --output=yaml
|
||||
```
|
||||
|
||||
The output shows that the Pod's Container has a CPU request of 800 millicpu and a CPU limit of 800 millicpu.
|
||||
How did the Container get those values?
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
limits:
|
||||
cpu: 800m
|
||||
requests:
|
||||
cpu: 800m
|
||||
```
|
||||
|
||||
Because your Container did not specify its own CPU request and limit, it was given the
|
||||
[default CPU request and limit](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
from the LimitRange.
|
||||
|
||||
At this point, your Container might be running or it might not be running. Recall that a prerequisite
|
||||
for this task is that your Nodes have at least 1 CPU. 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.
|
||||
|
||||
Delete your Pod:
|
||||
|
||||
```
|
||||
kubectl delete pod constraints-cpu-demo-4 --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
## Enforcement of minimum and maximum CPU constraints
|
||||
|
||||
The maximum and minimum CPU constraints imposed on a namespace by a LimitRange are enforced only
|
||||
when a Pod is created or updated. If you change the LimitRange, it does not affect
|
||||
Pods that were created previously.
|
||||
|
||||
## Motivation for minimum and maximum CPU constraints
|
||||
|
||||
As a cluster administrator, you might want to impose restrictions on the CPU resources that Pods can use.
|
||||
For example:
|
||||
|
||||
* Each Node in a cluster has 2 CPU. You do not want to accept any Pod that requests
|
||||
more than 2 CPU, because no Node in the cluster can support the request.
|
||||
|
||||
* A cluster is shared by your production and development departments.
|
||||
You want to allow production workloads to consume up to 3 CPU, but you want development workloads to be limited
|
||||
to 1 CPU. You create separate namespaces for production and development, and you apply CPU constraints to
|
||||
each namespace.
|
||||
|
||||
## Clean up
|
||||
|
||||
Delete your namespace:
|
||||
|
||||
```shell
|
||||
kubectl delete namespace constraints-cpu-example
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-cpu-demo-2
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-cpu-demo-2-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
cpu: "1.5"
|
||||
requests:
|
||||
cpu: "500m"
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-cpu-demo-4
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-cpu-demo-4-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
cpu: "800m"
|
||||
requests:
|
||||
cpu: "100m"
|
||||
@@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-cpu-demo-4
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-cpu-demo-4-ctr
|
||||
image: vish/stress
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-cpu-demo
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-cpu-demo-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
cpu: "800m"
|
||||
requests:
|
||||
cpu: "500m"
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: LimitRange
|
||||
metadata:
|
||||
name: cpu-min-max-demo-lr
|
||||
spec:
|
||||
limits:
|
||||
- max:
|
||||
cpu: "800m"
|
||||
min:
|
||||
cpu: "200m"
|
||||
type: Container
|
||||
@@ -0,0 +1,186 @@
|
||||
---
|
||||
title: Configure Default CPU Requests and Limits for a Namespace
|
||||
content_template: templates/task
|
||||
weight: 20
|
||||
---
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
This page shows how to configure default CPU requests and limits for a namespace.
|
||||
A Kubernetes cluster can be divided into namespaces. If a Container is created in a namespace
|
||||
that has a default CPU limit, and the Container does not specify its own CPU limit, then
|
||||
the Container is assigned the default CPU limit. Kubernetes assigns a default CPU request
|
||||
under certain conditions that are explained later in this topic.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## Create a namespace
|
||||
|
||||
Create a namespace so that the resources you create in this exercise are
|
||||
isolated from the rest of your cluster.
|
||||
|
||||
```shell
|
||||
kubectl create namespace default-cpu-example
|
||||
```
|
||||
|
||||
## Create a LimitRange and a Pod
|
||||
|
||||
Here's the configuration file for a LimitRange object. The configuration specifies
|
||||
a default CPU request and a default CPU limit.
|
||||
|
||||
{{< code file="cpu-defaults.yaml" >}}
|
||||
|
||||
Create the LimitRange in the default-cpu-example namespace:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-defaults.yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
Now if a Container is created in the default-cpu-example namespace, and the
|
||||
Container does not specify its own values for CPU request and CPU limit,
|
||||
the Container is given a default CPU request of 0.5 and a default
|
||||
CPU limit of 1.
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container
|
||||
does not specify a CPU request and limit.
|
||||
|
||||
{{< code file="cpu-defaults-pod.yaml" >}}
|
||||
|
||||
Create the Pod.
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-defaults-pod.yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
View the Pod's specification:
|
||||
|
||||
```shell
|
||||
kubectl get pod default-cpu-demo --output=yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
The output shows that the Pod's Container has a CPU request of 500 millicpus and
|
||||
a CPU limit of 1 cpu. These are the default values specified by the LimitRange.
|
||||
|
||||
```shel
|
||||
containers:
|
||||
- image: nginx
|
||||
imagePullPolicy: Always
|
||||
name: default-cpu-demo-ctr
|
||||
resources:
|
||||
limits:
|
||||
cpu: "1"
|
||||
requests:
|
||||
cpu: 500m
|
||||
```
|
||||
|
||||
## What if you specify a Container's limit, but not its request?
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container
|
||||
specifies a CPU limit, but not a request:
|
||||
|
||||
{{< code file="cpu-defaults-pod-2.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-defaults-pod-2.yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
View the Pod specification:
|
||||
|
||||
```
|
||||
kubectl get pod default-cpu-demo-2 --output=yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
The output shows that the Container's CPU request is set to match its CPU limit.
|
||||
Notice that the Container was not assigned the default CPU request value of 0.5 cpu.
|
||||
|
||||
```
|
||||
resources:
|
||||
limits:
|
||||
cpu: "1"
|
||||
requests:
|
||||
cpu: "1"
|
||||
```
|
||||
|
||||
## What if you specify a Container's request, but not its limit?
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container
|
||||
specifies a CPU request, but not a limit:
|
||||
|
||||
{{< code file="cpu-defaults-pod-3.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/cpu-defaults-pod-3.yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
View the Pod specification:
|
||||
|
||||
```
|
||||
kubectl get pod default-cpu-demo-3 --output=yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
The output shows that the Container's CPU request is set to the value specified in the
|
||||
Container's configuration file. The Container's CPU limit is set to 1 cpu, which is the
|
||||
default CPU limit for the namespace.
|
||||
|
||||
```
|
||||
resources:
|
||||
limits:
|
||||
cpu: "1"
|
||||
requests:
|
||||
cpu: 750m
|
||||
```
|
||||
|
||||
## Motivation for default CPU limits and requests
|
||||
|
||||
If your namespace has a
|
||||
[resource quota](),
|
||||
it is helpful to have a default value in place for CPU limit.
|
||||
Here are two of the restrictions that a resource quota imposes on a namespace:
|
||||
|
||||
* Every Container that runs in the namespace must have its own CPU limit.
|
||||
* The total amount of CPU used by all Containers in the namespace must not exceed a specified limit.
|
||||
|
||||
If a Container does not specify its own CPU limit, it is given the default limit, and then
|
||||
it can be allowed to run in a namespace that is restricted by a quota.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: default-cpu-demo-2
|
||||
spec:
|
||||
containers:
|
||||
- name: default-cpu-demo-2-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
cpu: "1"
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: default-cpu-demo-3
|
||||
spec:
|
||||
containers:
|
||||
- name: default-cpu-demo-3-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
requests:
|
||||
cpu: "0.75"
|
||||
@@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: default-cpu-demo
|
||||
spec:
|
||||
containers:
|
||||
- name: default-cpu-demo-ctr
|
||||
image: nginx
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: LimitRange
|
||||
metadata:
|
||||
name: cpu-limit-range
|
||||
spec:
|
||||
limits:
|
||||
- default:
|
||||
cpu: 1
|
||||
defaultRequest:
|
||||
cpu: 0.5
|
||||
type: Container
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
---
|
||||
title: Configure Minimum and Maximum Memory Constraints for a Namespace
|
||||
content_template: templates/task
|
||||
weight: 30
|
||||
---
|
||||
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
This page shows how to set minimum and maximum values for memory used by Containers
|
||||
running in a namespace. You specify minimum and maximum memory values in a
|
||||
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
|
||||
object. If a Pod does not meet the constraints imposed by the LimitRange,
|
||||
it cannot be created in the namespace.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
Each node in your cluster must have at least 1 GiB of memory.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## Create a namespace
|
||||
|
||||
Create a namespace so that the resources you create in this exercise are
|
||||
isolated from the rest of your cluster.
|
||||
|
||||
```shell
|
||||
kubectl create namespace constraints-mem-example
|
||||
```
|
||||
|
||||
## Create a LimitRange and a Pod
|
||||
|
||||
Here's the configuration file for a LimitRange:
|
||||
|
||||
{{< code file="memory-constraints.yaml" >}}
|
||||
|
||||
Create the LimitRange:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-constraints.yaml --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
View detailed information about the LimitRange:
|
||||
|
||||
```shell
|
||||
kubectl get limitrange mem-min-max-demo-lr --namespace=constraints-mem-example --output=yaml
|
||||
```
|
||||
|
||||
The output shows the minimum and maximum memory constraints as expected. But
|
||||
notice that even though you didn't specify default values in the configuration
|
||||
file for the LimitRange, they were created automatically.
|
||||
|
||||
```
|
||||
limits:
|
||||
- default:
|
||||
memory: 1Gi
|
||||
defaultRequest:
|
||||
memory: 1Gi
|
||||
max:
|
||||
memory: 1Gi
|
||||
min:
|
||||
memory: 500Mi
|
||||
type: Container
|
||||
```
|
||||
|
||||
Now whenever a Container is created in the constraints-mem-example namespace, Kubernetes
|
||||
performs these steps:
|
||||
|
||||
* If the Container does not specify its own memory request and limit, assign the default
|
||||
memory request and limit to the Container.
|
||||
|
||||
* Verify that the Container has a memory request that is greater than or equal to 500 MiB.
|
||||
|
||||
* Verify that the Container has a memory limit that is less than or equal to 1 GiB.
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container manifest
|
||||
specifies a memory request of 600 MiB and a memory limit of 800 MiB. These satisfy the
|
||||
minimum and maximum memory constraints imposed by the LimitRange.
|
||||
|
||||
{{< code file="memory-constraints-pod.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-constraints-pod.yaml --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
Verify that the Pod's Container is running:
|
||||
|
||||
```shell
|
||||
kubectl get pod constraints-mem-demo --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
View detailed information about the Pod:
|
||||
|
||||
```shell
|
||||
kubectl get pod constraints-mem-demo --output=yaml --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
The output shows that the Container has a memory request of 600 MiB and a memory limit
|
||||
of 800 MiB. These satisfy the constraints imposed by the LimitRange.
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
limits:
|
||||
memory: 800Mi
|
||||
requests:
|
||||
memory: 600Mi
|
||||
```
|
||||
|
||||
Delete your Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod constraints-mem-demo --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
## Attempt to create a Pod that exceeds the maximum memory constraint
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container specifies a
|
||||
memory request of 800 MiB and a memory limit of 1.5 GiB.
|
||||
|
||||
{{< code file="memory-constraints-pod-2.yaml" >}}
|
||||
|
||||
Attempt to create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-constraints-pod-2.yaml --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
The output shows that the Pod does not get created, because the Container specifies a memory limit that is
|
||||
too large:
|
||||
|
||||
```
|
||||
Error from server (Forbidden): error when creating "docs/tasks/administer-cluster/memory-constraints-pod-2.yaml":
|
||||
pods "constraints-mem-demo-2" is forbidden: maximum memory usage per Container is 1Gi, but limit is 1536Mi.
|
||||
```
|
||||
|
||||
## Attempt to create a Pod that does not meet the minimum memory request
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container specifies a
|
||||
memory request of 200 MiB and a memory limit of 800 MiB.
|
||||
|
||||
{{< code file="memory-constraints-pod-3.yaml" >}}
|
||||
|
||||
Attempt to create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-constraints-pod-3.yaml --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
The output shows that the Pod does not get created, because the Container specifies a memory
|
||||
request that is too small:
|
||||
|
||||
```
|
||||
Error from server (Forbidden): error when creating "docs/tasks/administer-cluster/memory-constraints-pod-3.yaml":
|
||||
pods "constraints-mem-demo-3" is forbidden: minimum memory usage per Container is 500Mi, but request is 100Mi.
|
||||
```
|
||||
|
||||
## Create a Pod that does not specify any memory request or limit
|
||||
|
||||
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container does not
|
||||
specify a memory request, and it does not specify a memory limit.
|
||||
|
||||
{{< code file="memory-constraints-pod-4.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-constraints-pod-4.yaml --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
View detailed information about the Pod:
|
||||
|
||||
```
|
||||
kubectl get pod constraints-mem-demo-4 --namespace=constraints-mem-example --output=yaml
|
||||
```
|
||||
|
||||
The output shows that the Pod's Container has a memory request of 1 GiB and a memory limit of 1 GiB.
|
||||
How did the Container get those values?
|
||||
|
||||
```
|
||||
resources:
|
||||
limits:
|
||||
memory: 1Gi
|
||||
requests:
|
||||
memory: 1Gi
|
||||
```
|
||||
|
||||
Because your Container did not specify its own memory request and limit, it was given the
|
||||
[default memory request and limit](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
from the LimitRange.
|
||||
|
||||
At this point, your Container might be running or it might not be running. Recall that a prerequisite
|
||||
for this task is that your Nodes have at least 1 GiB of memory. If each of your Nodes has only
|
||||
1 GiB of memory, then there is not enough allocatable memory on any Node to accommodate a memory
|
||||
request of 1 GiB. If you happen to be using Nodes with 2 GiB of memory, then you probably have
|
||||
enough space to accommodate the 1 GiB request.
|
||||
|
||||
Delete your Pod:
|
||||
|
||||
```
|
||||
kubectl delete pod constraints-mem-demo-4 --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
## Enforcement of minimum and maximum memory constraints
|
||||
|
||||
The maximum and minimum memory constraints imposed on a namespace by a LimitRange are enforced only
|
||||
when a Pod is created or updated. If you change the LimitRange, it does not affect
|
||||
Pods that were created previously.
|
||||
|
||||
## Motivation for minimum and maximum memory constraints
|
||||
|
||||
As a cluster administrator, you might want to impose restrictions on the amount of memory that Pods can use.
|
||||
For example:
|
||||
|
||||
* Each Node in a cluster has 2 GB of memory. You do not want to accept any Pod that requests
|
||||
more than 2 GB of memory, because no Node in the cluster can support the request.
|
||||
|
||||
* A cluster is shared by your production and development departments.
|
||||
You want to allow production workloads to consume up to 8 GB of memory, but
|
||||
you want development workloads to be limited to 512 MB. You create separate namespaces
|
||||
for production and development, and you apply memory constraints to each namespace.
|
||||
|
||||
## Clean up
|
||||
|
||||
Delete your namespace:
|
||||
|
||||
```shell
|
||||
kubectl delete namespace constraints-mem-example
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-mem-demo-2
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-mem-demo-2-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
memory: "1.5Gi"
|
||||
requests:
|
||||
memory: "800Mi"
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-mem-demo-3
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-mem-demo-3-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
memory: "800Mi"
|
||||
requests:
|
||||
memory: "100Mi"
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-mem-demo-4
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-mem-demo-4-ctr
|
||||
image: nginx
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: constraints-mem-demo
|
||||
spec:
|
||||
containers:
|
||||
- name: constraints-mem-demo-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
memory: "800Mi"
|
||||
requests:
|
||||
memory: "600Mi"
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: LimitRange
|
||||
metadata:
|
||||
name: mem-min-max-demo-lr
|
||||
spec:
|
||||
limits:
|
||||
- max:
|
||||
memory: 1Gi
|
||||
min:
|
||||
memory: 500Mi
|
||||
type: Container
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
---
|
||||
title: Configure Default Memory Requests and Limits for a Namespace
|
||||
content_template: templates/task
|
||||
weight: 10
|
||||
---
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
This page shows how to configure default memory requests and limits for a namespace.
|
||||
If a Container is created in a namespace that has a default memory limit, and the Container
|
||||
does not specify its own memory limit, then the Container is assigned the default memory limit.
|
||||
Kubernetes assigns a default memory request under certain conditions that are explained later in this topic.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
Each node in your cluster must have at least 2 GiB of memory.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## Create a namespace
|
||||
|
||||
Create a namespace so that the resources you create in this exercise are
|
||||
isolated from the rest of your cluster.
|
||||
|
||||
```shell
|
||||
kubectl create namespace default-mem-example
|
||||
```
|
||||
|
||||
## Create a LimitRange and a Pod
|
||||
|
||||
Here's the configuration file for a LimitRange object. The configuration specifies
|
||||
a default memory request and a default memory limit.
|
||||
|
||||
{{< code file="memory-defaults.yaml" >}}
|
||||
|
||||
Create the LimitRange in the default-mem-example namespace:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-defaults.yaml --namespace=default-mem-example
|
||||
```
|
||||
|
||||
Now if a Container is created in the default-mem-example namespace, and the
|
||||
Container does not specify its own values for memory request and memory limit,
|
||||
the Container is given a default memory request of 256 MiB and a default
|
||||
memory limit of 512 MiB.
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container
|
||||
does not specify a memory request and limit.
|
||||
|
||||
{{< code file="memory-defaults-pod.yaml" >}}
|
||||
|
||||
Create the Pod.
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-defaults-pod.yaml --namespace=default-mem-example
|
||||
```
|
||||
|
||||
View detailed information about the Pod:
|
||||
|
||||
```shell
|
||||
kubectl get pod default-mem-demo --output=yaml --namespace=default-mem-example
|
||||
```
|
||||
|
||||
The output shows that the Pod's Container has a memory request of 256 MiB and
|
||||
a memory limit of 512 MiB. These are the default values specified by the LimitRange.
|
||||
|
||||
```shel
|
||||
containers:
|
||||
- image: nginx
|
||||
imagePullPolicy: Always
|
||||
name: default-mem-demo-ctr
|
||||
resources:
|
||||
limits:
|
||||
memory: 512Mi
|
||||
requests:
|
||||
memory: 256Mi
|
||||
```
|
||||
|
||||
Delete your Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod default-mem-demo --namespace=default-mem-example
|
||||
```
|
||||
|
||||
## What if you specify a Container's limit, but not its request?
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container
|
||||
specifies a memory limit, but not a request:
|
||||
|
||||
{{< code file="memory-defaults-pod-2.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-defaults-pod-2.yaml --namespace=default-mem-example
|
||||
```
|
||||
|
||||
View detailed information about the Pod:
|
||||
|
||||
```shell
|
||||
kubectl get pod default-mem-demo-2 --output=yaml --namespace=default-mem-example
|
||||
```
|
||||
|
||||
The output shows that the Container's memory request is set to match its memory limit.
|
||||
Notice that the Container was not assigned the default memory request value of 256Mi.
|
||||
|
||||
```
|
||||
resources:
|
||||
limits:
|
||||
memory: 1Gi
|
||||
requests:
|
||||
memory: 1Gi
|
||||
```
|
||||
|
||||
## What if you specify a Container's request, but not its limit?
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container
|
||||
specifies a memory request, but not a limit:
|
||||
|
||||
{{< code file="memory-defaults-pod-3.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-defaults-pod-3.yaml --namespace=default-mem-example
|
||||
```
|
||||
|
||||
View the Pod's specification:
|
||||
|
||||
```shell
|
||||
kubectl get pod default-mem-demo-3 --output=yaml --namespace=default-mem-example
|
||||
```
|
||||
|
||||
The output shows that the Container's memory request is set to the value specified in the
|
||||
Container's configuration file. The Container's memory limit is set to 512Mi, which is the
|
||||
default memory limit for the namespace.
|
||||
|
||||
```
|
||||
resources:
|
||||
limits:
|
||||
memory: 512Mi
|
||||
requests:
|
||||
memory: 128Mi
|
||||
```
|
||||
|
||||
## Motivation for default memory limits and requests
|
||||
|
||||
If your namespace has a resource quota,
|
||||
it is helpful to have a default value in place for memory limit.
|
||||
Here are two of the restrictions that a resource quota imposes on a namespace:
|
||||
|
||||
* Every Container that runs in the namespace must have its own memory limit.
|
||||
* The total amount of memory used by all Containers in the namespace must not exceed a specified limit.
|
||||
|
||||
If a Container does not specify its own memory limit, it is given the default limit, and then
|
||||
it can be allowed to run in a namespace that is restricted by a quota.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: default-mem-demo-2
|
||||
spec:
|
||||
containers:
|
||||
- name: defalt-mem-demo-2-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
memory: "1Gi"
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: default-mem-demo-3
|
||||
spec:
|
||||
containers:
|
||||
- name: default-mem-demo-3-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
requests:
|
||||
memory: "128Mi"
|
||||
@@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: default-mem-demo
|
||||
spec:
|
||||
containers:
|
||||
- name: default-mem-demo-ctr
|
||||
image: nginx
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: LimitRange
|
||||
metadata:
|
||||
name: mem-limit-range
|
||||
spec:
|
||||
limits:
|
||||
- default:
|
||||
memory: 512Mi
|
||||
defaultRequest:
|
||||
memory: 256Mi
|
||||
type: Container
|
||||
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: quota-mem-cpu-demo-2
|
||||
spec:
|
||||
containers:
|
||||
- name: quota-mem-cpu-demo-2-ctr
|
||||
image: redis
|
||||
resources:
|
||||
limits:
|
||||
memory: "1Gi"
|
||||
cpu: "800m"
|
||||
requests:
|
||||
memory: "700Mi"
|
||||
cpu: "400m"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: quota-mem-cpu-demo
|
||||
spec:
|
||||
containers:
|
||||
- name: quota-mem-cpu-demo-ctr
|
||||
image: nginx
|
||||
resources:
|
||||
limits:
|
||||
memory: "800Mi"
|
||||
cpu: "800m"
|
||||
requests:
|
||||
memory: "600Mi"
|
||||
cpu: "400m"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
apiVersion: v1
|
||||
kind: ResourceQuota
|
||||
metadata:
|
||||
name: mem-cpu-demo
|
||||
spec:
|
||||
hard:
|
||||
requests.cpu: "1"
|
||||
requests.memory: 1Gi
|
||||
limits.cpu: "2"
|
||||
limits.memory: 2Gi
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
---
|
||||
title: Configure Memory and CPU Quotas for a Namespace
|
||||
content_template: templates/task
|
||||
weight: 50
|
||||
---
|
||||
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
This page shows how to set quotas for the total amount memory and CPU that
|
||||
can be used by all Containers running in a namespace. You specify quotas in a
|
||||
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
|
||||
object.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
Each node in your cluster must have at least 1 GiB of memory.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## Create a namespace
|
||||
|
||||
Create a namespace so that the resources you create in this exercise are
|
||||
isolated from the rest of your cluster.
|
||||
|
||||
```shell
|
||||
kubectl create namespace quota-mem-cpu-example
|
||||
```
|
||||
|
||||
## Create a ResourceQuota
|
||||
|
||||
Here is the configuration file for a ResourceQuota object:
|
||||
|
||||
{{< code file="quota-mem-cpu.yaml" >}}
|
||||
|
||||
Create the ResourceQuota:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-mem-cpu.yaml --namespace=quota-mem-cpu-example
|
||||
```
|
||||
|
||||
View detailed information about the ResourceQuota:
|
||||
|
||||
```shell
|
||||
kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --output=yaml
|
||||
```
|
||||
|
||||
The ResourceQuota places these requirements on the quota-mem-cpu-example namespace:
|
||||
|
||||
* Every Container must have a memory request, memory limit, cpu request, and cpu limit.
|
||||
* The memory request total for all Containers must not exceed 1 GiB.
|
||||
* The memory limit total for all Containers must not exceed 2 GiB.
|
||||
* The CPU request total for all Containers must not exceed 1 cpu.
|
||||
* The CPU limit total for all Containers must not exceed 2 cpu.
|
||||
|
||||
## Create a Pod
|
||||
|
||||
Here is the configuration file for a Pod:
|
||||
|
||||
{{< code file="quota-mem-cpu-pod.yaml" >}}
|
||||
|
||||
|
||||
Create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-mem-cpu-pod.yaml --namespace=quota-mem-cpu-example
|
||||
```
|
||||
|
||||
Verify that the Pod's Container is running:
|
||||
|
||||
```
|
||||
kubectl get pod quota-mem-cpu-demo --namespace=quota-mem-cpu-example
|
||||
```
|
||||
|
||||
Once again, view detailed information about the ResourceQuota:
|
||||
|
||||
```
|
||||
kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --output=yaml
|
||||
```
|
||||
|
||||
The output shows the quota along with how much of the quota has been used.
|
||||
You can see that the memory and CPU requests and limits for your Pod do not
|
||||
exceed the quota.
|
||||
|
||||
```
|
||||
status:
|
||||
hard:
|
||||
limits.cpu: "2"
|
||||
limits.memory: 2Gi
|
||||
requests.cpu: "1"
|
||||
requests.memory: 1Gi
|
||||
used:
|
||||
limits.cpu: 800m
|
||||
limits.memory: 800Mi
|
||||
requests.cpu: 400m
|
||||
requests.memory: 600Mi
|
||||
```
|
||||
|
||||
## Attempt to create a second Pod
|
||||
|
||||
Here is the configuration file for a second Pod:
|
||||
|
||||
{{< code file="quota-mem-cpu-pod-2.yaml" >}}
|
||||
|
||||
In the configuration file, you can see that the Pod has a memory request of 700 MiB.
|
||||
Notice that the sum of the used memory request and this new memory
|
||||
request exceeds the memory request quota. 600 MiB + 700 MiB > 1 GiB.
|
||||
|
||||
Attempt to create the Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-mem-cpu-pod-2.yaml --namespace=quota-mem-cpu-example
|
||||
```
|
||||
|
||||
The second Pod does not get created. The output shows that creating the second Pod
|
||||
would cause the memory request total to exceed the memory request quota.
|
||||
|
||||
```
|
||||
Error from server (Forbidden): error when creating "docs/tasks/administer-cluster/quota-mem-cpu-pod-2.yaml":
|
||||
pods "quota-mem-cpu-demo-2" is forbidden: exceeded quota: mem-cpu-demo,
|
||||
requested: requests.memory=700Mi,used: requests.memory=600Mi, limited: requests.memory=1Gi
|
||||
```
|
||||
|
||||
## Discussion
|
||||
|
||||
As you have seen in this exercise, you can use a ResourceQuota to restrict
|
||||
the memory request total for all Containers running in a namespace.
|
||||
You can also restrict the totals for memory limit, cpu request, and cpu limit.
|
||||
|
||||
If you want to restrict individual Containers, instead of totals for all Containers, use a
|
||||
[LimitRange](/docs/tasks/administer-cluster/memory-constraint-namespace/).
|
||||
|
||||
## Clean up
|
||||
|
||||
Delete your namespace:
|
||||
|
||||
```shell
|
||||
kubectl delete namespace quota-mem-cpu-example
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
kind: PersistentVolumeClaim
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: pvc-quota-demo-2
|
||||
spec:
|
||||
storageClassName: manual
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 4Gi
|
||||
@@ -0,0 +1,11 @@
|
||||
kind: PersistentVolumeClaim
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: pvc-quota-demo
|
||||
spec:
|
||||
storageClassName: manual
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 3Gi
|
||||
@@ -0,0 +1,17 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: pod-quota-demo
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
purpose: quota-demo
|
||||
replicas: 3
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
purpose: quota-demo
|
||||
spec:
|
||||
containers:
|
||||
- name: pod-quota-demo
|
||||
image: nginx
|
||||
@@ -0,0 +1,141 @@
|
||||
---
|
||||
title: Configure a Pod Quota for a Namespace
|
||||
content_template: templates/task
|
||||
weight: 60
|
||||
---
|
||||
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
This page shows how to set a quota for the total number of Pods that can run
|
||||
in a namespace. You specify quotas in a
|
||||
[ResourceQuota](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#resourcequota-v1-core)
|
||||
object.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## Create a namespace
|
||||
|
||||
Create a namespace so that the resources you create in this exercise are
|
||||
isolated from the rest of your cluster.
|
||||
|
||||
```shell
|
||||
kubectl create namespace quota-pod-example
|
||||
```
|
||||
|
||||
## Create a ResourceQuota
|
||||
|
||||
Here is the configuration file for a ResourceQuota object:
|
||||
|
||||
{{< code file="quota-pod.yaml" >}}
|
||||
|
||||
Create the ResourceQuota:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-pod.yaml --namespace=quota-pod-example
|
||||
```
|
||||
|
||||
View detailed information about the ResourceQuota:
|
||||
|
||||
```shell
|
||||
kubectl get resourcequota pod-demo --namespace=quota-pod-example --output=yaml
|
||||
```
|
||||
|
||||
The output shows that the namespace has a quota of two Pods, and that currently there are
|
||||
no Pods; that is, none of the quota is used.
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
hard:
|
||||
pods: "2"
|
||||
status:
|
||||
hard:
|
||||
pods: "2"
|
||||
used:
|
||||
pods: "0"
|
||||
```
|
||||
|
||||
Here is the configuration file for a Deployment:
|
||||
|
||||
{{< code file="quota-pod-deployment.yaml" >}}
|
||||
|
||||
In the configuration file, `replicas: 3` tells Kubernetes to attempt to create three Pods, all running the same application.
|
||||
|
||||
Create the Deployment:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-pod-deployment.yaml --namespace=quota-pod-example
|
||||
```
|
||||
|
||||
View detailed information about the Deployment:
|
||||
|
||||
```shell
|
||||
kubectl get deployment pod-quota-demo --namespace=quota-pod-example --output=yaml
|
||||
```
|
||||
|
||||
The output shows that even though the Deployment specifies three replicas, only two
|
||||
Pods were created because of the quota.
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
...
|
||||
replicas: 3
|
||||
...
|
||||
status:
|
||||
availableReplicas: 2
|
||||
...
|
||||
lastUpdateTime: 2017-07-07T20:57:05Z
|
||||
message: 'unable to create pods: pods "pod-quota-demo-1650323038-" is forbidden:
|
||||
exceeded quota: pod-demo, requested: pods=1, used: pods=2, limited: pods=2'
|
||||
```
|
||||
|
||||
## Clean up
|
||||
|
||||
Delete your namespace:
|
||||
|
||||
```shell
|
||||
kubectl delete namespace quota-pod-example
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
apiVersion: v1
|
||||
kind: ResourceQuota
|
||||
metadata:
|
||||
name: pod-demo
|
||||
spec:
|
||||
hard:
|
||||
pods: "2"
|
||||
@@ -0,0 +1,11 @@
|
||||
kind: PersistentVolumeClaim
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: pvc-quota-demo-2
|
||||
spec:
|
||||
storageClassName: manual
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 4Gi
|
||||
Reference in New Issue
Block a user