Containerd 运行时组件
容器运行时(Container Runtime)是 Kubernetes(k8s) 最重要的组件之一,负责管理镜像和容器的生命周期。Kubelet 通过 Container Runtime Interface (CRI)
与容器运行时交互,以管理镜像和容器。
Containerd 不支持 docker API 和 docker CLI,但是可以通过 cri-tool 命令实现类似的功能。
镜像相关功能 | Docker | Containerd |
---|---|---|
显示本地镜像列表 | docker images | crictl images |
下载镜像 | docker pull | crictl pull |
上传镜像 | docker push | 无 |
删除本地镜像 | docker rmi | crictl rmi |
查看镜像详情 | docker inspect IMAGE-ID | crictl inspect IMAGE-ID |
容器相关功能 | Docker | Containerd |
---|---|---|
显示容器列表 | docker ps | crictl ps |
创建容器 | docker create | crictl create |
启动容器 | docker start | crictl start |
停止容器 | docker stop | crictl stop |
删除容器 | docker rm | crictl rm |
查看容器详情 | docker inspect | crictl inspect |
attach | docker attach | crictl attach |
exec | docker exec | crictl exec |
logs | docker logs | crictl logs |
stats | docker stats | crictl stats |
POD 相关功能 | Docker | Containerd |
---|---|---|
显示 POD 列表 | 无 | crictl pods |
查看 POD 详情 | 无 | crictl inspectp |
运行 POD | 无 | crictl runp |
停止 POD | 无 | crictl stopp |
kubelet --> docker shim (在 kubelet 进程中) --> dockerd --> containerd
kubelet --> cri plugin(在 containerd 进程中) --> containerd
k8s 将运行时docker 修改为containerd
(1)将节点标记为维护模式,并驱逐所有容器
kubectl cordon <node-name>
kubectl drain <node-name> --ignore-daemonsets
(2)关闭服务
systemctl stop kubelet
systemctl stop docker
apt purge docker-ce docker-ce-cli
(3)创建默认config.toml 文件
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
(4)kubelet参数文件,修改运行时docker为containerd
vi /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
(5)重启服务
systemctl daemon-reload systemctl restart containerd systemctl restart kubelet (6)验证 kubectl get node <nodename> -o wide
container-runtime 已经变为containerd. Containerd 配置文件 containerd-config.toml
下面是一个完整的config.toml 的默认配置文件实例
root = "/var/lib/containerd" state = "/run/containerd" oom_score = 0 imports = ["/etc/containerd/runtime_*.toml", "./debug.toml"] [grpc] address = "/run/containerd/containerd.sock" uid = 0 gid = 0 [debug] address = "/run/containerd/debug.sock" uid = 0 gid = 0 level = "info" [metrics] address = "" grpc_histogram = false [cgroup] path = "" [plugins] [plugins.cgroups] no_prometheus = false [plugins.diff] default = ["walking"] [plugins.linux] shim = "containerd-shim" runtime = "runc" runtime_root = "" no_shim = false shim_debug = false [plugins.scheduler] pause_threshold = 0.02 deletion_threshold = 0 mutation_threshold = 100 schedule_delay = 0 startup_delay = "100ms" 附
find . -type f -size +1024M 查找大文件大于1024M的文件