Containerd 运行时组件

容器运行时(Container Runtime)是 Kubernetes(k8s) 最重要的组件之一,负责管理镜像和容器的生命周期。Kubelet 通过 Container Runtime Interface (CRI) 与容器运行时交互,以管理镜像和容器。

Containerd 不支持 docker API 和 docker CLI,但是可以通过 cri-tool 命令实现类似的功能。

镜像相关功能

Docker

Containerd

显示本地镜像列表docker imagescrictl images
下载镜像docker pullcrictl pull
上传镜像docker push
删除本地镜像docker rmicrictl rmi
查看镜像详情docker inspect IMAGE-IDcrictl inspect IMAGE-ID

容器相关功能

Docker

Containerd

显示容器列表docker pscrictl ps
创建容器docker createcrictl create
启动容器docker startcrictl start
停止容器docker stopcrictl stop
删除容器docker rmcrictl rm
查看容器详情docker inspectcrictl inspect
attachdocker attachcrictl attach
execdocker execcrictl exec
logsdocker logscrictl logs
statsdocker statscrictl stats

POD 相关功能

Docker

Containerd

显示 POD 列表crictl pods
查看 POD 详情crictl inspectp
运行 PODcrictl runp
停止 PODcrictl stopp

调用链区别有哪些?

  • Docker 作为 k8s 容器运行时,调用关系如下:
    kubelet --> docker shim (在 kubelet 进程中) --> dockerd --> containerd
  • Containerd 作为 k8s 容器运行时,调用关系如下:
    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的文件
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐