Skip to content

Commit 2355094

Browse files
committed
kubeadm: add a new page
- Add the new page "Configuring a cgroup driver" The page includes details on how to configure the cgroup driver using kubeadm. It also includes a migration guide for users to move to the "systemd" driver. - Link to the new page from install-kubeadm.md and container-runtimes.md
1 parent e1acd19 commit 2355094

File tree

3 files changed

+142
-26
lines changed

3 files changed

+142
-26
lines changed

content/en/docs/setup/production-environment/container-runtimes.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Changing the settings such that your container runtime and kubelet use `systemd`
4848
stabilized the system. To configure this for Docker, set `native.cgroupdriver=systemd`.
4949

5050
{{< caution >}}
51-
Changing the cgroup driver of a Node that has joined a cluster is strongly *not* recommended.
51+
Changing the cgroup driver of a Node that has joined a cluster is a sensitive operation.
5252
If the kubelet has created Pods using the semantics of one cgroup driver, changing the container
5353
runtime to another cgroup driver can cause errors when trying to re-create the Pod sandbox
5454
for such existing Pods. Restarting the kubelet may not solve such errors.
@@ -57,6 +57,11 @@ If you have automation that makes it feasible, replace the node with another usi
5757
configuration, or reinstall it using automation.
5858
{{< /caution >}}
5959

60+
### Migrating to the `systemd` driver in kubeadm managed clusters
61+
62+
Follow this [Migration guide](/tasks/administer-cluster/kubeadm/configure-cgroup-driver)
63+
if you wish to migrate to the `systemd` cgroup driver in existing kubeadm managed clusters.
64+
6065
## Container runtimes
6166

6267
{{% thirdparty-content %}}

content/en/docs/setup/production-environment/tools/kubeadm/install-kubeadm.md

+9-25
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ sudo mkdir -p /opt/cni/bin
233233
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-amd64-${CNI_VERSION}.tgz" | sudo tar -C /opt/cni/bin -xz
234234
```
235235

236-
Define the directory to download command files
236+
Define the directory to download command files
237237

238238
{{< note >}}
239239
The `DOWNLOAD_DIR` variable must be set to a writable directory.
@@ -284,33 +284,17 @@ See the [Kubeadm Troubleshooting guide](/docs/setup/production-environment/tools
284284
The kubelet is now restarting every few seconds, as it waits in a crashloop for
285285
kubeadm to tell it what to do.
286286

287-
## Configure cgroup driver used by kubelet on control-plane node
287+
## Configuring a cgroup driver
288288

289-
When using Docker, kubeadm will automatically detect the cgroup driver for the kubelet
290-
and set it in the `/var/lib/kubelet/config.yaml` file during runtime.
289+
Both the container runtime and the kubelet have a property called
290+
["cgroup driver"](/docs/setup/production-environment/container-runtimes/), which is important
291+
for the management of cgroups on Linux machines.
291292

292-
If you are using a different CRI, you must pass your `cgroupDriver` value to `kubeadm init`, like so:
293-
294-
```yaml
295-
apiVersion: kubelet.config.k8s.io/v1beta1
296-
kind: KubeletConfiguration
297-
cgroupDriver: <value>
298-
```
299-
300-
For further details, please read [Using kubeadm init with a configuration file](/docs/reference/setup-tools/kubeadm/kubeadm-init/#config-file).
301-
302-
Please mind, that you **only** have to do that if the cgroup driver of your CRI
303-
is not `cgroupfs`, because that is the default value in the kubelet already.
304-
305-
{{< note >}}
306-
Since `--cgroup-driver` flag has been deprecated by the kubelet, if you have that in `/var/lib/kubelet/kubeadm-flags.env`
307-
or `/etc/default/kubelet`(`/etc/sysconfig/kubelet` for RPMs), please remove it and use the KubeletConfiguration instead
308-
(stored in `/var/lib/kubelet/config.yaml` by default).
309-
{{< /note >}}
310-
311-
The automatic detection of cgroup driver for other container runtimes
312-
like CRI-O and containerd is work in progress.
293+
{{< warning >}}
294+
Matching the container runtime and kubelet cgroup drivers is required or otherwise the kubelet process will fail.
295+
{{< warning >}}
313296

297+
See [Configuring a cgroup driver](/tasks/administer-cluster/kubeadm/configure-cgroup-driver) for more details.
314298

315299
## Troubleshooting
316300

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: Configuring a cgroup driver
3+
content_type: task
4+
weight: 10
5+
---
6+
7+
<!-- overview -->
8+
9+
This page explains how to configure the kubelet cgroup driver to match the container
10+
runtime cgroup driver for kubeadm clusters.
11+
12+
## {{% heading "prerequisites" %}}
13+
14+
You should be familiar with the Kubernetes
15+
[container runtime requirements](/docs/setup/production-environment/container-runtimes).
16+
17+
<!-- steps -->
18+
19+
## Configuring the container runtime cgroup driver
20+
21+
The [Container runtimes](/docs/setup/production-environment/container-runtimes) page
22+
explains that the `systemd` driver is recommended for kubeadm based setups instead
23+
of the `cgroupfs` driver, because kubeadm manages the kubelet as a systemd service.
24+
25+
The page also provides details on how to setup a number of different container runtimes with the
26+
`systemd` driver by default.
27+
28+
## Configuring the kubelet cgroup driver
29+
30+
kubeadm allows you to pass a `KubeletConfiguration` structure during `kubeadm init`.
31+
This `KubeletConfiguration` can include the `cgroupDriver` field which controls the cgroup
32+
driver of the kubelet.
33+
34+
{{< note >}}
35+
36+
{{< feature-state for_k8s_version="v1.21" state="stable" >}}
37+
38+
If the user is not setting the `cgroupDriver` field under `KubeletConfiguration`,
39+
`kubeadm init` will default it to `systemd`.
40+
{{< /note >}}
41+
42+
A minimal example of configuring the field explicitly:
43+
44+
```yaml
45+
# kubeadm-config.yaml
46+
kind: ClusterConfiguration
47+
apiVersion: kubeadm.k8s.io/v1beta2
48+
kubernetesVersion: v1.21
49+
---
50+
kind: KubeletConfiguration
51+
apiVersion: kubelet.config.k8s.io/v1beta1
52+
cgroupDriver: systemd
53+
```
54+
55+
Such a configuration file can then be passed to the kubeadm command:
56+
57+
```shell
58+
kubeadm init --config kubeadm-config.yaml
59+
```
60+
61+
{{< note >}}
62+
Kubeadm uses the same `KubeletConfiguration` for all nodes in the cluster.
63+
The `KubeletConfiguration` is stored in a [ConfigMap](docs/concepts/configuration/configmap)
64+
object under the `kube-system` namespace.
65+
66+
Executing the sub commands `init`, `join` and `upgrade` would result in kubeadm
67+
writing the `KubeletConfiguration` as a file under `/var/lib/kubelet/config.yaml`
68+
and passing it to the local node kubelet.
69+
{{< /note >}}
70+
71+
## Using the `cgroupfs` driver
72+
73+
As this guide explains using the `cgroupfs` driver with kubeadm is not recommended.
74+
75+
To continue using `cgroupfs` and to prevent `kubeadm upgrade` from modifying the
76+
`KubeletConfiguration` cgroup driver on existing setups, you must be explicit
77+
about its value. This applies to a case where you do not wish future versions
78+
of kubeadm to apply the `systemd` driver by default.
79+
80+
See the below section on "Modify the kubelet ConfigMap" for details on
81+
how to be explicit about the value.
82+
83+
If you wish to configure a container runtime to use the `cgroupfs` driver,
84+
you must refer to the documentation of the container runtime of your choice.
85+
86+
## Migrating to the `systemd` driver
87+
88+
To change the cgroup driver of an existing kubeadm cluster to `systemd` in-place,
89+
a similar procedure to a kubelet upgrade is required. This must include both
90+
steps outlined below.
91+
92+
{{< note >}}
93+
Alternatively, it is possible to replace the old nodes in the cluster with new ones
94+
that use the `systemd` driver. This requires executing only the first step below
95+
before joining the new nodes and ensuring the workloads can safely move to the new
96+
nodes before deleting the old nodes.
97+
{{< /note >}}
98+
99+
### Modify the kubelet ConfigMap
100+
101+
- Find the kubelet ConfigMap name using `kubectl get cm -n kube-system | grep kubelet-config`.
102+
- Call `kubectl edit cm kubelet-config-x.yy -n kube-system` (replace `x.yy` with
103+
the Kubernetes version).
104+
- Either modify the existing `cgroupDriver` value or add a new field that looks like this:
105+
106+
```yaml
107+
cgroupDriver: systemd
108+
```
109+
This field must be present under the `kubelet:` section of the ConfigMap.
110+
111+
### Update the cgroup driver on all nodes
112+
113+
For each node in the cluster:
114+
115+
- [Drain the node](/docs/tasks/administer-cluster/safely-drain-node) using `kubectl drain <node-name> --ignore-daemonsets`
116+
- Stop the kubelet using `systemctl stop kubelet`
117+
- Stop the container runtime
118+
- Modify the container runtime cgroup driver to `systemd`
119+
- Set `cgroupDriver: systemd` in `/var/lib/kubelet/config.yaml`
120+
- Start the container runtime
121+
- Start the kubelet using `systemctl start kubelet`
122+
- [Uncordon the node](/docs/tasks/administer-cluster/safely-drain-node) using `kubectl uncordon <node-name>`
123+
124+
Execute these steps on nodes one at a time to ensure workloads
125+
have sufficient time to schedule on different nodes.
126+
127+
Once the process is complete ensure that all nodes and workloads are healthy.

0 commit comments

Comments
 (0)