kubelet使用containerd作为CRI

环境准备

cat <

安装containd

# 安装 containerd
## 设置仓库
### 安装所需包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
### 添加 Docker 仓库
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
## 安装 containerd
sudo yum update -y && sudo yum install -y containerd.io
# 配置 containerd
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
# 重启 containerd
sudo systemctl restart containerd

配置kubelet

#修改/usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=containerd.service
Requires=containerd.service

[Service]
ExecStart=/usr/local/bin/kubelet \
  --container-runtime=remote --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock \
  --bootstrap-kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
  --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \
  --config=/etc/kubernetes/kubelet-conf.yml \

Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target

重点是[Unit]中的After和Requires都要是containerd,并且kubelet的启动参数加上--container-runtime=remote --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock

问题:

使用containerd作为CRI后,kubelet启动不成功,报错255,如下所示

systemctl状态.png

使用命令journalctl -xeu kubelet得到以下日志

journalctl日志.png

从上面可以知道kubelet启动失败的原因是连接不上containerd,但是检查发现containerd是正常运行的。

这种错误有可能是k8s版本与containerd的不匹配造成的,但是看网上其他人使用的版本与我的一致,并且正常运行,故可以排除这个可能。

最后发现是containerd的配置问题,因为我用yum安装containerd后忘了覆盖原有的配置,使得kubelet启动失败。解决方法就是删掉原来的配置文件,或者使用命令重新生成一份。

这里可以看下yum安装后的配置文件,根据查阅的资料显示,这里这么配的原因是因为docker需要用到。

#   Copyright 2018-2020 Docker Inc.

#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at

#       http://www.apache.org/licenses/LICENSE-2.0

#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

disabled_plugins = ["cri"]

#root = "/var/lib/containerd"
#state = "/run/containerd"
#subreaper = true
#oom_score = 0

#[grpc]
#  address = "/run/containerd/containerd.sock"
#  uid = 0
#  gid = 0

#[debug]
#  address = "/run/containerd/debug.sock"
#  uid = 0
#  gid = 0
#  level = "info"

关于该问题的其他讨论可以看这里.

你可能感兴趣的:(kubelet使用containerd作为CRI)