|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.25: cgroup v2 graduates to GA" |
| 4 | +date: 2022-08-31 |
| 5 | +slug: cgroupv2-ga-1-25 |
| 6 | +--- |
| 7 | + |
| 8 | +**Authors:**: David Porter (Google), Mrunal Patel (Red Hat) |
| 9 | + |
| 10 | +Kubernetes 1.25 brings cgroup v2 to GA (general availability), letting the |
| 11 | +[kubelet](/docs/concepts/overview/components/#kubelet) use the latest container resource |
| 12 | +management capabilities. |
| 13 | + |
| 14 | +## What are cgroups? |
| 15 | + |
| 16 | +Effective [resource management](/docs/concepts/configuration/manage-resources-containers/) is a |
| 17 | +critical aspect of Kubernetes. This involves managing the finite resources in |
| 18 | +your nodes, such as CPU, memory, and storage. |
| 19 | + |
| 20 | +*cgroups* are a Linux kernel capability that establish resource management |
| 21 | +functionality like limiting CPU usage or setting memory limits for running |
| 22 | +processes. |
| 23 | + |
| 24 | +When you use the resource management capabilities in Kubernetes, such as configuring |
| 25 | +[requests and limits for Pods and containers](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits), |
| 26 | +Kubernetes uses cgroups to enforce your resource requests and limits. |
| 27 | + |
| 28 | +The Linux kernel offers two versions of cgroups: cgroup v1 and cgroup v2. |
| 29 | + |
| 30 | +## What is cgroup v2? |
| 31 | + |
| 32 | +cgroup v2 is the latest version of the Linux cgroup API. cgroup v2 provides a |
| 33 | +unified control system with enhanced resource management capabilities. |
| 34 | + |
| 35 | +cgroup v2 has been development in the Linux Kernel since 2016 and in recent |
| 36 | +years has matured across the container ecosystem. With Kubernetes 1.25, cgroup |
| 37 | +v2 support has graduated to general availability. |
| 38 | + |
| 39 | +Many recent releases of Linux distributions have switched over to cgroup v2 by |
| 40 | +default so it's important that Kubernetes continues to work well on these new |
| 41 | +updated distros. |
| 42 | + |
| 43 | +cgroup v2 offers several improvements over cgroup v1, such as the following: |
| 44 | + |
| 45 | +* Single unified hierarchy design in API |
| 46 | +* Safer sub-tree delegation to containers |
| 47 | +* Newer features like [Pressure Stall Information](https://www.kernel.org/doc/html/latest/accounting/psi.html) |
| 48 | +* Enhanced resource allocation management and isolation across multiple resources |
| 49 | + * Unified accounting for different types of memory allocations (network and kernel memory, etc) |
| 50 | + * Accounting for non-immediate resource changes such as page cache write backs |
| 51 | + |
| 52 | +Some Kubernetes features exclusively use cgroup v2 for enhanced resource |
| 53 | +management and isolation. For example, |
| 54 | +the [MemoryQoS feature](/blog/2021/11/26/qos-memory-resources/) improves |
| 55 | +memory utilization and relies on cgroup v2 functionality to enable it. New |
| 56 | +resource management features in the kubelet will also take advantage of the new |
| 57 | +cgroup v2 features moving forward. |
| 58 | + |
| 59 | +## How do you use cgroup v2? |
| 60 | + |
| 61 | +Many Linux distributions are switching to cgroup v2 by default; you might start |
| 62 | +using it the next time you update the Linux version of your control plane and |
| 63 | +nodes! |
| 64 | + |
| 65 | +Using a Linux distribution that uses cgroup v2 by default is the recommended |
| 66 | +method. Some of the popular Linux distributions that use cgroup v2 include the |
| 67 | +following: |
| 68 | + |
| 69 | +* Container Optimized OS (since M97) |
| 70 | +* Ubuntu (since 21.10) |
| 71 | +* Debian GNU/Linux (since Debian 11 Bullseye) |
| 72 | +* Fedora (since 31) |
| 73 | +* Arch Linux (since April 2021) |
| 74 | +* RHEL and RHEL-like distributions (since 9) |
| 75 | + |
| 76 | +To check if your distribution uses cgroup v2 by default, |
| 77 | +refer to [Check your cgroup version](/docs/concepts/architecture/cgroups/#check-cgroup-version) or |
| 78 | +consult your distribution's documentation. |
| 79 | + |
| 80 | +If you're using a managed Kubernetes offering, consult your provider to |
| 81 | +determine how they're adopting cgroup v2, and whether you need to take action. |
| 82 | + |
| 83 | +To use cgroup v2 with Kubernetes, you must meet the following requirements: |
| 84 | + |
| 85 | +* Your Linux distribution enables cgroup v2 on kernel version 5.8 or later |
| 86 | +* Your container runtime supports cgroup v2. For example: |
| 87 | + * [containerd](https://containerd.io/) v1.4 or later |
| 88 | + * [cri-o](https://cri-o.io/) v1.20 or later |
| 89 | +* The kubelet and the container runtime are configured to use the [systemd cgroup driver](/docs/setup/production-environment/container-runtimes#systemd-cgroup-driver) |
| 90 | + |
| 91 | +The kubelet and container runtime use a [cgroup driver](/docs/setup/production-environment/container-runtimes#cgroup-drivers) |
| 92 | +to set cgroup paramaters. When using cgroup v2, it's strongly recommended that both |
| 93 | +the kubelet and your container runtime use the |
| 94 | +[systemd cgroup driver](/docs/setup/production-environment/container-runtimes#systemd-cgroup-driver), |
| 95 | +so that there's a single cgroup manager on the system. To configure the kubelet |
| 96 | +and the container runtime to use the driver, refer to the |
| 97 | +[systemd cgroup driver documentation](/docs/setup/production-environment/container-runtimes#systemd-cgroup-driver). |
| 98 | + |
| 99 | +## Migrate to cgroup v2 |
| 100 | + |
| 101 | +When you run Kubernetes with a Linux distribution that enables cgroup v2, the |
| 102 | +kubelet should automatically adapt without any additional configuration |
| 103 | +required, as long as you meet the requirements. |
| 104 | + |
| 105 | +In most cases, you won't see a difference in the user experience when you |
| 106 | +switch to using cgroup v2 unless your users access the cgroup file system |
| 107 | +directly. |
| 108 | + |
| 109 | +If you have applications that access the cgroup file system directly, either on |
| 110 | +the node or from inside a container, you must update the applications to use |
| 111 | +the cgroup v2 API instead of the cgroup v1 API. |
| 112 | + |
| 113 | +Scenarios in which you might need to update to cgroup v2 include the following: |
| 114 | + |
| 115 | +* If you run third-party monitoring and security agents that depend on the cgroup file system, update the |
| 116 | + agents to versions that support cgroup v2. |
| 117 | +* If you run [cAdvisor](https://github.com/google/cadvisor) as a stand-alone |
| 118 | + DaemonSet for monitoring pods and containers, update it to v0.43.0 or later. |
| 119 | +* If you deploy Java applications with the JDK, prefer to use JDK 11.0.16 and |
| 120 | + later or JDK 15 and later, which [fully support cgroup v2](https://bugs.openjdk.org/browse/JDK-8230305). |
| 121 | + |
| 122 | +## Learn more |
| 123 | + |
| 124 | +* Read the [Kubernetes cgroup v2 documentation](/docs/concepts/architecture/cgroups/) |
| 125 | +* Read the enhancement proposal, [KEP 2254](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/2254-cgroup-v2/README.md) |
| 126 | +* Learn more about |
| 127 | + [cgroups](https://man7.org/linux/man-pages/man7/cgroups.7.html) on Linux Manual Pages |
| 128 | + and [cgroup v2](https://docs.kernel.org/admin-guide/cgroup-v2.html) on the Linux Kernel documentation |
| 129 | + |
| 130 | + |
| 131 | +## Get involved |
| 132 | + |
| 133 | +Your feedback is always welcome! SIG Node meets regularly and are available in |
| 134 | +the `#sig-node` channel in the Kubernetes [Slack](https://slack.k8s.io/), or |
| 135 | +using the SIG [mailing list](https://github.com/kubernetes/community/tree/master/sig-node#contact). |
| 136 | + |
| 137 | +cgroup v2 has had a long journey and is a great example of open source |
| 138 | +community collaboration across the industry because it required work across the |
| 139 | +stack, from the Linux Kernel to systemd to various container runtimes, and (of |
| 140 | +course) Kubernetes. |
| 141 | + |
| 142 | +## Acknowledgments |
| 143 | + |
| 144 | +We would like to thank [Giuseppe Scrivano](https://github.com/giuseppe) who |
| 145 | +initiated cgroup v2 support in Kubernetes, and reviews and leadership from the |
| 146 | +SIG Node community including chairs [Dawn Chen](https://github.com/dchen1107) |
| 147 | +and [Derek Carr](https://github.com/derekwaynecarr). |
| 148 | + |
| 149 | +We'd also like to thank the maintainers of container runtimes like Docker, |
| 150 | +containerd and CRI-O, and the maintainers of components like |
| 151 | +[cAdvisor](https://github.com/google/cadvisor) |
| 152 | +and [runc, libcontainer](https://github.com/opencontainers/runc), |
| 153 | +which underpin many container runtimes. Finally, this wouldn't have been |
| 154 | +possible without support from systemd and upstream Linux Kernel maintainers. |
| 155 | + |
| 156 | +It's a team effort! |
0 commit comments