Set systemd as Cgroup Driver

We want to use systemd as cgroup driver for docker and kubelet, let's see how to achieve that.

Configure docker

After you install and start docker, by default it will use cgroupfs as the cgroup driver, check by running:

docker info | grep Cgroup

Cgroup Driver: cgroupfs

Edit /usr/lib/systemd/system/docker.service file:

ExecStart=/usr/bin/dockerd --exec-opt native.cgroupdriver=systemd

Then reload daemon and restart docker

systemctl daemon-reload
systemctl restart docker

Verify the change

docker info | grep Cgroup

Cgroup Driver: systemd

Configure kubelet

Currently, the kubelet cannot automatically detects the cgroup driver used by the CRI runtime, but the value of --cgroup-driver must match the cgroup driver used by the CRI runtime to ensure the health of the kubelet.

Note: interesting thing is kubeadm init now can automatically detect and set kubelet with the same cgroup driver as docker (I use version 1.13.x).

There is a file: /var/lib/kubelet/kubeadm-flags.env, that kubeadm init and kubeadm join generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically, in /etc/systemd/system/kubelet.service.d/10-kubeadm.conf you can see it:
uc?id=1Wn2J8wk_7e36Z-W_x5lgM93nFBkGJ7EV

you will see systemd resides in /var/lib/kubelet/kubeadm-flags.env:

KUBELET_KUBEADM_ARGS=--cgroup-driver=systemd --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.1

Anyway let's see how to do the configuration manually. After install kubelet, go to edit /etc/systemd/system/kubelet.service.d/10-kubeadm.conf file, add this line:

Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"

Append $KUBELET_CGROUP_ARGS at end of ExecStart=/usr/bin/kubelet statement:

uc?id=1AiZ-y12HevZivQm5TwIYYzY-OX7lfzho

Then when you complete kubeadm init, verify the change:

ps aux | grep kubelet

root     19864  4.5  0.6 2326996 104192 ?      Ssl  01:21  32:49 /usr/bin/kubelet
--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf 
--kubeconfig=/etc/kubernetes/kubelet.conf 
--config=/var/lib/kubelet/config.yaml 
--cgroup-driver=systemd 
--network-plugin=cni 
--pod-infra-container-image=k8s.gcr.io/pause:3.1 
--cgroup-driver=systemd 

You see, there are 2 --cgroup-driver=systemd options, so I think manually configure kubelet service file is needless.

转载于:https://www.cnblogs.com/chengdol/p/10504061.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值