|
| 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