成功最有效的方法就是向有经验的人学习!

Cgroup drivers和systemd cgroupfs区别

通过下面内容可知:systemd和cgroupfs都是CGroup管理器,而systemd是大多数Linux发行版原生的。如果Docker运行时和kubelet的CGroup驱动配置为cgroupfs,则意味着使用了systemd作为init system的系统上有两个不同的CGroup管理器。

如果不修改配置,会在kubeadm init时有提示:

[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. 
The recommended driver is "systemd". 
Please follow the guide at https://kubernetes.io/docs/setup/cri/

https://kubernetes.io/docs/setup/production-environment/container-runtimes/
When systemd is chosen as the init system for a Linux distribution, the init process generates and consumes a root control group (cgroup) and acts as a cgroup manager. Systemd has a tight integration with cgroups and allocates a cgroup per systemd unit. It’s possible to configure your container runtime and the kubelet to use cgroupfs. Using cgroupfs alongside systemd means that there will be two different cgroup managers.
当选择systemd作为Linux发行版的init system时,init process生成并使用一个root控制组(cgroup),并充当cgroup管理器。Systemd与cgroups紧密集成,并为每个Systemd Unit分配一个cgroup。可以将容器runtime 和kubelet配置为使用cgroupfs。与systemd一起使用cgroupfs意味着将有两个不同的cgroup管理器。

通过下面内容可知:同时使用cgroupfs和systemd的节点,在资源紧张时会变得不稳定。

A single cgroup manager simplifies the view of what resources are being allocated and will by default have a more consistent view of the available and in-use resources. When there are two cgroup managers on a system, you end up with two views of those resources. In the field, people have reported cases where nodes that are configured to use cgroupfs for the kubelet and Docker, but systemd for the rest of the processes, become unstable under resource pressure.
单个cgroup管理器简化了资源分配视图,并且默认情况下对可用和正在使用的资源有更一致的视图。当一个系统上有两个cgroup管理器时,您将得到这些资源的两个视图。在某些领域中,有人报告了这样的情况:为kubelet和Docker配置为使用cgroupfs,但为其余Processes配置为systemd的节点,在资源紧张时变得不稳定。

docker 默认Cgroup Driver为cgroup,但是在kubernetes1.14之后的版本推荐使用systemd,对于18.x.x版本的docker来说是相对比较简单的,只需要修改/etc/docker/daemon.json的配置就可以配置docker的cgroup驱动。

可以通过修改docker的/etc/docker/daemon.json文件,更改docker和kubelet的CGroup Driver:

{undefined
  "exec-opts": ["native.cgroupdriver=systemd"]
}

完整示例

{
  "registry-mirrors": ["http://xxxxxxxxxxxxx"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "max-concurrent-downloads": 20,
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
    },
  "data-root": "/var/lib/docker"
}

查看kubelet --help 提示,默认的是cgroupfs,所以除了修改docker的配置,kubelet的配置也要修改,否则通过kubelet调度的容器将无法运行!

--cgroup-driver string                                     Driver that the kubelet uses to manipulate cgroups on the host.  Possible values: 'cgroupfs', 'systemd' (default "cgroupfs")

修改kubelet的config.yaml:

/var/lib/kubelet/config.yaml

apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
……
authorization:
……
cgroupDriver: systemd

Changing the settings such that your container runtime and kubelet use systemd as the cgroup driver stabilized the system. To configure this for Docker, set native.cgroupdriver=systemd.
更改设置,使容器运行时和kubelet使用systemd作为cgroup驱动程序来稳定系统。设置native.cgroupdriver=systemd来为Docker配置这个。

警告:

强烈建议不要更改已加入集群的节点的cgroup驱动程序。

如果kubelet使用一个cgroup驱动程序的语义创建了Pods,那么在试图为现有的Pods重新创建Pod沙箱时,将容器运行时更改为另一个cgroup驱动程序可能会导致错误。重新启动kubelet可能无法解决这些错误。

赞(0) 打赏
未经允许不得转载:陈桂林博客 » Cgroup drivers和systemd cgroupfs区别
分享到

大佬们的评论 抢沙发

全新“一站式”建站,高质量、高售后的一条龙服务

微信 抖音 支付宝 百度 头条 快手全平台打通信息流

橙子建站.极速智能建站8折购买虚拟主机

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册