Merge remote-tracking branch 'upstream/main' into dev-1.24
This commit is contained in:
+38
-29
@@ -2,14 +2,18 @@
|
||||
title: Configure Minimum and Maximum CPU Constraints for a Namespace
|
||||
content_type: task
|
||||
weight: 40
|
||||
description: >-
|
||||
Define a range of valid CPU resource limits for a namespace, so that every new Pod
|
||||
in that namespace falls within the range you configure.
|
||||
---
|
||||
|
||||
|
||||
<!-- 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)
|
||||
This page shows how to set minimum and maximum values for the CPU resources used by containers
|
||||
and Pods in a {{< glossary_tooltip text="namespace" term_id="namespace" >}}. You specify minimum
|
||||
and maximum CPU values in a
|
||||
[LimitRange](/docs/reference/kubernetes-api/policy-resources/limit-range-v1/)
|
||||
object. If a Pod does not meet the constraints imposed by the LimitRange, it cannot be created
|
||||
in the namespace.
|
||||
|
||||
@@ -19,11 +23,13 @@ in the namespace.
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
Your cluster must have at least 1 CPU available for use to run the task examples.
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
You must have access to create namespaces in your cluster.
|
||||
|
||||
Your cluster must have at least 1.0 CPU available for use to run the task examples.
|
||||
See [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
|
||||
to learn what Kubernetes means by “1 CPU”.
|
||||
|
||||
|
||||
<!-- steps -->
|
||||
@@ -39,7 +45,7 @@ kubectl create namespace constraints-cpu-example
|
||||
|
||||
## Create a LimitRange and a Pod
|
||||
|
||||
Here's the configuration file for a LimitRange:
|
||||
Here's an example manifest for a LimitRange:
|
||||
|
||||
{{< codenew file="admin/resource/cpu-constraints.yaml" >}}
|
||||
|
||||
@@ -72,15 +78,15 @@ limits:
|
||||
type: Container
|
||||
```
|
||||
|
||||
Now whenever a Container is created in the constraints-cpu-example namespace, Kubernetes
|
||||
performs these steps:
|
||||
Now whenever you create a Pod in the constraints-cpu-example namespace (or some other client
|
||||
of the Kubernetes API creates an equivalent Pod), 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.
|
||||
* If any container in that Pod does not specify its own CPU request and limit, the control plane
|
||||
assigns the default CPU request and limit to that container.
|
||||
|
||||
* Verify that the Container specifies a CPU request that is greater than or equal to 200 millicpu.
|
||||
* Verify that every container in that Pod 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.
|
||||
* Verify that every container in that Pod specifies a CPU limit that is less than or equal to 800 millicpu.
|
||||
|
||||
{{< note >}}
|
||||
When creating a `LimitRange` object, you can specify limits on huge-pages
|
||||
@@ -88,7 +94,7 @@ 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
|
||||
Here's a manifest 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.
|
||||
|
||||
@@ -100,7 +106,7 @@ Create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod.yaml --namespace=constraints-cpu-example
|
||||
```
|
||||
|
||||
Verify that the Pod's Container is running:
|
||||
Verify that the Pod is running and that its container is healthy:
|
||||
|
||||
```shell
|
||||
kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example
|
||||
@@ -112,7 +118,7 @@ View detailed information about the Pod:
|
||||
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
|
||||
The output shows that the Pod's only container has a CPU request of 500 millicpu and CPU limit
|
||||
of 800 millicpu. These satisfy the constraints imposed by the LimitRange.
|
||||
|
||||
```yaml
|
||||
@@ -131,7 +137,7 @@ 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
|
||||
Here's a manifest for a Pod that has one container. The container specifies a
|
||||
CPU request of 500 millicpu and a cpu limit of 1.5 cpu.
|
||||
|
||||
{{< codenew file="admin/resource/cpu-constraints-pod-2.yaml" >}}
|
||||
@@ -142,8 +148,8 @@ Attempt to create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/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:
|
||||
The output shows that the Pod does not get created, because it defines an unacceptable container.
|
||||
That container is not acceptable because it specifies a CPU limit that is too large:
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
## 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
|
||||
Here's a manifest for a Pod that has one container. The container specifies a
|
||||
CPU request of 100 millicpu and a CPU limit of 800 millicpu.
|
||||
|
||||
{{< codenew file="admin/resource/cpu-constraints-pod-3.yaml" >}}
|
||||
@@ -163,8 +169,9 @@ Attempt to create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/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:
|
||||
The output shows that the Pod does not get created, because it defines an unacceptable container.
|
||||
That container is not acceptable because it specifies a CPU limit that is lower than the
|
||||
enforced minimum:
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
## 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.
|
||||
Here's a manifest for a Pod that has one container. The container does not
|
||||
specify a CPU request, nor does it specify a CPU limit.
|
||||
|
||||
{{< codenew file="admin/resource/cpu-constraints-pod-4.yaml" >}}
|
||||
|
||||
@@ -190,8 +197,9 @@ 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?
|
||||
The output shows that the Pod's single container has a CPU request of 800 millicpu and a
|
||||
CPU limit of 800 millicpu.
|
||||
How did that container get those values?
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
@@ -201,11 +209,12 @@ resources:
|
||||
cpu: 800m
|
||||
```
|
||||
|
||||
Because your Container did not specify its own CPU request and limit, it was given the
|
||||
Because that container did not specify its own CPU request and limit, the control plane
|
||||
applied the
|
||||
[default CPU request and limit](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
|
||||
from the LimitRange.
|
||||
from the LimitRange for this namespace.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
Delete your Pod:
|
||||
|
||||
|
||||
+54
-32
@@ -2,23 +2,36 @@
|
||||
title: Configure Default CPU Requests and Limits for a Namespace
|
||||
content_type: task
|
||||
weight: 20
|
||||
description: >-
|
||||
Define a default CPU resource limits for a namespace, so that every new Pod
|
||||
in that namespace has a CPU resource limit configured.
|
||||
---
|
||||
|
||||
<!-- 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.
|
||||
This page shows how to configure default CPU requests and limits for a
|
||||
{{< glossary_tooltip text="namespace" term_id="namespace" >}}.
|
||||
|
||||
A Kubernetes cluster can be divided into namespaces. If you create a Pod within a
|
||||
namespace that has a default CPU
|
||||
[limit](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits), and any container in that Pod does not specify
|
||||
its own CPU limit, then the
|
||||
{{< glossary_tooltip text="control plane" term_id="control-plane" >}} assigns the default
|
||||
CPU limit to that container.
|
||||
|
||||
Kubernetes assigns a default CPU
|
||||
[request](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits),
|
||||
but only under certain conditions that are explained later in this page.
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
You must have access to create namespaces in your cluster.
|
||||
|
||||
If you're not already familiar with what Kubernetes means by 1.0 CPU,
|
||||
read [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu).
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
@@ -33,8 +46,8 @@ 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.
|
||||
Here's a manifest for an example {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}}.
|
||||
The manifest specifies a default CPU request and a default CPU limit.
|
||||
|
||||
{{< codenew file="admin/resource/cpu-defaults.yaml" >}}
|
||||
|
||||
@@ -44,12 +57,12 @@ Create the LimitRange in the default-cpu-example namespace:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/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
|
||||
Now if you create a Pod in the default-cpu-example namespace, and any container
|
||||
in that Pod does not specify its own values for CPU request and CPU limit,
|
||||
then the control plane applies default values: a 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
|
||||
Here's a manifest for a Pod that has one container. The container
|
||||
does not specify a CPU request and limit.
|
||||
|
||||
{{< codenew file="admin/resource/cpu-defaults-pod.yaml" >}}
|
||||
@@ -66,8 +79,9 @@ View the Pod's specification:
|
||||
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.
|
||||
The output shows that the Pod's only container has a CPU request of 500m `cpu`
|
||||
(which you can read as “500 millicpu”), and a CPU limit of 1 `cpu`.
|
||||
These are the default values specified by the LimitRange.
|
||||
|
||||
```shell
|
||||
containers:
|
||||
@@ -81,9 +95,9 @@ containers:
|
||||
cpu: 500m
|
||||
```
|
||||
|
||||
## What if you specify a Container's limit, but not its request?
|
||||
## 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
|
||||
Here's a manifest for a Pod that has one container. The container
|
||||
specifies a CPU limit, but not a request:
|
||||
|
||||
{{< codenew file="admin/resource/cpu-defaults-pod-2.yaml" >}}
|
||||
@@ -95,14 +109,15 @@ Create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-2.yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
View the Pod specification:
|
||||
View the [specification](/docs/concepts/overview/working-with-objects/kubernetes-objects/#object-spec-and-status)
|
||||
of the Pod that you created:
|
||||
|
||||
```
|
||||
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.
|
||||
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:
|
||||
@@ -112,9 +127,9 @@ resources:
|
||||
cpu: "1"
|
||||
```
|
||||
|
||||
## What if you specify a Container's request, but not its limit?
|
||||
## 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
|
||||
Here's an example manifest for a Pod that has one container. The container
|
||||
specifies a CPU request, but not a limit:
|
||||
|
||||
{{< codenew file="admin/resource/cpu-defaults-pod-3.yaml" >}}
|
||||
@@ -125,15 +140,16 @@ Create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-3.yaml --namespace=default-cpu-example
|
||||
```
|
||||
|
||||
View the Pod specification:
|
||||
View the specification of the Pod that you created:
|
||||
|
||||
```
|
||||
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.
|
||||
The output shows that the container's CPU request is set to the value you specified at
|
||||
the time you created the Pod (in other words: it matches the manifest).
|
||||
However, the same container's CPU limit is set to 1 `cpu`, which is the default CPU limit
|
||||
for that namespace.
|
||||
|
||||
```
|
||||
resources:
|
||||
@@ -145,16 +161,22 @@ resources:
|
||||
|
||||
## Motivation for default CPU limits and requests
|
||||
|
||||
If your namespace has a
|
||||
[resource quota](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/),
|
||||
If your namespace has a CPU {{< glossary_tooltip text="resource quota" term_id="resource-quota" >}}
|
||||
configured,
|
||||
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:
|
||||
Here are two of the restrictions that a CPU 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.
|
||||
* For every Pod that runs in the namespace, each of its containers must have a CPU limit.
|
||||
* CPU limits apply a resource reservation on the node where the Pod in question is scheduled.
|
||||
The total amount of CPU that is reserved for use by all Pods in the namespace must not
|
||||
exceed a specified limit.
|
||||
|
||||
When you add a LimitRange:
|
||||
|
||||
If any Pod in that namespace that includes a container does not specify its own CPU limit,
|
||||
the control plane applies the default CPU limit to that container, and the Pod can be
|
||||
allowed to run in a namespace that is restricted by a CPU ResourceQuota.
|
||||
|
||||
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.
|
||||
|
||||
## Clean up
|
||||
|
||||
|
||||
+46
-37
@@ -2,12 +2,15 @@
|
||||
title: Configure Minimum and Maximum Memory Constraints for a Namespace
|
||||
content_type: task
|
||||
weight: 30
|
||||
description: >-
|
||||
Define a range of valid memory resource limits for a namespace, so that every new Pod
|
||||
in that namespace falls within the range you configure.
|
||||
---
|
||||
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
This page shows how to set minimum and maximum values for memory used by Containers
|
||||
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,
|
||||
@@ -15,16 +18,14 @@ it cannot be created in the namespace.
|
||||
|
||||
|
||||
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
Each node in your cluster must have at least 1 GiB of memory.
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
You must have access to create namespaces in your cluster.
|
||||
|
||||
Each node in your cluster must have at least 1 GiB of memory available for Pods.
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
@@ -39,7 +40,7 @@ kubectl create namespace constraints-mem-example
|
||||
|
||||
## Create a LimitRange and a Pod
|
||||
|
||||
Here's the configuration file for a LimitRange:
|
||||
Here's an example manifest for a LimitRange:
|
||||
|
||||
{{< codenew file="admin/resource/memory-constraints.yaml" >}}
|
||||
|
||||
@@ -72,18 +73,19 @@ file for the LimitRange, they were created automatically.
|
||||
type: Container
|
||||
```
|
||||
|
||||
Now whenever a Container is created in the constraints-mem-example namespace, Kubernetes
|
||||
Now whenever you define a Pod within 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.
|
||||
* If any container in that Pod does not specify its own memory request and limit, assign
|
||||
the default memory request and limit to that container.
|
||||
|
||||
* Verify that the Container has a memory request that is greater than or equal to 500 MiB.
|
||||
* Verify that every container in that Pod requests at least 500 MiB of memory.
|
||||
|
||||
* Verify that the Container has a memory limit that is less than or equal to 1 GiB.
|
||||
* Verify that every container in that Pod requests no more than 1024 MiB (1 GiB)
|
||||
of memory.
|
||||
|
||||
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
|
||||
Here's a manifest for a Pod that has one container. Within the Pod spec, the sole
|
||||
container 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.
|
||||
|
||||
{{< codenew file="admin/resource/memory-constraints-pod.yaml" >}}
|
||||
@@ -94,7 +96,7 @@ Create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints-pod.yaml --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
Verify that the Pod's Container is running:
|
||||
Verify that the Pod is running and that its container is healthy:
|
||||
|
||||
```shell
|
||||
kubectl get pod constraints-mem-demo --namespace=constraints-mem-example
|
||||
@@ -106,8 +108,9 @@ View detailed information about the Pod:
|
||||
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.
|
||||
The output shows that the container within that Pod has a memory request of 600 MiB and
|
||||
a memory limit of 800 MiB. These satisfy the constraints imposed by the LimitRange for
|
||||
this namespace:
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
@@ -125,7 +128,7 @@ 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
|
||||
Here's a manifest for a Pod that has one container. The container specifies a
|
||||
memory request of 800 MiB and a memory limit of 1.5 GiB.
|
||||
|
||||
{{< codenew file="admin/resource/memory-constraints-pod-2.yaml" >}}
|
||||
@@ -136,8 +139,8 @@ Attempt to create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/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:
|
||||
The output shows that the Pod does not get created, because it defines a container that
|
||||
requests more memory than is allowed:
|
||||
|
||||
```
|
||||
Error from server (Forbidden): error when creating "examples/admin/resource/memory-constraints-pod-2.yaml":
|
||||
@@ -146,7 +149,7 @@ pods "constraints-mem-demo-2" is forbidden: maximum memory usage per Container i
|
||||
|
||||
## 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
|
||||
Here's a manifest for a Pod that has one container. That container specifies a
|
||||
memory request of 100 MiB and a memory limit of 800 MiB.
|
||||
|
||||
{{< codenew file="admin/resource/memory-constraints-pod-3.yaml" >}}
|
||||
@@ -157,8 +160,8 @@ Attempt to create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/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:
|
||||
The output shows that the Pod does not get created, because it defines a container
|
||||
that requests less memory than the enforced minimum:
|
||||
|
||||
```
|
||||
Error from server (Forbidden): error when creating "examples/admin/resource/memory-constraints-pod-3.yaml":
|
||||
@@ -167,9 +170,7 @@ pods "constraints-mem-demo-3" is forbidden: minimum memory usage per Container i
|
||||
|
||||
## 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
|
||||
Here's a manifest for a Pod that has one container. The container does not
|
||||
specify a memory request, and it does not specify a memory limit.
|
||||
|
||||
{{< codenew file="admin/resource/memory-constraints-pod-4.yaml" >}}
|
||||
@@ -182,12 +183,12 @@ kubectl apply -f https://k8s.io/examples/admin/resource/memory-constraints-pod-4
|
||||
|
||||
View detailed information about the Pod:
|
||||
|
||||
```
|
||||
```shell
|
||||
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?
|
||||
The output shows that the Pod's only container has a memory request of 1 GiB and a memory limit of 1 GiB.
|
||||
How did that container get those values?
|
||||
|
||||
```
|
||||
resources:
|
||||
@@ -197,11 +198,20 @@ resources:
|
||||
memory: 1Gi
|
||||
```
|
||||
|
||||
Because your Container did not specify its own memory request and limit, it was given the
|
||||
Because your Pod did not define any memory request and limit for that container, the cluster
|
||||
applied a
|
||||
[default memory request and limit](/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
|
||||
from the LimitRange.
|
||||
|
||||
At this point, your Container might be running or it might not be running. Recall that a prerequisite
|
||||
This means that the definition of that Pod shows those values. You can check it using
|
||||
`kubectl describe`:
|
||||
|
||||
```shell
|
||||
# Look for the "Requests:" section of the output
|
||||
kubectl describe pod constraints-mem-demo-4 --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
At this point, your Pod 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
|
||||
@@ -209,7 +219,7 @@ enough space to accommodate the 1 GiB request.
|
||||
|
||||
Delete your Pod:
|
||||
|
||||
```
|
||||
```shell
|
||||
kubectl delete pod constraints-mem-demo-4 --namespace=constraints-mem-example
|
||||
```
|
||||
|
||||
@@ -224,12 +234,12 @@ Pods that were created previously.
|
||||
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.
|
||||
* Each Node in a cluster has 2 GiB of memory. You do not want to accept any Pod that requests
|
||||
more than 2 GiB 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
|
||||
You want to allow production workloads to consume up to 8 GiB of memory, but
|
||||
you want development workloads to be limited to 512 MiB. You create separate namespaces
|
||||
for production and development, and you apply memory constraints to each namespace.
|
||||
|
||||
## Clean up
|
||||
@@ -241,7 +251,6 @@ kubectl delete namespace constraints-mem-example
|
||||
```
|
||||
|
||||
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
|
||||
|
||||
+50
-26
@@ -2,21 +2,35 @@
|
||||
title: Configure Default Memory Requests and Limits for a Namespace
|
||||
content_type: task
|
||||
weight: 10
|
||||
description: >-
|
||||
Define a default memory resource limit for a namespace, so that every new Pod
|
||||
in that namespace has a memory resource limit configured.
|
||||
---
|
||||
|
||||
<!-- 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.
|
||||
This page shows how to configure default memory requests and limits for a
|
||||
{{< glossary_tooltip text="namespace" term_id="namespace" >}}.
|
||||
|
||||
A Kubernetes cluster can be divided into namespaces. Once you have a namespace that
|
||||
that has a default memory
|
||||
[limit](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits),
|
||||
and you then try to create a Pod with a container that does not specify its own memory
|
||||
limit its own memory limit, then the
|
||||
{{< glossary_tooltip text="control plane" term_id="control-plane" >}} assigns the default
|
||||
memory limit to that container.
|
||||
|
||||
Kubernetes assigns a default memory request under certain conditions that are explained later in this topic.
|
||||
|
||||
|
||||
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
You must have access to create namespaces in your cluster.
|
||||
|
||||
Each node in your cluster must have at least 2 GiB of memory.
|
||||
|
||||
@@ -35,8 +49,9 @@ 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.
|
||||
Here's a manifest for an example {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}}.
|
||||
The manifest specifies a default memory
|
||||
request and a default memory limit.
|
||||
|
||||
{{< codenew file="admin/resource/memory-defaults.yaml" >}}
|
||||
|
||||
@@ -46,12 +61,13 @@ Create the LimitRange in the default-mem-example namespace:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/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.
|
||||
Now if you create a Pod in the default-mem-example namespace, and any container
|
||||
within that Pod does not specify its own values for memory request and memory limit,
|
||||
then the {{< glossary_tooltip text="control plane" term_id="control-plane" >}}
|
||||
applies default values: a memory request of 256MiB and a memory limit of 512MiB.
|
||||
|
||||
Here's the configuration file for a Pod that has one Container. The Container
|
||||
|
||||
Here's an example manifest for a Pod that has one container. The container
|
||||
does not specify a memory request and limit.
|
||||
|
||||
{{< codenew file="admin/resource/memory-defaults-pod.yaml" >}}
|
||||
@@ -68,7 +84,7 @@ View detailed information about the Pod:
|
||||
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
|
||||
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.
|
||||
|
||||
```shell
|
||||
@@ -89,9 +105,9 @@ Delete your Pod:
|
||||
kubectl delete pod default-mem-demo --namespace=default-mem-example
|
||||
```
|
||||
|
||||
## What if you specify a Container's limit, but not its request?
|
||||
## 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
|
||||
Here's a manifest for a Pod that has one container. The container
|
||||
specifies a memory limit, but not a request:
|
||||
|
||||
{{< codenew file="admin/resource/memory-defaults-pod-2.yaml" >}}
|
||||
@@ -109,8 +125,8 @@ View detailed information about the Pod:
|
||||
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.
|
||||
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:
|
||||
@@ -120,9 +136,9 @@ resources:
|
||||
memory: 1Gi
|
||||
```
|
||||
|
||||
## What if you specify a Container's request, but not its limit?
|
||||
## 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
|
||||
Here's a manifest for a Pod that has one container. The container
|
||||
specifies a memory request, but not a limit:
|
||||
|
||||
{{< codenew file="admin/resource/memory-defaults-pod-3.yaml" >}}
|
||||
@@ -139,9 +155,9 @@ View the Pod's specification:
|
||||
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.
|
||||
The output shows that the container's memory request is set to the value specified in the
|
||||
container's manifest. The container is limited to use no more than 512MiB of
|
||||
memory, which matches the default memory limit for the namespace.
|
||||
|
||||
```
|
||||
resources:
|
||||
@@ -153,15 +169,23 @@ resources:
|
||||
|
||||
## Motivation for default memory limits and requests
|
||||
|
||||
If your namespace has a resource quota,
|
||||
If your namespace has a memory {{< glossary_tooltip text="resource quota" term_id="resource-quota" >}}
|
||||
configured,
|
||||
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.
|
||||
* For every Pod that runs in the namespace, the Pod and each of its containers must have a memory limit.
|
||||
(If you specify a memory limit for every container in a Pod, Kubernetes can infer the Pod-level memory
|
||||
limit by adding up the limits for its containers).
|
||||
* CPU limits apply a resource reservation on the node where the Pod in question is scheduled.
|
||||
The total amount of memory reserved for all Pods in the namespace must not exceed a specified limit.
|
||||
* The total amount of memory actually used by all Pods in the namespace must also 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.
|
||||
When you add a LimitRange:
|
||||
|
||||
If any Pod in that namespace that includes a container does not specify its own memory limit,
|
||||
the control plane applies the default memory limit to that container, and the Pod can be
|
||||
allowed to run in a namespace that is restricted by a memory ResourceQuota.
|
||||
|
||||
## Clean up
|
||||
|
||||
|
||||
+34
-21
@@ -2,14 +2,17 @@
|
||||
title: Configure Memory and CPU Quotas for a Namespace
|
||||
content_type: task
|
||||
weight: 50
|
||||
description: >-
|
||||
Define overall memory and CPU resource limits for a namespace.
|
||||
---
|
||||
|
||||
|
||||
<!-- 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)
|
||||
can be used by all Pods running in a {{< glossary_tooltip text="namespace" term_id="namespace" >}}.
|
||||
You specify quotas in a
|
||||
[ResourceQuota](/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
|
||||
object.
|
||||
|
||||
|
||||
@@ -17,14 +20,13 @@ object.
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
You must have access to create namespaces in your cluster.
|
||||
|
||||
Each node in your cluster must have at least 1 GiB of memory.
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
## Create a namespace
|
||||
@@ -38,7 +40,7 @@ kubectl create namespace quota-mem-cpu-example
|
||||
|
||||
## Create a ResourceQuota
|
||||
|
||||
Here is the configuration file for a ResourceQuota object:
|
||||
Here is a manifest for an example ResourceQuota:
|
||||
|
||||
{{< codenew file="admin/resource/quota-mem-cpu.yaml" >}}
|
||||
|
||||
@@ -56,15 +58,18 @@ kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --outpu
|
||||
|
||||
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.
|
||||
* For every Pod in the namespace, each container must have a memory request, memory limit, cpu request, and cpu limit.
|
||||
* The memory request total for all Pods in that namespace must not exceed 1 GiB.
|
||||
* The memory limit total for all Pods in that namespace must not exceed 2 GiB.
|
||||
* The CPU request total for all Pods in that namespace must not exceed 1 cpu.
|
||||
* The CPU limit total for all Pods in that namespace must not exceed 2 cpu.
|
||||
|
||||
See [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
|
||||
to learn what Kubernetes means by “1 CPU”.
|
||||
|
||||
## Create a Pod
|
||||
|
||||
Here is the configuration file for a Pod:
|
||||
Here is a manifest for an example Pod:
|
||||
|
||||
{{< codenew file="admin/resource/quota-mem-cpu-pod.yaml" >}}
|
||||
|
||||
@@ -75,15 +80,15 @@ Create the Pod:
|
||||
kubectl apply -f https://k8s.io/examples/admin/resource/quota-mem-cpu-pod.yaml --namespace=quota-mem-cpu-example
|
||||
```
|
||||
|
||||
Verify that the Pod's Container is running:
|
||||
Verify that the Pod is running and that its (only) container is healthy:
|
||||
|
||||
```
|
||||
```shell
|
||||
kubectl get pod quota-mem-cpu-demo --namespace=quota-mem-cpu-example
|
||||
```
|
||||
|
||||
Once again, view detailed information about the ResourceQuota:
|
||||
|
||||
```
|
||||
```shell
|
||||
kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --output=yaml
|
||||
```
|
||||
|
||||
@@ -105,15 +110,22 @@ status:
|
||||
requests.memory: 600Mi
|
||||
```
|
||||
|
||||
If you have the `jq` tool, you can also query (using [JSONPath](/docs/reference/kubectl/jsonpath/))
|
||||
for just the `used` values, **and** pretty-print that that of the output. For example:
|
||||
|
||||
```shell
|
||||
kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example -o jsonpath='{ .status.used }' | jq .
|
||||
```
|
||||
|
||||
## Attempt to create a second Pod
|
||||
|
||||
Here is the configuration file for a second Pod:
|
||||
Here is a manifest for a second Pod:
|
||||
|
||||
{{< codenew file="admin/resource/quota-mem-cpu-pod-2.yaml" >}}
|
||||
|
||||
In the configuration file, you can see that the Pod has a memory request of 700 MiB.
|
||||
In the manifest, 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.
|
||||
request exceeds the memory request quota: 600 MiB + 700 MiB > 1 GiB.
|
||||
|
||||
Attempt to create the Pod:
|
||||
|
||||
@@ -133,11 +145,12 @@ requested: requests.memory=700Mi,used: requests.memory=600Mi, limited: requests.
|
||||
## 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.
|
||||
the memory request total for all Pods 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/manage-resources/memory-constraint-namespace/).
|
||||
Instead of managing total resource use within a namespace, you might want to restrict
|
||||
individual Pods, or the containers in those Pods. To achieve that kind of limiting, use a
|
||||
[LimitRange](/docs/concepts/policy/limit-range/).
|
||||
|
||||
## Clean up
|
||||
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
title: Configure a Pod Quota for a Namespace
|
||||
content_type: task
|
||||
weight: 60
|
||||
description: >-
|
||||
Restrict how many Pods you can create within a namespace.
|
||||
---
|
||||
|
||||
|
||||
<!-- 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)
|
||||
in a {{< glossary_tooltip text="Namespace" term_id="namespace" >}}. You specify quotas in a
|
||||
[ResourceQuota](/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
|
||||
object.
|
||||
|
||||
|
||||
@@ -18,10 +20,9 @@ object.
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
You must have access to create namespaces in your cluster.
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
@@ -36,7 +37,7 @@ kubectl create namespace quota-pod-example
|
||||
|
||||
## Create a ResourceQuota
|
||||
|
||||
Here is the configuration file for a ResourceQuota object:
|
||||
Here is an example manifest for a ResourceQuota:
|
||||
|
||||
{{< codenew file="admin/resource/quota-pod.yaml" >}}
|
||||
|
||||
@@ -66,11 +67,12 @@ status:
|
||||
pods: "0"
|
||||
```
|
||||
|
||||
Here is the configuration file for a Deployment:
|
||||
Here is an example manifest for a {{< glossary_tooltip term_id="deployment" >}}:
|
||||
|
||||
{{< codenew file="admin/resource/quota-pod-deployment.yaml" >}}
|
||||
|
||||
In the configuration file, `replicas: 3` tells Kubernetes to attempt to create three Pods, all running the same application.
|
||||
In that manifest, `replicas: 3` tells Kubernetes to attempt to create three new Pods, all
|
||||
running the same application.
|
||||
|
||||
Create the Deployment:
|
||||
|
||||
@@ -85,7 +87,7 @@ kubectl get deployment pod-quota-demo --namespace=quota-pod-example --output=yam
|
||||
```
|
||||
|
||||
The output shows that even though the Deployment specifies three replicas, only two
|
||||
Pods were created because of the quota.
|
||||
Pods were created because of the quota you defined earlier:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
@@ -95,11 +97,18 @@ spec:
|
||||
status:
|
||||
availableReplicas: 2
|
||||
...
|
||||
lastUpdateTime: 2017-07-07T20:57:05Z
|
||||
lastUpdateTime: 2021-04-02T20: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'
|
||||
```
|
||||
|
||||
### Choice of resource
|
||||
|
||||
In this task you have defined a ResourceQuota that limited the total number of Pods, but
|
||||
you could also limit the total number of other kinds of object. For example, you
|
||||
might decide to limit how many {{< glossary_tooltip text="CronJobs" term_id="cronjob" >}}
|
||||
that can live in a single namespace.
|
||||
|
||||
## Clean up
|
||||
|
||||
Delete your namespace:
|
||||
|
||||
+20
-22
@@ -8,37 +8,35 @@ weight: 70
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
With Kubernetes 1.20 dockershim was deprecated. From the
|
||||
[Dockershim Deprecation FAQ](/blog/2020/12/02/dockershim-faq/)
|
||||
you might already know that most apps do not have a direct dependency on runtime hosting
|
||||
containers. However, there are still a lot of telemetry and security agents
|
||||
that has a dependency on docker to collect containers metadata, logs and
|
||||
metrics. This document aggregates information on how to detect these
|
||||
dependencies and links on how to migrate these agents to use generic tools or
|
||||
alternative runtimes.
|
||||
Kubernetes' support for direct integration with Docker Engine is deprecated, and will be removed. Most apps do not have a direct dependency on runtime hosting containers. However, there are still a lot of telemetry and monitoring agents that has a dependency on docker to collect containers metadata, logs and metrics. This document aggregates information on how to detect these dependencies and links on how to migrate these agents to use generic tools or alternative runtimes.
|
||||
|
||||
## Telemetry and security agents
|
||||
|
||||
There are a few ways agents may run on Kubernetes cluster. Agents may run on
|
||||
nodes directly or as DaemonSets.
|
||||
Within a Kubernetes cluster there are a few different ways to run telemetry or security agents.
|
||||
Some agents have a direct dependency on Docker Engine when they as DaemonSets or
|
||||
directly on nodes.
|
||||
|
||||
### Why do telemetry agents rely on Docker?
|
||||
### Why do some telemetry agents communicate with Docker Engine?
|
||||
|
||||
Historically, Kubernetes was built on top of Docker. Kubernetes is managing
|
||||
networking and scheduling, Docker was placing and operating containers on a
|
||||
node. So you can get scheduling-related metadata like a pod name from Kubernetes
|
||||
and containers state information from Docker. Over time more runtimes were
|
||||
created to manage containers. Also there are projects and Kubernetes features
|
||||
that generalize container status information extraction across many runtimes.
|
||||
Historically, Kubernetes was written to work specifically with Docker Engine.
|
||||
Kubernetes took care of networking and scheduling, relying on Docker Engine for launching
|
||||
and running containers (within Pods) on a node. Some information that is relevant to telemetry,
|
||||
such as a pod name, is only available from Kubernetes components. Other data, such as container
|
||||
metrics, is not the responsibility of the container runtime. Early yelemetry agents needed to query the
|
||||
container runtime **and** Kubernetes to report an accurate picture. Over time, Kubernetes gained
|
||||
the ability to support multiple runtimes, and now supports any runtime that is compatible with
|
||||
the container runtime interface.
|
||||
|
||||
Some agents are tied specifically to the Docker tool. The agents may run
|
||||
commands like [`docker ps`](https://docs.docker.com/engine/reference/commandline/ps/)
|
||||
Some telemetry agents rely specifically on Docker Engine tooling. For example, an agent
|
||||
might run a command such as
|
||||
[`docker ps`](https://docs.docker.com/engine/reference/commandline/ps/)
|
||||
or [`docker top`](https://docs.docker.com/engine/reference/commandline/top/) to list
|
||||
containers and processes or [docker logs](https://docs.docker.com/engine/reference/commandline/logs/)
|
||||
to subscribe on docker logs. With the deprecating of Docker as a container runtime,
|
||||
containers and processes or [`docker logs`](https://docs.docker.com/engine/reference/commandline/logs/)
|
||||
to receive streamed logs. If nodes in your existing cluster use
|
||||
Docker Engine, and you switch to a different container runtime,
|
||||
these commands will not work any longer.
|
||||
|
||||
### Identify DaemonSets that depend on Docker {#identify-docker-dependency}
|
||||
### Identify DaemonSets that depend on Docker Engine {#identify-docker-dependency}
|
||||
|
||||
If a pod wants to make calls to the `dockerd` running on the node, the pod must either:
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ transient slices for resources that are supported by that init system.
|
||||
Depending on the configuration of the associated container runtime,
|
||||
operators may have to choose a particular cgroup driver to ensure
|
||||
proper system behavior. For example, if operators use the `systemd`
|
||||
cgroup driver provided by the `docker` runtime, the `kubelet` must
|
||||
cgroup driver provided by the `containerd` runtime, the `kubelet` must
|
||||
be configured to use the `systemd` cgroup driver.
|
||||
|
||||
### Kube Reserved
|
||||
|
||||
@@ -174,7 +174,7 @@ The output shows that the Container was killed because it is out of memory (OOM)
|
||||
```shell
|
||||
lastState:
|
||||
terminated:
|
||||
containerID: docker://65183c1877aaec2e8427bc95609cc52677a454b56fcb24340dbd22917c23b10f
|
||||
containerID: 65183c1877aaec2e8427bc95609cc52677a454b56fcb24340dbd22917c23b10f
|
||||
exitCode: 137
|
||||
finishedAt: 2017-06-20T20:52:19Z
|
||||
reason: OOMKilled
|
||||
|
||||
@@ -7,8 +7,10 @@ weight: 100
|
||||
<!-- overview -->
|
||||
|
||||
This page shows how to create a Pod that uses a
|
||||
{{< glossary_tooltip text="Secret" term_id="secret" >}} to pull an image from a
|
||||
private container image registry or repository.
|
||||
{{< glossary_tooltip text="Secret" term_id="secret" >}} to pull an image
|
||||
from a private container image registry or repository. There are many private
|
||||
registries in use. This task uses [Docker Hub](https://www.docker.com/products/docker-hub)
|
||||
as an example registry.
|
||||
|
||||
{{% thirdparty-content single="true" %}}
|
||||
|
||||
@@ -18,6 +20,8 @@ private container image registry or repository.
|
||||
|
||||
* To do this exercise, you need the `docker` command line tool, and a
|
||||
[Docker ID](https://docs.docker.com/docker-id/) for which you know the password.
|
||||
* If you are using a different private container registry, you need the command
|
||||
line tool for that registry and any login information for the registry.
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
@@ -59,12 +63,13 @@ The output contains a section similar to this:
|
||||
If you use a Docker credentials store, you won't see that `auth` entry but a `credsStore` entry with the name of the store as value.
|
||||
{{< /note >}}
|
||||
|
||||
## Create a Secret based on existing Docker credentials {#registry-secret-existing-credentials}
|
||||
## Create a Secret based on existing credentials {#registry-secret-existing-credentials}
|
||||
|
||||
A Kubernetes cluster uses the Secret of `kubernetes.io/dockerconfigjson` type to authenticate with
|
||||
a container registry to pull a private image.
|
||||
|
||||
If you already ran `docker login`, you can copy that credential into Kubernetes:
|
||||
If you already ran `docker login`, you can copy
|
||||
that credential into Kubernetes:
|
||||
|
||||
```shell
|
||||
kubectl create secret generic regcred \
|
||||
@@ -77,7 +82,7 @@ secret) then you can customise the Secret before storing it.
|
||||
Be sure to:
|
||||
|
||||
- set the name of the data item to `.dockerconfigjson`
|
||||
- base64 encode the docker file and paste that string, unbroken
|
||||
- base64 encode the Docker configuration file and then paste that string, unbroken
|
||||
as the value for field `data[".dockerconfigjson"]`
|
||||
- set `type` to `kubernetes.io/dockerconfigjson`
|
||||
|
||||
@@ -213,4 +218,3 @@ kubectl get pod private-reg
|
||||
* Learn more about [adding image pull secrets to a service account](/docs/tasks/configure-pod-container/configure-service-account/#add-imagepullsecrets-to-a-service-account).
|
||||
* See [kubectl create secret docker-registry](/docs/reference/generated/kubectl/kubectl-commands/#-em-secret-docker-registry-em-).
|
||||
* See the `imagePullSecrets` field within the [container definitions](/docs/reference/kubernetes-api/workload-resources/pod-v1/#containers) of a Pod
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ The `spec` of a static Pod cannot refer to other API objects
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
This page assumes you're using {{< glossary_tooltip term_id="docker" >}} to run Pods,
|
||||
This page assumes you're using {{< glossary_tooltip term_id="cri-o" >}} to run Pods,
|
||||
and that your nodes are running the Fedora operating system.
|
||||
Instructions for other distributions or Kubernetes installations may vary.
|
||||
|
||||
@@ -156,15 +156,20 @@ already be running.
|
||||
You can view running containers (including static Pods) by running (on the node):
|
||||
```shell
|
||||
# Run this command on the node where the kubelet is running
|
||||
docker ps
|
||||
crictl ps
|
||||
```
|
||||
|
||||
The output might be something like:
|
||||
|
||||
```console
|
||||
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID
|
||||
129fd7d382018 docker.io/library/nginx@sha256:... 11 minutes ago Running web 0 34533c6729106
|
||||
```
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
f6d05272b57e nginx:latest "nginx" 8 minutes ago Up 8 minutes k8s_web.6f802af4_static-web-fk-node1_default_67e24ed9466ba55986d120c867395f3c_378e5f3c
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
`crictl` outputs the image URI and SHA-256 checksum. `NAME` will look more like:
|
||||
`docker.io/library/nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31`.
|
||||
{{< /note >}}
|
||||
|
||||
You can see the mirror Pod on the API server:
|
||||
|
||||
@@ -172,8 +177,8 @@ You can see the mirror Pod on the API server:
|
||||
kubectl get pods
|
||||
```
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
static-web-my-node1 1/1 Running 0 2m
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
static-web 1/1 Running 0 2m
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
@@ -181,7 +186,6 @@ Make sure the kubelet has permission to create the mirror Pod in the API server.
|
||||
[PodSecurityPolicy](/docs/concepts/policy/pod-security-policy/).
|
||||
{{< /note >}}
|
||||
|
||||
|
||||
{{< glossary_tooltip term_id="label" text="Labels" >}} from the static Pod are
|
||||
propagated into the mirror Pod. You can use those labels as normal via
|
||||
{{< glossary_tooltip term_id="selector" text="selectors" >}}, etc.
|
||||
@@ -190,34 +194,33 @@ If you try to use `kubectl` to delete the mirror Pod from the API server,
|
||||
the kubelet _doesn't_ remove the static Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod static-web-my-node1
|
||||
kubectl delete pod static-web
|
||||
```
|
||||
```
|
||||
pod "static-web-my-node1" deleted
|
||||
pod "static-web" deleted
|
||||
```
|
||||
You can see that the Pod is still running:
|
||||
```shell
|
||||
kubectl get pods
|
||||
```
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
static-web-my-node1 1/1 Running 0 12s
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
static-web 1/1 Running 0 4s
|
||||
```
|
||||
|
||||
Back on your node where the kubelet is running, you can try to stop the Docker
|
||||
container manually.
|
||||
Back on your node where the kubelet is running, you can try to stop the container manually.
|
||||
You'll see that, after a time, the kubelet will notice and will restart the Pod
|
||||
automatically:
|
||||
|
||||
```shell
|
||||
# Run these commands on the node where the kubelet is running
|
||||
docker stop f6d05272b57e # replace with the ID of your container
|
||||
crictl stop 129fd7d382018 # replace with the ID of your container
|
||||
sleep 20
|
||||
docker ps
|
||||
crictl ps
|
||||
```
|
||||
```
|
||||
CONTAINER ID IMAGE COMMAND CREATED ...
|
||||
5b920cbaf8b1 nginx:latest "nginx -g 'daemon of 2 seconds ago ...
|
||||
```console
|
||||
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID
|
||||
89db4553e1eeb docker.io/library/nginx@sha256:... 19 seconds ago Running web 1 34533c6729106
|
||||
```
|
||||
|
||||
## Dynamic addition and removal of static pods
|
||||
@@ -230,14 +233,13 @@ The running kubelet periodically scans the configured directory (`/etc/kubelet.d
|
||||
#
|
||||
mv /etc/kubelet.d/static-web.yaml /tmp
|
||||
sleep 20
|
||||
docker ps
|
||||
crictl ps
|
||||
# You see that no nginx container is running
|
||||
mv /tmp/static-web.yaml /etc/kubelet.d/
|
||||
sleep 20
|
||||
docker ps
|
||||
crictl ps
|
||||
```
|
||||
```console
|
||||
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID
|
||||
f427638871c35 docker.io/library/nginx@sha256:... 19 seconds ago Running web 1 34533c6729106
|
||||
```
|
||||
CONTAINER ID IMAGE COMMAND CREATED ...
|
||||
e7a62e3427f1 nginx:latest "nginx -g 'daemon of 27 seconds ago
|
||||
```
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ You may want to set
|
||||
(default to 1),
|
||||
[`.spec.minReadySeconds`](/docs/concepts/workloads/controllers/deployment/#min-ready-seconds)
|
||||
(default to 0) and
|
||||
[`.spec.maxSurge`](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-surge)
|
||||
[`.spec.updateStrategy.rollingUpdate.maxSurge`](/docs/reference/kubernetes-api/workload-resources/daemon-set-v1/#DaemonSetSpec)
|
||||
(a beta feature and defaults to 0) as well.
|
||||
|
||||
### Creating a DaemonSet with `RollingUpdate` update strategy
|
||||
|
||||
+13
-28
@@ -70,14 +70,9 @@ spec:
|
||||
|
||||
Patch your Deployment:
|
||||
|
||||
{{< tabs name="kubectl_patch_example" >}}
|
||||
{{{< tab name="Bash" codelang="bash" >}}
|
||||
kubectl patch deployment patch-demo --patch "$(cat patch-file.yaml)"
|
||||
{{< /tab >}}
|
||||
{{< tab name="PowerShell" codelang="posh" >}}
|
||||
kubectl patch deployment patch-demo --patch $(Get-Content patch-file.yaml -Raw)
|
||||
{{< /tab >}}}
|
||||
{{< /tabs >}}
|
||||
```shell
|
||||
kubectl patch deployment patch-demo --patch-file patch-file.yaml
|
||||
```
|
||||
|
||||
View the patched Deployment:
|
||||
|
||||
@@ -183,7 +178,7 @@ spec:
|
||||
Patch your Deployment:
|
||||
|
||||
```shell
|
||||
kubectl patch deployment patch-demo --patch "$(cat patch-file-tolerations.yaml)"
|
||||
kubectl patch deployment patch-demo --patch-file patch-file-tolerations.yaml
|
||||
```
|
||||
|
||||
View the patched Deployment:
|
||||
@@ -249,7 +244,7 @@ spec:
|
||||
In your patch command, set `type` to `merge`:
|
||||
|
||||
```shell
|
||||
kubectl patch deployment patch-demo --type merge --patch "$(cat patch-file-2.yaml)"
|
||||
kubectl patch deployment patch-demo --type merge --patch-file patch-file-2.yaml
|
||||
```
|
||||
|
||||
View the patched Deployment:
|
||||
@@ -308,14 +303,9 @@ spec:
|
||||
|
||||
Patch your Deployment:
|
||||
|
||||
{{< tabs name="kubectl_retainkeys_example" >}}
|
||||
{{{< tab name="Bash" codelang="bash" >}}
|
||||
kubectl patch deployment retainkeys-demo --type merge --patch "$(cat patch-file-no-retainkeys.yaml)"
|
||||
{{< /tab >}}
|
||||
{{< tab name="PowerShell" codelang="posh" >}}
|
||||
kubectl patch deployment retainkeys-demo --type merge --patch $(Get-Content patch-file-no-retainkeys.yaml -Raw)
|
||||
{{< /tab >}}}
|
||||
{{< /tabs >}}
|
||||
```shell
|
||||
kubectl patch deployment retainkeys-demo --type merge --patch-file patch-file-no-retainkeys.yaml
|
||||
```
|
||||
|
||||
In the output, you can see that it is not possible to set `type` as `Recreate` when a value is defined for `spec.strategy.rollingUpdate`:
|
||||
|
||||
@@ -339,14 +329,9 @@ With this patch, we indicate that we want to retain only the `type` key of the `
|
||||
|
||||
Patch your Deployment again with this new patch:
|
||||
|
||||
{{< tabs name="kubectl_retainkeys2_example" >}}
|
||||
{{{< tab name="Bash" codelang="bash" >}}
|
||||
kubectl patch deployment retainkeys-demo --type merge --patch "$(cat patch-file-retainkeys.yaml)"
|
||||
{{< /tab >}}
|
||||
{{< tab name="PowerShell" codelang="posh" >}}
|
||||
kubectl patch deployment retainkeys-demo --type merge --patch $(Get-Content patch-file-retainkeys.yaml -Raw)
|
||||
{{< /tab >}}}
|
||||
{{< /tabs >}}
|
||||
```shell
|
||||
kubectl patch deployment retainkeys-demo --type merge --patch-file patch-file-retainkeys.yaml
|
||||
```
|
||||
|
||||
Examine the content of the Deployment:
|
||||
|
||||
@@ -425,10 +410,10 @@ The following commands are equivalent:
|
||||
|
||||
|
||||
```shell
|
||||
kubectl patch deployment patch-demo --patch "$(cat patch-file.yaml)"
|
||||
kubectl patch deployment patch-demo --patch-file patch-file.yaml
|
||||
kubectl patch deployment patch-demo --patch 'spec:\n template:\n spec:\n containers:\n - name: patch-demo-ctr-2\n image: redis'
|
||||
|
||||
kubectl patch deployment patch-demo --patch "$(cat patch-file.json)"
|
||||
kubectl patch deployment patch-demo --patch-file patch-file.json
|
||||
kubectl patch deployment patch-demo --patch '{"spec": {"template": {"spec": {"containers": [{"name": "patch-demo-ctr-2","image": "redis"}]}}}}'
|
||||
```
|
||||
|
||||
|
||||
@@ -173,7 +173,10 @@ automatically responds to changes in the number of replicas of the corresponding
|
||||
|
||||
## Create the PDB object
|
||||
|
||||
You can create or update the PDB object with a command like `kubectl apply -f mypdb.yaml`.
|
||||
You can create or update the PDB object using kubectl.
|
||||
```shell
|
||||
kubectl apply -f mypdb.yaml
|
||||
```
|
||||
|
||||
## Check the status of the PDB
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ For example, to download version {{< param "fullversion" >}} on Linux, type:
|
||||
chmod +x kubectl
|
||||
mkdir -p ~/.local/bin/kubectl
|
||||
mv ./kubectl ~/.local/bin/kubectl
|
||||
# and then add ~/.local/bin/kubectl to $PATH
|
||||
# and then append (or prepend) ~/.local/bin to $PATH
|
||||
```
|
||||
|
||||
{{< /note >}}
|
||||
|
||||
@@ -59,7 +59,7 @@ The following methods exist for installing kubectl on Windows:
|
||||
$($(CertUtil -hashfile .\kubectl.exe SHA256)[1] -replace " ", "") -eq $(type .\kubectl.exe.sha256)
|
||||
```
|
||||
|
||||
1. Add the binary in to your `PATH`.
|
||||
1. Append or prepend the kubectl binary folder to your `PATH` environment variable.
|
||||
|
||||
1. Test to ensure the version of `kubectl` is the same as downloaded:
|
||||
|
||||
@@ -172,7 +172,7 @@ Below are the procedures to set up autocompletion for PowerShell.
|
||||
$($(CertUtil -hashfile .\kubectl-convert.exe SHA256)[1] -replace " ", "") -eq $(type .\kubectl-convert.exe.sha256)
|
||||
```
|
||||
|
||||
1. Add the binary in to your `PATH`.
|
||||
1. Append or prepend the kubectl binary folder to your `PATH` environment variable.
|
||||
|
||||
1. Verify plugin is successfully installed
|
||||
|
||||
|
||||
Reference in New Issue
Block a user