CentOS 中默认的 Docker 安装是从systemd
Cgroup 开始的。我从官方 YUM repo 安装了 Kubernetes,systemddrop-in 10-kubeadm.conf
包含以下内容:
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt"
Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=0"
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"
Environment="KUBELET_CERTIFICATE_ARGS=--rotate-certificates=true --cert-dir=/var/lib/kubelet/pki"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CGROUP_ARGS $KUBELET_CERTIFICATE_ARGS $KUBELET_EXTRA_ARGS
我还尝试获取环境变量来查看 systemd 插件是否能正确覆盖(systemctl show --property=Environment kubelet | cat
):
Environment=KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf\x20--kubeconfig=/etc/kubernetes/kubelet.conf KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests\x20--allow-privileged=true KUBELET_NETWORK_ARGS=--network-plugin=cni\x20--cni-conf-dir=/etc/cni/net.d\x20--cni-bin-dir=/opt/cni/bin KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10\x20--cluster-domain=cluster.local KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook\x20--client-ca-file=/etc/kubernetes/pki/ca.crt KUBELET_CADVISOR_ARGS=--cadvisor-port=0 KUBELET_CGROUP_ARGS=--cgroup-driver=systemd KUBELET_CERTIFICATE_ARGS=--rotate-certificates=true\x20--cert-dir=/var/lib/kubelet/pki
当我使用 初始化集群时kubeadm init --apiserver-advertise-address=X.X.X.X --pod-network-cidr=10.244.0.0/16
,该过程成功了。但是,运行时kubelet version
出现 Cgroup 配置错误:
error: failed to run Kubelet: failed to create kubelet: misconfiguration: kubelet cgroup driver: "cgroupfs" is different from docker cgroup driver: "systemd"
版本
- CentOS Linux 版本 7.4.1708(核心)
- Kubernetes 版本(
kubectl version
):1.9(GitVersion:1.9.1;Go 版本:go1.9.2) - Docker 版本(
docker version
):1.12.6
这个问题的正确解决方案是什么?我尝试将 Kubernetes 的 Cgroup 更改为 cgroupfs,但 kubeadm 一直给我“kubelet 无响应”错误。我该如何让 Kubernetes 接受给它的 CGroup 参数?
答案1
我遇到了同样的问题。您需要确保 Docker 和 Kubelet 使用相同的 cgroup 驱动程序运行。
在 Centos 中,Docker 在 cgroupfs 中运行,而 kubelet 在 systemd cgroup 中运行。为了更改此设置,您需要遵循 Kubelet 文档: https://kubernetes.io/docs/setup/independent/install-kubeadm/#configure-cgroup-driver-used-by-kubelet-on-master-node
要修复此问题,您需要:
sed -i "s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
然后重启 kubelet
systemctl daemon-reload
systemctl restart kubelet
答案2
使用你的 cgroup-driver 值修改文件 /etc/sysconfig/kubelet,如下所示:
KUBELET_EXTRA_ARGS=--cgroup-driver=<value>
为了获得您的Docker Cgroup 驱动程序:
docker info | grep -i 'cgroup driver'
然后重新加载systemd 守护进程并重新启动库贝莱特:
systemctl daemon-reload
systemctl restart kubelet