升级软件包后,无法正常的安装Kubernetes

因为需要升级内核的原因,将CentOS的软件包也一起升级了一下,升级后发现无法正常的安装K8S集群了。

执行systemctl status kubelet有如下输出:


● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: activating (auto-restart) (Result: exit-code) since Tue 2022-02-15 22:51:17 EST; 6s ago
     Docs: https://kubernetes.io/docs/
  Process: 22267 ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=1/FAILURE)
 Main PID: 22267 (code=exited, status=1/FAILURE)

Feb 15 22:51:17 node1 systemd[1]: kubelet.service: main process exited, code=exited, status=1/FAILURE
Feb 15 22:51:17 node1 systemd[1]: Unit kubelet.service entered failed state.
Feb 15 22:51:17 node1 systemd[1]: kubelet.service failed.

执行``有如下输出:


Feb 15 22:57:10 node1 kubelet[3467]: Flag --network-plugin has been deprecated, will be removed along with dockershim.
Feb 15 22:57:10 node1 kubelet[3467]: Flag --network-plugin has been deprecated, will be removed along with dockershim.
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.087929    3467 server.go:446] "Kubelet version" kubeletVersion="v1.23.3"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.088067    3467 server.go:874] "Client rotation is on, will bootstrap in background"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.089873    3467 certificate_store.go:130] Loading cert/key pair from "/var/lib/kubelet/pki/kubelet-client-current.pem".
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.090757    3467 dynamic_cafile_content.go:156] "Starting controller" name="client-ca-bundle::/etc/kubernetes/pki/ca.crt"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.121338    3467 server.go:693] "--cgroups-per-qos enabled, but --cgroup-root was not specified.  defaulting to /"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.121801    3467 container_manager_linux.go:281] "Container manager verified user specified cgroup-root exists" cgroupRoot=[]
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.122098    3467 container_manager_linux.go:286] "Creating Container Manager object based on Node Config" nodeConfig={RuntimeCgroupsName: SystemCgroupsName: KubeletCgroupsName: ContainerRuntime:docker CgroupsPerQOS:tr
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.122685    3467 topology_manager.go:133] "Creating topology manager with policy per scope" topologyPolicyName="none" topologyScopeName="container"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.122700    3467 container_manager_linux.go:321] "Creating device plugin manager" devicePluginEnabled=true
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.122724    3467 state_mem.go:36] "Initialized new in-memory state store"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.122784    3467 kubelet.go:313] "Using dockershim is deprecated, please consider using a full-fledged CRI implementation"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.122806    3467 client.go:80] "Connecting to docker on the dockerEndpoint" endpoint="unix:///var/run/docker.sock"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.122826    3467 client.go:99] "Start docker client with request timeout" timeout="2m0s"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.128300    3467 docker_service.go:571] "Hairpin mode is set but kubenet is not enabled, falling back to HairpinVeth" hairpinMode=promiscuous-bridge
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.128489    3467 docker_service.go:243] "Hairpin mode is set" hairpinMode=hairpin-veth
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.135699    3467 docker_service.go:258] "Docker cri networking managed by the network plugin" networkPluginName="cni"
Feb 15 22:57:10 node1 kubelet[3467]: I0215 22:57:10.141221    3467 docker_service.go:264] "Docker Info" dockerInfo=&{ID:7NE4:QRQ2:ICIH:N556:WNAB:MT6E:YOZM:UPVH:45JC:MVQG:47KQ:KG6L Containers:0 ContainersRunning:0 ContainersPaused:0 ContainersStopped:0 Images:7 Driver
Feb 15 22:57:10 node1 kubelet[3467]: E0215 22:57:10.141257    3467 server.go:302] "Failed to run kubelet" err="failed to run Kubelet: misconfiguration: kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\""
Feb 15 22:57:10 node1 systemd[1]: kubelet.service: main process exited, code=exited, status=1/FAILURE
Feb 15 22:57:10 node1 systemd[1]: Unit kubelet.service entered failed state.
Feb 15 22:57:10 node1 systemd[1]: kubelet.service failed.

核心信息在于 kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\"

执行如下指令(我默认情况下没有/etc/docker/daemon.json文件,所以我可以使用下面的指令,如果已经存在该文件了,则需要将exe-opts添加到daemon.json中):

1
2
3
4
5
6
7

sudo tee /etc/docker/daemon.json << EOF
{
    "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

参考资料

  1. 【kubeadm初始化报错】failed to run Kubelet: misconfiguration: kubelet cgroup driver: “cgroupfs” is different from docker cgroup driver: “systemd”