k8s系列-05-k8s集群搭建方案对比,以及containerd是什么,如何安装_运维


主旨

k8s在使用过程中,有多个部署方案,我们该如何做选择呢,各自更加适用于什么环境呢,为什么k8s中使用的是containerd,他和docker之间有什么关系呢?

集群

可选方案

方案来源

易难度

高可用

部署方式

kubeadm

官方

适中

自定义

容器

kubespray

官方

简单

生产级

容器

kubernetes-the-hard-way

社区

困难

自定义

二进制

可以根据自己的实际需求,自行选择哈,咱们这个k8s系列,主要使用kubespray和kubernetes-the-hard-way这两个方式来延伸。


containerd

官网介绍:

containerd is available as a daemon for Linux and Windows. It manages the complete container lifecycle of its host system, from image transfer and storage to container execution and supervision to low-level storage to network attachments and beyond.

以上内容翻译过来就是:containerd是Linux和Windows的守护程序。它管理其主机系统的完整容器生命周期,从图像传输和存储到容器执行和监督,再到低级存储到网络附件等等。

k8s系列-05-k8s集群搭建方案对比,以及containerd是什么,如何安装_docker_02


containerd是容器虚拟化技术,从docker中剥离出来,形成开放容器接口(OCI)标准的一部分。

Containerd 负责干下面这些事情:

•管理容器的生命周期(从创建容器到销毁容器)
•拉取/推送容器镜像
•存储管理(管理镜像及容器数据的存储)
•调用 runC 运行容器(与 runC 等容器运行时交互)
•管理容器网络接口及网络


注意:Containerd 被设计成嵌入到一个更大的系统中,而不是直接由开发人员或终端用户使用。


我们可以从下面几点来理解为什么需要独立的 containerd:

•继续从整体 docker 引擎中分离出的项目(开源项目的思路)
•可以被 Kubernets CRI 等项目使用(通用化)
•为广泛的行业合作打下基础(就像 runC 一样)


就简单说到这里吧,都是概念性的事儿,都是小问题,理解即可。


安装containerd

首先我们登录github官网上,可以看到截止今日最新版本是1.6.1,咱们这里就根据这个版本来进行安装。

软件获取:公众号“运维家”,后台回复“containerd”,即可获取下载链接,也可以从github上进行下载,不过网速堪忧啊。

[yunweijia@localhost ~]$ mkdir containerd
[yunweijia@localhost ~]$ cd containerd/
# 上传软件包
[yunweijia@localhost containerd]$ ls
cri-containerd-1.6.1-linux-amd64.tar.gz
[yunweijia@localhost containerd]$


解压:

[yunweijia@localhost containerd]$ tar xf cri-containerd-1.6.1-linux-amd64.tar.gz 
[yunweijia@localhost containerd]$ ls
cri-containerd-1.6.1-linux-amd64.tar.gz etc opt usr
[yunweijia@localhost containerd]$


删除一些我们不需要的内容:

[yunweijia@localhost containerd]$ rm -rf opt/


拷贝:

[yunweijia@localhost containerd]$ sudo cp -r etc /
[yunweijia@localhost containerd]$ sudo cp -r usr /


生成默认的配置文件,不知道为啥sudo报错没权限,我直接切换到了root用户进行该操作:

[yunweijia@localhost containerd]$ su root
密码:
[root@localhost containerd]#
[root@localhost containerd]# containerd config default > /etc/containerd/config.toml
[root@localhost containerd]# exit
exit
[yunweijia@localhost containerd]$


开启自启动并重启:

[yunweijia@localhost containerd]$ sudo systemctl enable containerd
Created symlink from /etc/systemd/system/multi-user.target.wants/containerd.service to /etc/systemd/system/containerd.service.
[yunweijia@localhost containerd]$ sudo systemctl restart containerd
[yunweijia@localhost containerd]$
[yunweijia@localhost containerd]$ sudo systemctl status containerd
● containerd.service - containerd container runtime
Loaded: loaded (/etc/systemd/system/containerd.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2022-03-07 11:38:41 CST; 1min 44s ago
Docs: https://containerd.io
Process: 38862 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
Main PID: 38864 (containerd)
Tasks: 8
Memory: 47.3M
CGroup: /system.slice/containerd.service
└─38864 /usr/local/bin/containerd


3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.713543190+08:00" level=error msg="failed to load cni during init, please che...i config"
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.713701928+08:00" level=info msg=serving... address=/run/containerd/containerd.sock.ttrpc
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.713726263+08:00" level=info msg=serving... address=/run/containerd/containerd.sock
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.713760788+08:00" level=info msg="containerd successfully booted in 0.077920s"
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.730233904+08:00" level=info msg="Start subscribing containerd event"
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.730310137+08:00" level=info msg="Start recovering state"
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.730404474+08:00" level=info msg="Start event monitor"
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.730417359+08:00" level=info msg="Start snapshots syncer"
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.730425694+08:00" level=info msg="Start cni network conf syncer for default"
3月 07 11:38:41 localhost.localdomain containerd[38864]: time="2022-03-07T11:38:41.730432477+08:00" level=info msg="Start streaming server"
Hint: Some lines were ellipsized, use -l to show in full.
[yunweijia@localhost containerd]$


至此,搭建完毕,下一篇我们将介绍如何使用containerd。