Kubernetes 官方發佈公告,宣佈自 v1.20 起放棄對 Docker 的支持。目前,Kubelet 中的 Docker 支持功能現已棄用,並將在以後的版本中被刪除。linux
再來看下面這張圖(來源網絡)nginx
從上圖中能夠看出 docker 對容器的管理和操做基本都是經過 containerd 完成的。因此,若是你們想從 docker 遷移出來,那麼 Containerd 是一個很是不錯的先擇。git
今天,民工哥就和你們來聊一聊這個開源技術 Containerd。github
很早以前的 Docker Engine 中就有了containerd,只不過如今是將 containerd 從 Docker Engine 裏分離出來,做爲一個獨立的開源項目,目標是提供一個更加開放、穩定的容器運行基礎設施。分離出來的 containerd 將具備更多的功能,涵蓋整個容器運行時管理的全部需求,提供更強大的支持。golang
簡單的來講,containerd 是一個工業級標準的容器運行時,它強調簡單性、健壯性和可移植性。containerd能夠在宿主機中管理完整的容器生命週期,包括容器鏡像的傳輸和存儲、容器的執行和管理、存儲和網絡等。docker
地址:https://github.com/containerd...json
其中,grpc 模塊向上層提供服務接口,metrics 則提供監控數據(cgroup 相關數據),二者均向上層提供服務。containerd 包含一個守護進程,該進程經過本地 UNIX 套接字暴露 grpc 接口。vim
storage 部分負責鏡像的存儲、管理、拉取等 metadata 管理容器及鏡像的元數據,經過bootio存儲在磁盤上 task -- 管理容器的邏輯結構,與 low-level 交互 event -- 對容器操做的事件,上層經過訂閱能夠知道發生了什麼事情 Runtimes -- low-level runtime(對接 runc)centos
從 k8s 的角度看,選擇 containerd做爲運行時的組件,它調用鏈更短,組件更少,更穩定,佔用節點資源更少。網絡
上圖來源 containerd官方網站,containerd可用做 Linux 和 Windows 的守護程序。它管理其主機系統的完整容器生命週期,從圖像傳輸和存儲到容器執行和監督,再到低級存儲到網絡附件等等。
下載地址:https://containerd.io/downloads/
[root@centos7 ~]# wget https://github.com/containerd/containerd/releases/download/v1.5.2/containerd-1.5.2-linux-amd64.tar.gz [root@centos7 ~]# tar zxf containerd-1.5.2-linux-amd64.tar.gz -C /usr/local/ #經過上面的操做,將containerd 安裝至/usr/local/bin目錄下 [root@centos7 ~]# cd /usr/local/bin/ [root@centos7 bin]# ll total 98068 -rwxr-xr-x 1 root root 214432 Mar 29 05:20 bpytop -rwxr-xr-x 1 1001 116 49049696 May 19 12:56 containerd -rwxr-xr-x 1 1001 116 6434816 May 19 12:56 containerd-shim -rwxr-xr-x 1 1001 116 8671232 May 19 12:57 containerd-shim-runc-v1 -rwxr-xr-x 1 1001 116 8683520 May 19 12:57 containerd-shim-runc-v2 -rwxr-xr-x 1 1001 116 27230976 May 19 12:56 ctr lrwxrwxrwx 1 root root 6 Mar 28 00:13 nc -> netcat -rwxr-xr-x 1 root root 126800 Mar 28 00:13 netcat
生成默認配置文件
[root@centos7 bin]# containerd config default > /etc/containerd/config.toml [root@centos7 bin]# ll /etc/containerd/config.toml -rw-r--r-- 1 root root 6069 Jun 4 14:47 /etc/containerd/config.toml
配置 containerd 做爲服務運行
[root@centos7 ~]# touch /lib/systemd/system/containerd.service [root@centos7 bin]# vim /lib/systemd/system/containerd.service [Unit] Description=containerd container runtime Documentation=https://containerd.io After=network.target [Service] ExecStartPre=/sbin/modprobe overlay ExecStart=/usr/local/bin/containerd Delegate=yes KillMode=process LimitNOFILE=1048576 # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNPROC=infinity LimitCORE=infinity [Install] WantedBy=multi-user.target
啓動服務
[root@centos7 ~]# systemctl daemon-reload [root@centos7 ~]# systemctl start containerd.service [root@centos7 ~]# systemctl status containerd.service
其實,史上最輕量 Kubernetes 發行版 K3s 默認就包括了 containerd、Flannel、CoreDNS 組件。
[root@centos7 ~]# ctr version Client: Version: v1.5.2 Revision: 36cc874494a56a253cd181a1a685b44b58a2e34a Go version: go1.16.4 Server: Version: v1.5.2 Revision: 36cc874494a56a253cd181a1a685b44b58a2e34a UUID: ebe42dac-40ae-4af1-99b0-52e61728c918
幫助信息
[root@centos7 ~]# ctr --help NAME: ctr - __ _____/ /______ / ___/ __/ ___/ / /__/ /_/ / \___/\__/_/ containerd CLI USAGE: ctr [global options] command [command options] [arguments...] VERSION: v1.5.2 DESCRIPTION: ctr is an unsupported debug and administrative client for interacting with the containerd daemon. Because it is unsupported, the commands, options, and operations are not guaranteed to be backward compatible or stable from release to release of the containerd project. COMMANDS: plugins, plugin provides information about containerd plugins version print the client and server versions containers, c, container manage containers content manage content events, event display containerd events images, image, i manage images leases manage leases namespaces, namespace, ns manage namespaces pprof provide golang pprof outputs for containerd run run a container snapshots, snapshot manage snapshots tasks, t, task manage tasks install install a new package oci OCI tools shim interact with a shim directly help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --debug enable debug output in logs --address value, -a value address for containerd's GRPC server (default: "/run/containerd/containerd.sock") [$CONTAINERD_ADDRESS] --timeout value total timeout for ctr commands (default: 0s) --connect-timeout value timeout for connecting to containerd (default: 0s) --namespace value, -n value namespace to use with commands (default: "default") [$CONTAINERD_NAMESPACE] --help, -h show help --version, -v print the version
查看與刪除
[root@centos7 ~]# ctr container list CONTAINER IMAGE RUNTIME nginx docker.io/library/nginx:alpine io.containerd.runc.v2 [root@centos7 ~]# ctr container del nginx [root@centos7 ~]# ctr container list CONTAINER IMAGE RUNTIME
pull鏡像文件
[root@centos7 ~]# ctr images pull docker.io/library/nginx:alpine
查看鏡像文件列表
[root@centos7 ~]# ctr images list REF TYPE DIGEST SIZE PLATFORMS LABELS docker.io/library/nginx:alpine application/vnd.docker.distribution.manifest.list.v2+json sha256:0f8595aa040ec107821e0409a1dd3f7a5e989501d5c8d5b5ca1f955f33ac81a0 9.4 MiB linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x -
運行容器
[root@centos7 ~]# ctr run -d docker.io/library/nginx:alpine nginx [root@centos7 ~]# ctr container list CONTAINER IMAGE RUNTIME nginx docker.io/library/nginx:alpine io.containerd.runc.v2
一圈使用下來,基本上與docker的命令相差無幾,使用上沒有什麼大的學習成本,因此,不管是 Kubernetes 是否支持 docker,對於咱們使用者來說,問題不大。
更多相關的介紹與實際操做指南,你們能夠參閱官方文檔,都有詳細的使用說明。