栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 系统运维 > 运维 > Linux

一文带你了解containerd方案

Linux 更新时间:发布时间: 百科书网 趣学号
一文带你了解containerd方案 k8s和docker的竞争

2015年6月22日,迫于google、红帽等巨头公司的压力,docker开放了容器运行时的标准,OCI成立。

2015年7月17日,docker捐赠了自己的容器运行时libcontainer,改造后成为了runc。

2016年12月14日,containerd项目从docker engine中正式分离,被捐赠给了CNCF。

2017年10月,docker宣布在企业版中内置k8s,宣告了docker在和k8s的容器化编排竞争中彻底败北。

2022年5月3日,kubernetes v1.24正式发布,彻底结束了对docker的兼容。

k8s开始了容器运行时的去docker化工作,目前k8s官方文档中给出的容器运行时方案主要有三种,第一种是直接使用docker原有的组件containerd、runc并且用nerdctl完全替代docker client的命令,这种方案我们简称为containerd方案、第二种是kubernetes社区提供的一个cri-o方案,这个方案没有containerd成熟、第三种是继续使用docker,但为了满足RCI,需要再增加一个cri-dockerd组件。其中最优解就是containerd方案,因为方案所使用的组件是docker捐赠的containerd和runc,以及实现容器网络的cni插件,由它们组成了一个去docker化的成熟方案。

接下来,我们就要介绍一下,containerd这个方案怎么进行安装。

containerd方案需要安装三个组件,第一个是最上层的containerd,实现了CRI标准,可以被kubelet直接调用。第二个是runc,实现了OCI标准,containerd会调用runc进行容器的创建。第三个是CNI插件,负责容器启动时的网络创建。

containerd方案安装(一键版) 安装nerdctl full包

一键版将所有组件都打进了nerdctl full包中,但相比于下载每一个组件,这种方式更方便,更容易入门,下载地址https://github.com/containerd/nerdctl/releases

[root@k8s ~]# tar Cxvf /usr/local nerdctl-full-0.22.2-linux-amd64.tar 
[root@k8s bin]# systemctl enable containerd
[root@k8s bin]# systemctl start containerd
containerd方案安装(自定义版) 安装containerd

相比于一键版,自定义版中每个组件版本都可以自己选择,如果想要理解containerd方案每个组件的作用可以进行自定义版安装。

从containerd github项目中下载containerd二进制,地址为https://github.com/containerd/containerd/releases

比较大的github项目一般会在assets下提供各种框架已经编译好的二进制文件包供你下载,比较方便的下载方式是,找到符合你架构的压缩包,拷贝链接,然后通过wget直接下载该链接,如果无法通过命令行直接下载,可以通过网页下载,你下载的包可能和我不太一样,但解压后都是一些二进制文件,最后放到指定文件夹下即可。

[root@k8s local]# tar Cxvf /usr/local containerd-1.6.6-linux-amd64.tar
[root@k8s local]# ll /usr/local/bin/
总用量 138836
-rwxr-xr-x. 1 root root 59613072 8月  5 05:53 containerd
-rwxr-xr-x. 1 root root 7389184 8月  5 05:53 containerd-shim
-rwxr-xr-x. 1 root root 9555968 8月  5 05:53 containerd-shim-runc-v1
-rwxr-xr-x. 1 root root 9580544 8月  5 05:53 containerd-shim-runc-v2
-rwxr-xr-x. 1 root root 25743728 8月  5 05:53 containerd-stress
-rwxr-xr-x. 1 root root 30281648 8月  5 05:53 ctr
配置systemd
[root@k8s ~]# wget https://github.com/containerd/containerd/blob/main/containerd.service
[root@k8s ~]# mv containerd.service /usr/lib/systemd/system/containerd.service
[root@k8s ~]# systemctl enable containerd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/containerd.service to /usr/lib/systemd/system/containerd.service.
安装runc

runc二进制下载地址为https://github.com/opencontainers/runc/releases

[root@k8s ~]# install -m 755 runc.amd64 /usr/local/sbin/runc
[root@k8s ~]# ll /usr/local/sbin/
总用量 9204
-rwxr-xr-x. 1 root root 9423264 8月  8 16:35 runc
安装CNI插件

CNI插件二进制下载地址为https://github.com/containernetworking/plugins/releases

[root@k8s ~]# mkdir -p /opt/cni/bin
[root@k8s ~]# tar Cxvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tar
[root@k8s ~]# ll /opt/cni/bin/
总用量 63728
-rwxr-xr-x. 1 root root 3780654 3月 10 01:08 bandwidth
-rwxr-xr-x. 1 root root 4221977 3月 10 01:08 bridge
-rwxr-xr-x. 1 root root 9742834 3月 10 01:08 dhcp
-rwxr-xr-x. 1 root root 4345726 3月 10 01:08 firewall
-rwxr-xr-x. 1 root root 3811793 3月 10 01:08 host-device
-rwxr-xr-x. 1 root root 3241605 3月 10 01:08 host-local
-rwxr-xr-x. 1 root root 3922560 3月 10 01:08 ipvlan
-rwxr-xr-x. 1 root root 3295519 3月 10 01:08 loopback
-rwxr-xr-x. 1 root root 3959868 3月 10 01:08 macvlan
-rwxr-xr-x. 1 root root 3679140 3月 10 01:08 portmap
-rwxr-xr-x. 1 root root 4092460 3月 10 01:08 ptp
-rwxr-xr-x. 1 root root 3484284 3月 10 01:08 sbr
-rwxr-xr-x. 1 root root 2818627 3月 10 01:08 static
-rwxr-xr-x. 1 root root 3379564 3月 10 01:08 tuning
-rwxr-xr-x. 1 root root 3920827 3月 10 01:08 vlan
-rwxr-xr-x. 1 root root 3523475 3月 10 01:08 vrf
安装nerdctl

如果你之前用的是docker客户端,会明显感觉containerd自带的客户端管理工具ctr和k8s自带的crictl都不是那么好用,所以containerd项目也推出了docker客户端的平替nerdctl。

nerdctl二进制下载地址为https://github.com/containerd/nerdctl/releases

[root@k8s ~]# tar Cxvf /usr/local/bin nerdctl-0.22.2-linux-amd64.tar 
[root@k8s ~]# ll /usr/local/bin/
总用量 165980
-rwxr-xr-x. 1 root root 59592416 6月  7 01:34 containerd
-rwxr-xr-x. 1 root root  21562 8月  2 01:53 containerd-rootless-setuptool.sh
-rwxr-xr-x. 1 root root   7032 8月  2 01:53 containerd-rootless.sh
-rwxr-xr-x. 1 root root 7389184 6月  7 01:34 containerd-shim
-rwxr-xr-x. 1 root root 9555968 6月  7 01:34 containerd-shim-runc-v1
-rwxr-xr-x. 1 root root 9580544 6月  7 01:34 containerd-shim-runc-v2
-rwxr-xr-x. 1 root root 25735456 6月  7 01:34 containerd-stress
-rwxr-xr-x. 1 root root 30265088 6月  7 01:34 ctr
-rwxr-xr-x. 1 root root 27807744 8月  2 01:54 nerdctl
nerdctl的使用 命令自动补全
[root@k8s ~]# echo "source <(nerdctl completion bash)" >> /root/.bash_profile
[root@k8s ~]# source /root/.bash_profile
镜像操作 nerdctl pull
[root@k8s ~]# nerdctl pull busybox
docker.io/library/busybox:latest:                                                 resolved       |++++++++++++++++++++++++++++++++++++++| 
index-sha256:ef320ff10026a50cf5f0213d35537ce0041ac1d96e9b7800bafd8bc9eff6c693:    done           |++++++++++++++++++++++++++++++++++++++| 
manifest-sha256:98de1ad411c6d08e50f26f392f3bc6cd65f686469b7c22a85c7b5fb1b820c154: done           |++++++++++++++++++++++++++++++++++++++| 
config-sha256:7a80323521ccd4c2b4b423fa6e38e5cea156600f40cd855e464cc52a321a24dd:   done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:50783e0dfb64b73019e973e7bce2c0d5a882301b781327ca153b876ad758dbd3:    done           |++++++++++++++++++++++++++++++++++++++| 
elapsed: 13.8s                                                                    total:  759.3  (55.0 KiB/s)
nerdctl images
[root@k8s ~]# nerdctl images
REPOSITORY    TAG       IMAGE ID        CREATED          PLATFORM       SIZE       BLOB SIZE
busybox       latest    ef320ff10026    8 minutes ago    linux/amd64    1.2 MiB    759.3 KiB
nerdctl tag
[root@k8s ~]# nerdctl tag docker.io/library/busybox:latest myharbor/busybox:latest
nerdctl push
[root@k8s ~]# nerdctl push myharbor/busybox:latest
nerdctl save
[root@k8s ~]# nerdctl save -o nerdctl_busybox.tar.gz busybox:latest
nerdctl load
[root@k8s ~]# nerdctl load -i nerdctl_busybox.tar.gz
unpacking docker.io/library/busybox:latest (sha256:ef320ff10026a50cf5f0213d35537ce0041ac1d96e9b7800bafd8bc9eff6c693)...done
nerdctl rmi
[root@k8s ~]# nerdctl rmi docker.io/myharbor/busybox:latest
Untagged: docker.io/myharbor/busybox:latest@sha256:ef320ff10026a50cf5f0213d35537ce0041ac1d96e9b7800bafd8bc9eff6c693
Deleted: sha256:084326605ab6715ca698453e530e4d0319d4e402b468894a06affef944b4ef04
容器操作 nerdctl run
[root@k8s ~]# nerdctl run -it busybox sh
nerdctl ps
[root@k8s ~]# nerdctl ps
CONTAINER ID    IMAGE                               COMMAND    CREATED          STATUS    PORTS    NAMES
e5d649613805    docker.io/library/busybox:latest    "sh"       6 seconds ago    Up                 busybox-e5d64
nerdctl stop
[root@k8s ~]# nerdctl stop busybox-e5d64 
busybox-e5d64
nerdctl rm
[root@k8s ~]# nerdctl ps -a
CONTAINER ID    IMAGE                               COMMAND    CREATED          STATUS                         PORTS    NAMES
e5d649613805    docker.io/library/busybox:latest    "sh"       2 minutes ago    Exited (137) 58 seconds ago             busybox-e5d64
[root@k8s ~]# nerdctl rm busybox-e5d64 
busybox-e5d64
nerdctl exec
[root@k8s ~]# nerdctl exec -it nginx-78184 /bin/sh
nerdctl log
[root@k8s ~]# nerdctl logs nginx-78184
转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/1064880.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号