无法运行 Kubelet:验证服务连接:未为端点实现 CRI v1 运行时 API

无法运行 Kubelet:验证服务连接:未为端点实现 CRI v1 运行时 API

我已经kubelet 1.26.0使用命令在 Ubuntu 22.04 上安装apt install kubelet,但是当我尝试时journalctl -xeu kubelet得到以下结果:

░░ 
░░ The unit kubelet.service has entered the 'failed' state with result 'exit-code'.
Dec 14 15:41:16 a systemd[1]: kubelet.service: Scheduled restart job, restart counter is at 86.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ Automatic restarting of the unit kubelet.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Dec 14 15:41:16 a systemd[1]: Stopped kubelet: The Kubernetes Node Agent.
░░ Subject: A stop job for unit kubelet.service has finished
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A stop job for unit kubelet.service has finished.
░░ 
░░ The job identifier is 26301 and the job result is done.
Dec 14 15:41:16 a systemd[1]: Started kubelet: The Kubernetes Node Agent.
░░ Subject: A start job for unit kubelet.service has finished successfully
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit kubelet.service has finished successfully.
░░ 
░░ The job identifier is 26301.
Dec 14 15:41:16 a kubelet[18015]: Flag --pod-infra-container-image has been deprecated, will be removed in 1.27. Image garbage collector will get sandbox image information from CRI.
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.367525   18015 server.go:198] "--pod-infra-container-image will not be pruned by the image garbage collector in kubelet and should also be set in the rem>
Dec 14 15:41:16 a kubelet[18015]: Flag --pod-infra-container-image has been deprecated, will be removed in 1.27. Image garbage collector will get sandbox image information from CRI.
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.371255   18015 server.go:412] "Kubelet version" kubeletVersion="v1.26.0"
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.371272   18015 server.go:414] "Golang settings" GOGC="" GOMAXPROCS="" GOTRACEBACK=""
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.371499   18015 server.go:836] "Client rotation is on, will bootstrap in background"
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.372757   18015 certificate_store.go:130] Loading cert/key pair from "/var/lib/kubelet/pki/kubelet-client-current.pem".
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.373608   18015 dynamic_cafile_content.go:157] "Starting controller" name="client-ca-bundle::/etc/kubernetes/pki/ca.crt"
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.399357   18015 server.go:659] "--cgroups-per-qos enabled, but --cgroup-root was not specified.  defaulting to /"
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.399717   18015 container_manager_linux.go:267] "Container manager verified user specified cgroup-root exists" cgroupRoot=[]
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.399832   18015 container_manager_linux.go:272] "Creating Container Manager object based on Node Config" nodeConfig={RuntimeCgroupsName: SystemCgroupsName>
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.399866   18015 topology_manager.go:134] "Creating topology manager with policy per scope" topologyPolicyName="none" topologyScopeName="container"
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.399883   18015 container_manager_linux.go:308] "Creating device plugin manager"
Dec 14 15:41:16 a kubelet[18015]: I1214 15:41:16.399940   18015 state_mem.go:36] "Initialized new in-memory state store"
Dec 14 15:41:16 a kubelet[18015]: E1214 15:41:16.402173   18015 run.go:74] "command failed" err="failed to run Kubelet: validate service connection: CRI v1 runtime API is not implemented for endpoint \">
Dec 14 15:41:16 a systemd[1]: kubelet.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ An ExecStart= process belonging to unit kubelet.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Dec 14 15:41:16 a systemd[1]: kubelet.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit kubelet.service has entered the 'failed' state with result 'exit-code'.
lines 2547-2600/2600 (END)

我不知道问题出在哪里。我该如何解决它?

答案1

今天刚遇到同样的问题 - 似乎与这一改变在 K8s 1.26 中。

解决方案是安装 containerd 1.6,但是...似乎还没有适用于该版本的 APT 包 :(。我只能找到适用于 Ubuntu 22.10 及以上版本的 1.6+ 包。

可能的解决方法:

  1. 上面链接中列出的那个 - 运行旧版本的 kubelet(1.25)
apt remove --purge kubelet
apt install -y kubeadm kubelet=1.25.5-00
  1. 通过下载并替换二进制文件,手动将 containerd 升级到 1.6 或更高版本
wget https://github.com/containerd/containerd/releases/download/v1.6.12/containerd-1.6.12-linux-amd64.tar.gz
tar xvf containerd-1.6.12-linux-amd64.tar.gz
systemctl stop containerd
cd bin
cp * /usr/bin/
systemctl start containerd

我目前正在测试这两个选项,它们似乎确实有效。希望在(不久的将来)我们能获得containerd1.6+ 版 apt 软件包,让我们的工作更轻松 :)

编辑以添加第三个选项(这似乎是迄今为止最简单的):

  1. 在 Docker 存储库中,有适用于 containerd 1.6 及更高版本的软件包。因此,您也可以添加 Docker 存储库,然后从那里安装 containerd.io:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo   "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install containerd.io

答案2

我对此有些困惑,@Bogd 的回答让我找到了正确的方向。评论太长了,所以这里是使用 Flannel 在新的 Ubuntu 22.04 节点上配置稳定的 Kubernetes 1.26 主服务器的步骤。

  1. sudo apt-get update
  2. sudo apt install apt-transport-https curl

安装containerd(参考:https://docs.docker.com/engine/install/ubuntu/

  1. sudo mkdir -p /etc/apt/keyrings
  2. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  3. echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  4. sudo apt-get update
  5. sudo apt-get install containerd.io

创建 containerd 配置

  1. sudo mkdir -p /etc/containerd
  2. sudo containerd config default | sudo tee /etc/containerd/config.toml

编辑 /etc/containerd/config.toml

  1. sudo nano /etc/containerd/config.toml 设置 SystemdCgroup = true
  2. sudo systemctl restart containerd

安装 Kubernetes

  1. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
  2. sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
  3. sudo apt install kubeadm kubelet kubectl kubernetes-cni

禁用交换

  1. sudo swapoff -a

检查并删除任何交换条目(如果存在)

  1. sudo nano /etc/fstab

避免在 kubeinit 上出现“/proc/sys/net/bridge/bridge-nf-call-iptables 不存在”错误(参考https://github.com/kubernetes/kubeadm/issues/1062)。如果在步骤6中也安装了docker,那么这个就没有必要了。

  1. sudo modprobe br_netfilter
  2. sudo nano /proc/sys/net/ipv4/ip_forward 编辑 ip_forward 文件中的条目并更改为 1。(或使用sysctl -w net.ipv4.ip_forward=1- 感谢@dpjanes,请参阅评论)

与 Flannel 一起使用的 kubeinit

  1. sudo kubeadm init --pod-network-cidr=10.244.0.0/16

按照 kubadm 命令的说明复制到配置中

  1. mkdir -p $HOME/.kube
  2. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  3. sudo chown $(id -u):$(id -g) $HOME/.kube/config

涂抹法兰绒(参考https://github.com/flannel-io/flannel

  1. kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/v0.20.2/Documentation/kube-flannel.yml

现在一切都应该正在运行:

kubectl get pods --all-namespaces

NAMESPACE      NAME                                  READY   STATUS    RESTARTS   AGE
kube-flannel   kube-flannel-ds-mcjmm                 1/1     Running   0          76s
kube-system    coredns-787d4945fb-fb59g              1/1     Running   0          8m8s
kube-system    coredns-787d4945fb-t25tj              1/1     Running   0          8m8s
kube-system    etcd-kube-master                      1/1     Running   0          8m19s
kube-system    kube-apiserver-kube-master            1/1     Running   0          8m19s
kube-system    kube-controller-manager-kube-master   1/1     Running   0          8m19s
kube-system    kube-proxy-2hz29                      1/1     Running   0          8m8s
kube-system    kube-scheduler-kube-master            1/1     Running   0          8m19s

答案3

查看/etc/containerd/config.toml配置文件,查看cri接口是否被禁用,如:disabled_plugins = ["cri"]。查看后发现配置disabled_plugins = ["cri"]被修改为disabled_plugins = [""]。然后重启并重启containerd服务:systemctl restart containerd。

答案4

Kubernetes 在 v1.20 之后不再支持 Docker 作为容器运行时,因此 Kubernetes 最新版本尚未为 Docker 编写支持的 CRI API,我们可以按照以下步骤使用 Mirantis 为 Docker 开发的 CRI 来完成此操作:

从以下 URL 安装 cri-dockerd:

https://github.com/Mirantis/cri-dockerd

git clone https://github.com/Mirantis/cri-dockerd.git

# Run these commands as root
###Install GO###
wget https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x ./installer_linux
./installer_linux
source ~/.bash_profile

cd cri-dockerd
mkdir bin
go build -o bin/cri-dockerd
mkdir -p /usr/local/bin
install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
cp -a packaging/systemd/* /etc/systemd/system
sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
systemctl daemon-reload
systemctl enable cri-docker.service
systemctl enable --now cri-docker.socket

注意:单独安装每个命令,在批量执行时我有时会遇到错误,因为一些命令可能需要-y或yes才能输入

现在使用以下命令启动 kube 管理集群:

kubeadm init --pod-network-cidr=192.168.0.0/16 --cri-socket=unix:///var/run/cri-dockerd.sock 

相关内容