Ubuntu2204部署容器引擎Containerd

这篇具有很好参考价值的文章主要介绍了Ubuntu2204部署容器引擎Containerd。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

  为什么使用containerd?

  使用containerd的原因主要有两点吧,第一个是docker在k8s1.24以后不再支持,如果需要在k8s中继续使用docker作为容器引擎,我们需要额外部署cri-dockerd;其次即便我们部署cri-dockerd,docker最后也是调用containerd;所以为了减少调用提高性能,我们直接使用containerd是最优选择;

Ubuntu2204部署容器引擎Containerd

  提示:containerd1.0作为k8s容器引擎时它需要额外的一个cri-containerd的插件来实现kubelet和containerd交互,工作逻辑和dockers类似,但比docker要少调用一层;使用docker作为容器引擎,kubelet和containerd交互需要先和dockershim交互,然后对应dockershim再将对应消息传递给docker,然后由docker和containerd交互;很显然使用docker作为容器引擎,调用复杂且性能不高;

Ubuntu2204部署容器引擎Containerd

  提示:containerd1.1以后,对应cri-containerd插件直接内置在containerd中,并默认处于启用状态;与cri-containerd不同,cri插件通过直接函数调用与containerd交互。这种方式使得kubelet和containerd交互更加稳定和高效,中间不再需要专门的cri-containerd插件来传递消息;

  安装containerd的方式通常有两种,一种是apt/yum安装,一种是二进制安装

  apt安装containerd

  验证仓库版本

root@k8s-node02:~# apt-cache madison containerd
containerd | 1.6.12-0ubuntu1~22.04.1 | http://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 Packages
containerd | 1.5.9-0ubuntu3.1 | http://mirrors.aliyun.com/ubuntu jammy-security/main amd64 Packages
containerd | 1.5.9-0ubuntu3 | http://mirrors.aliyun.com/ubuntu jammy/main amd64 Packages
containerd | 1.5.9-0ubuntu3 | http://mirrors.aliyun.com/ubuntu jammy/main Sources
containerd | 1.5.9-0ubuntu3.1 | http://mirrors.aliyun.com/ubuntu jammy-security/main Sources
containerd | 1.6.12-0ubuntu1~22.04.1 | http://mirrors.aliyun.com/ubuntu jammy-updates/main Sources
root@k8s-node02:~# 

  安装containerd

root@k8s-node02:~# apt install containerd=1.6.12-0ubuntu1~22.04.1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  runc
The following NEW packages will be installed:
  containerd runc
0 upgraded, 2 newly installed, 0 to remove and 51 not upgraded.
Need to get 38.6 MB of archives.
After this operation, 145 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

  查看service⽂件

root@k8s-node02:~# cat /usr/lib/systemd/system/containerd.service 
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# 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
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
root@k8s-node02:~# 

  验证runc和containerd环境

root@k8s-node02:~# runc -v
runc version 1.1.4-0ubuntu1~22.04.1
spec: 1.0.2-dev
go: go1.18.1
libseccomp: 2.5.3
root@k8s-node02:~# containerd -v
containerd github.com/containerd/containerd 1.6.12-0ubuntu1~22.04.1 
root@k8s-node02:~# 

  生成containerd配置⽂件

root@k8s-node02:~# containerd --help |grep config
by using this command. If none of the *config*, *publish*, or *help* commands
A default configuration is used if no TOML configuration is specified or located
at the default file location. The *containerd config* command can be used to
generate the default configuration for containerd. The output of that command
can be used and modified as necessary as a custom configuration.
   config    information on the containerd config
   --config value, -c value     path to the configuration file (default: "/etc/containerd/config.toml")
root@k8s-node02:~# mkdir -p /etc/containerd/
root@k8s-node02:~# containerd config default > /etc/containerd/config.toml
root@k8s-node02:~# ll /etc/containerd/config.toml
-rw-r--r-- 1 root root 6994 Apr  9 13:36 /etc/containerd/config.toml
root@k8s-node02:~# 

  启动containerd

root@k8s-node02:~# systemctl start containerd
root@k8s-node02:~# systemctl status containerd
● containerd.service - containerd container runtime
     Loaded: loaded (/lib/systemd/system/containerd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-04-09 13:32:10 UTC; 5min ago
       Docs: https://containerd.io
    Process: 1073 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
   Main PID: 1075 (containerd)
      Tasks: 10
     Memory: 13.7M
        CPU: 2.766s
     CGroup: /system.slice/containerd.service
             └─1075 /usr/bin/containerd

Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.638730092Z" level=info msg=serving... address=/run/containerd/containerd.sock.ttrpc
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.638832460Z" level=info msg=serving... address=/run/containerd/containerd.sock
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.638982310Z" level=info msg="containerd successfully booted in 0.020303s"
Apr 09 13:32:10 k8s-node02.ik8s.cc systemd[1]: Started containerd container runtime.
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.639510934Z" level=info msg="Start subscribing containerd event"
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.639631535Z" level=info msg="Start recovering state"
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.639738452Z" level=info msg="Start event monitor"
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.639821525Z" level=info msg="Start snapshots syncer"
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.639936969Z" level=info msg="Start cni network conf syncer for default"
Apr 09 13:32:10 k8s-node02.ik8s.cc containerd[1075]: time="2023-04-09T13:32:10.640051290Z" level=info msg="Start streaming server"
root@k8s-node02:~# 

  通过命令行测试下载镜像

  containerd的命令⾏客户端有ctr、crictl、nerdctl等,containerd相⽐docker多了⼀个命名空间的逻辑概念,⾃身的命令⾏客户端ctr命令默认是在default命名空间⾥、nerdctl也是在default,当使⽤crictl命令的时候,是在k8s.io这个命名空间,⽽k8s的创建的pod也是在k8s.io命名空间,因此在使⽤nerdctl管理kubernetes环境的pod的时候要指定命名空间为k8s.io,否则看不到kubernetes环境中的pod;
Ubuntu2204部署容器引擎Containerd

  验证镜像

root@k8s-node02:~# ctr images ls
REF                             TYPE                                                      DIGEST                                                                  SIZE    PLATFORMS                                                                                LABELS 
docker.io/library/alpine:latest application/vnd.docker.distribution.manifest.list.v2+json sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126 3.2 MiB linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x -      
root@k8s-node02:~# 

  ctr客户端创建测试容器

root@k8s-node02:~# ctr run -t --net-host docker.io/library/alpine:latest testcontainer sh
/ # ifconfig
ens33     Link encap:Ethernet  HWaddr 00:0C:29:73:67:C2  
          inet addr:192.168.0.75  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe73:67c2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:33342 errors:0 dropped:48 overruns:0 frame:0
          TX packets:22887 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:44009320 (41.9 MiB)  TX bytes:1665243 (1.5 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:42 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4562 (4.4 KiB)  TX bytes:4562 (4.4 KiB)

/ # ^C
/ # exit
root@k8s-node02:~# ctr containers ls
CONTAINER        IMAGE                              RUNTIME                  
testcontainer    docker.io/library/alpine:latest    io.containerd.runc.v2    
root@k8s-node02:~# 

  ⼆进制安装containerd

  下载二进制包

root@k8s-node03:~# wget https://github.com/containerd/containerd/releases/download/v1.6.20/containerd-1.6.20-linux-amd64.tar.gz

  解压二进制包

root@k8s-node03:~# ls
containerd-1.6.20-linux-amd64.tar.gz
root@k8s-node03:~# tar xf containerd-1.6.20-linux-amd64.tar.gz 
root@k8s-node03:~# ls
bin  containerd-1.6.20-linux-amd64.tar.gz
root@k8s-node03:~# 

  复制二进制文件至用户环境变量目录

root@k8s-node03:~# ls
bin  containerd-1.6.20-linux-amd64.tar.gz
root@k8s-node03:~# ls bin
containerd       containerd-shim-runc-v1  containerd-stress
containerd-shim  containerd-shim-runc-v2  ctr
root@k8s-node03:~# cp bin/* /usr/local/bin/
root@k8s-node03:~# 

  验证containerd版本信息

root@k8s-node03:~# containerd -v
containerd github.com/containerd/containerd v1.6.20 2806fc1057397dbaeefbea0e4e17bddfbd388f38
root@k8s-node03:~# 

  准备service文件

root@k8s-node03:~# cat /usr/lib/systemd/system/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# 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
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
root@k8s-node03:~# 

  提示:注意containerd的目录;

  生成配置文件

root@k8s-node03:~# mkdir -p /etc/containerd/
root@k8s-node03:~# containerd config default > /etc/containerd/config.toml
root@k8s-node03:~# ll /etc/containerd/config.toml
-rw-r--r-- 1 root root 6994 Apr  9 14:08 /etc/containerd/config.toml
root@k8s-node03:~# 

  提示:containerd的配置文件默认是/etc/containerd/config.toml;我们可以通过containerd --help|grep config命令得到该信息;

Ubuntu2204部署容器引擎Containerd

  编辑配置文件配置底层pause镜像地址

Ubuntu2204部署容器引擎Containerd

  提示:默认pause镜像地址是registry.k8s.io/pause:3.6,该仓库在google,一般需要借助科学上问工具才能正常访问,所以这里我们换成国内的镜像地址;

  配置镜像加速器

Ubuntu2204部署容器引擎Containerd

  配置systemd驱动器

Ubuntu2204部署容器引擎Containerd

  提示:cgroup是用来对容器的资源做限制的,默认containerd没有开启SystemdCgroup,在systemd初始化的系统上,建议开启;特别注意containerd如果作为k8s集群的容器引擎,这个驱动器需要和kubelet保持一致;否则会出现初始化k8s集群,容器自动重建的现象;

Ubuntu2204部署容器引擎Containerd

  启动containerd并设置为开机启动

root@k8s-node03:~# systemctl start containerd && systemctl enable containerd
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
root@k8s-node03:~# systemctl status containerd
● containerd.service - containerd container runtime
     Loaded: loaded (/lib/systemd/system/containerd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-04-09 14:27:39 UTC; 58s ago
       Docs: https://containerd.io
   Main PID: 34424 (containerd)
      Tasks: 10
     Memory: 13.1M
        CPU: 551ms
     CGroup: /system.slice/containerd.service
             └─34424 /usr/local/bin/containerd

Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.401494614Z" level=info msg="Start subscribing containerd event"
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.401622138Z" level=info msg="Start recovering state"
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.401749630Z" level=info msg="Start event monitor"
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.401832242Z" level=info msg="Start snapshots syncer"
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.401909113Z" level=info msg="Start cni network conf syncer for default"
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.401984359Z" level=info msg="Start streaming server"
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.402288194Z" level=info msg=serving... address=/run/containerd/containerd.sock.ttrpc
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.402424377Z" level=info msg=serving... address=/run/containerd/containerd.sock
Apr 09 14:27:39 k8s-node03.ik8s.cc systemd[1]: Started containerd container runtime.
Apr 09 14:27:39 k8s-node03.ik8s.cc containerd[34424]: time="2023-04-09T14:27:39.403282275Z" level=info msg="containerd successfully booted in 0.032541s"
root@k8s-node03:~# 

  部署runc

root@k8s-node03:~# wget https://github.com/opencontainers/runc/releases/download/v1.1.5/runc.amd64

  给二进制文件添加执行权限,并将其移动至/usr/bin/目录并改名为runc

root@k8s-node03:~# ll
total 52332
drwx------  5 root root     4096 Apr  9 14:35 ./
drwxr-xr-x 19 root root     4096 Apr  9 03:29 ../
-rw-------  1 root root     1363 Apr  9 06:09 .bash_history
-rw-r--r--  1 root root     3106 Oct 15  2021 .bashrc
drwx------  3 root root     4096 Apr  9 03:38 .cache/
-rw-r--r--  1 root root      161 Jul  9  2019 .profile
drwx------  2 root root     4096 Apr  9 05:46 .ssh/
-rw-------  1 root root    12827 Apr  9 14:27 .viminfo
drwxr-xr-x  2 root root     4096 Mar 30 20:51 bin/
-rw-r--r--  1 root root 44102774 Apr  9 13:58 containerd-1.6.20-linux-amd64.tar.gz
-rw-r--r--  1 root root  9431456 Apr  9 12:29 runc.amd64
root@k8s-node03:~# chmod a+x runc.amd64 
root@k8s-node03:~# mv runc.amd64 /usr/bin/runc
root@k8s-node03:~# 

  下载测试镜像并验证

root@k8s-node03:~# ctr images pull docker.io/library/alpine:latest
docker.io/library/alpine:latest:                                                  resolved       |++++++++++++++++++++++++++++++++++++++| 
index-sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126:    done           |++++++++++++++++++++++++++++++++++++++| 
manifest-sha256:b6ca290b6b4cdcca5b3db3ffa338ee0285c11744b4a6abaa9627746ee3291d8d: done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:f56be85fc22e46face30e2c3de3f7fe7c15f8fd7c4e5add29d7f64b87abdaa09:    done           |++++++++++++++++++++++++++++++++++++++| 
config-sha256:9ed4aefc74f6792b5a804d1d146fe4b4a2299147b0f50eaf2b08435d7b38c27e:   done           |++++++++++++++++++++++++++++++++++++++| 
elapsed: 11.3s                                                                    total:  2.0 Mi (181.5 KiB/s)                                     
unpacking linux/amd64 sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126...
done: 121.740597ms
root@k8s-node03:~# ctr images ls
REF                             TYPE                                                      DIGEST                                                                  SIZE    PLATFORMS                                                                                LABELS 
docker.io/library/alpine:latest application/vnd.docker.distribution.manifest.list.v2+json sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126 3.2 MiB linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x -      
root@k8s-node03:~# 

  ctr客户端创建测试容器

root@k8s-node03:~# ctr run -t --net-host docker.io/library/alpine:latest test sh
/ # ifconfig
ens33     Link encap:Ethernet  HWaddr 00:0C:29:EB:68:C7  
          inet addr:192.168.0.76  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feeb:68c7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:150682 errors:0 dropped:98 overruns:0 frame:0
          TX packets:47714 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:204871097 (195.3 MiB)  TX bytes:3518180 (3.3 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:233 errors:0 dropped:0 overruns:0 frame:0
          TX packets:233 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:20170 (19.6 KiB)  TX bytes:20170 (19.6 KiB)

/ # exit
root@k8s-node03:~# ctr containers ls
CONTAINER    IMAGE                              RUNTIME                  
test         docker.io/library/alpine:latest    io.containerd.runc.v2    
root@k8s-node03:~# 

  提示:默认我们不指定名称空间对应容器都运行在default名称空间下;我们可以使用-n选项来指定对应名称空间信息;

Ubuntu2204部署容器引擎Containerd

  containerd客户端⼯具扩展

  crictl客户端工具部署
root@k8s-node03:~# wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.26.1/crictl-v1.26.1-linux-amd64.tar.gz

  解压压缩包并将其移动至用户环境变量目录中去

root@k8s-node03:~# ls
bin  containerd-1.6.20-linux-amd64.tar.gz  crictl-v1.26.1-linux-amd64.tar.gz
root@k8s-node03:~# tar xf crictl-v1.26.1-linux-amd64.tar.gz 
root@k8s-node03:~# ls
bin  containerd-1.6.20-linux-amd64.tar.gz  crictl  crictl-v1.26.1-linux-amd64.tar.gz
root@k8s-node03:~# mv crictl /usr/local/bin/
root@k8s-node03:~# ls /usr/local/bin/
containerd  containerd-shim  containerd-shim-runc-v1  containerd-shim-runc-v2  containerd-stress  crictl  ctr
root@k8s-node03:~# 

  验证crictl是否可正常运行?

root@k8s-node03:~# crictl -v
crictl version v1.26.1
root@k8s-node03:~# 

  查看crictl默认配置文件路径

root@k8s-node03:~# crictl --help |grep config
   config              Get and set crictl client configuration options
   --config value, -c value            Location of the client config file. If not specified and the default does not exist, the program's directory is searched as well (default: "/etc/crictl.yaml") [$CRI_CONFIG_FILE]
root@k8s-node03:~#

  查看containerd sock文件路径

root@k8s-node03:~# cat /etc/containerd/config.toml |grep sock
  address = "/run/containerd/containerd.sock"
root@k8s-node03:~#

  配置crictl运⾏时环境

root@k8s-node03:~# cat /etc/crictl.yaml
runtime-endpoint: "unix:///run/containerd/containerd.sock"
image-endpoint: "unix:///run/containerd/containerd.sock"
timeout: 10
debug: false
root@k8s-node03:~# 

  测试:下载并验证镜像

root@k8s-node03:~# crictl pull nginx:1.20.2
Image is up to date for sha256:50fe74b50e0d0258922495297efbb9ebc3cbd5742103df1ca54dc21c07d24575
root@k8s-node03:~# crictl images
IMAGE                     TAG                 IMAGE ID            SIZE
docker.io/library/nginx   1.20.2              50fe74b50e0d0       56.7MB
root@k8s-node03:~# 

  提示:该工具不是特别好用,用的人相对较少,也不推荐使用;

  nerdctl客户端工具安装
root@k8s-node03:~# wget https://github.com/containerd/nerdctl/releases/download/v1.3.0/nerdctl-1.3.0-linux-amd64.tar.gz

  解压包至/usr/local/bin/

root@k8s-node03:~# ls
bin                                   crictl-v1.26.1-linux-amd64.tar.gz
containerd-1.6.20-linux-amd64.tar.gz  nerdctl-1.3.0-linux-amd64.tar.gz
root@k8s-node03:~# tar xf nerdctl-1.3.0-linux-amd64.tar.gz -C /usr/local/bin/
root@k8s-node03:~# ll /usr/local/bin/nerdctl 
-rwxr-xr-x 1 root root 24920064 Apr  5 12:22 /usr/local/bin/nerdctl*
root@k8s-node03:~# 

  验证nerdctl是否可以正常执行?

root@k8s-node03:~# nerdctl version 
WARN[0000] unable to determine buildctl version: exec: "buildctl": executable file not found in $PATH 
Client:
 Version:       v1.3.0
 OS/Arch:       linux/amd64
 Git commit:    c6ddd63dea9aa438fdb0587c0d3d9ae61a60523e
 buildctl:
  Version:

Server:
 containerd:
  Version:      v1.6.20
  GitCommit:    2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:      1.1.5
  GitCommit:    v1.1.5-0-gf19387a6
root@k8s-node03:~# 

Ubuntu2204部署容器引擎Containerd

  提示:nerdctl工具和crictl一样,默认不指定名称空间就是default名称空间;

  为nerdctl提供一个配置文件来指定默认名称空间

root@k8s-node03:~# cat /etc/nerdctl/nerdctl.toml
namespace = "k8s.io"
debug = false
debug_full = false
insecure_registry = true
root@k8s-node03:~# 

  测试:不指定名称空间,看看对应配置是否生效?

root@k8s-node03:~# nerdctl images
REPOSITORY    TAG       IMAGE ID        CREATED           PLATFORM       SIZE         BLOB SIZE
nginx         1.20.2    03f3cb0afb7b    12 minutes ago    linux/amd64    149.1 MiB    54.1 MiB
nginx         <none>    03f3cb0afb7b    12 minutes ago    linux/amd64    149.1 MiB    54.1 MiB
<none>        <none>    03f3cb0afb7b    12 minutes ago    linux/amd64    149.1 MiB    54.1 MiB
root@k8s-node03:~# 

  提示:可以看到现在我们不指定名称空间,对应就是显示k8s.io名称空间下镜像;说明我们给的配置生效了;

  查看containerd cni插件目录和nerdctl cni插件位置

Ubuntu2204部署容器引擎Containerd

  安装CNI(Container networking interface)

root@k8s-node03:~# wget https://github.com/containernetworking/plugins/releases/download/v1.2.0/cni-plugins-linux-amd64-v1.2.0.tgz

  确认cni插件路径是否存在

root@k8s-node03:~# ll /opt/cni/bin
ls: cannot access '/opt/cni/bin': No such file or directory
root@k8s-node03:~# mkdir -p /opt/cni/bin
root@k8s-node03:~# ll /opt/cni/bin
total 8
drwxr-xr-x 2 root root 4096 Apr  9 15:16 ./
drwxr-xr-x 3 root root 4096 Apr  9 15:16 ../
root@k8s-node03:~# 

  解压二进制包至/opt/cni/bin/目录下

root@k8s-node03:~# tar xf cni-plugins-linux-amd64-v1.2.0.tgz -C /opt/cni/bin/
root@k8s-node03:~# ll /opt/cni/bin/
total 68944
drwxrwxr-x 2 root root     4096 Jan 16 21:42 ./
drwxr-xr-x 3 root root     4096 Apr  9 15:16 ../
-rwxr-xr-x 1 root root  3859475 Jan 16 21:42 bandwidth*
-rwxr-xr-x 1 root root  4299004 Jan 16 21:42 bridge*
-rwxr-xr-x 1 root root 10167415 Jan 16 21:42 dhcp*
-rwxr-xr-x 1 root root  3986082 Jan 16 21:42 dummy*
-rwxr-xr-x 1 root root  4385098 Jan 16 21:42 firewall*
-rwxr-xr-x 1 root root  3870731 Jan 16 21:42 host-device*
-rwxr-xr-x 1 root root  3287319 Jan 16 21:42 host-local*
-rwxr-xr-x 1 root root  3999593 Jan 16 21:42 ipvlan*
-rwxr-xr-x 1 root root  3353028 Jan 16 21:42 loopback*
-rwxr-xr-x 1 root root  4029261 Jan 16 21:42 macvlan*
-rwxr-xr-x 1 root root  3746163 Jan 16 21:42 portmap*
-rwxr-xr-x 1 root root  4161070 Jan 16 21:42 ptp*
-rwxr-xr-x 1 root root  3550152 Jan 16 21:42 sbr*
-rwxr-xr-x 1 root root  2845685 Jan 16 21:42 static*
-rwxr-xr-x 1 root root  3437180 Jan 16 21:42 tuning*
-rwxr-xr-x 1 root root  3993252 Jan 16 21:42 vlan*
-rwxr-xr-x 1 root root  3586502 Jan 16 21:42 vrf*
root@k8s-node03:~# 

  提示:nerdctl在创建容器时,它依赖cni插件来给容器创建网络;

  测试:创建Nginx测试容器并指定端口

root@k8s-node03:~# nerdctl images
REPOSITORY    TAG       IMAGE ID        CREATED              PLATFORM       SIZE         BLOB SIZE
nginx         1.20.2    03f3cb0afb7b    About an hour ago    linux/amd64    149.1 MiB    54.1 MiB
nginx         latest    2ab30d6ac535    50 minutes ago       linux/amd64    149.7 MiB    54.4 MiB
nginx         <none>    03f3cb0afb7b    About an hour ago    linux/amd64    149.1 MiB    54.1 MiB
<none>        <none>    2ab30d6ac535    50 minutes ago       linux/amd64    149.7 MiB    54.4 MiB
<none>        <none>    03f3cb0afb7b    About an hour ago    linux/amd64    149.1 MiB    54.1 MiB
root@k8s-node03:~# nerdctl run -d -p 80:80 nginx 
FATA[0000] failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running hook #0: error running hook: exit status 1, stdout: , stderr: time="2023-04-09T16:11:40Z" level=fatal msg="failed to call cni.Setup: plugin type=\"bridge\" failed (add): failed to locate iptables: exec: \"iptables\": executable file not found in $PATH"
Failed to write to log, write /var/lib/nerdctl/1935db59/containers/k8s.io/bf9d980bbed0d28778a3e0f21ad380df1b712841b6887792ce1fa0f483bf9a7d/oci-hook.createRuntime.log: file already closed: unknown 
root@k8s-node03:~# nerdctl ps -a
CONTAINER ID    IMAGE                             COMMAND                   CREATED          STATUS     PORTS                 NAMES
bf9d980bbed0    docker.io/library/nginx:latest    "/docker-entrypoint.…"    6 seconds ago    Created    0.0.0.0:80->80/tcp    nginx-bf9d9
root@k8s-node03:~# 

  提示:这里容器虽然创建了没有运行,给我们报了一个错,意思就是在path环境变量中没有找到iptables,无法执行iptables命令;解决办法就是安装iptables工具(我这里是最小化安装的ubuntu2204的版本,好多命令都没有);

  安装iptables工具

root@k8s-node03:~# apt-get install iptables -y

  再次运行容器,看看对应容器是否能够正常运行?

root@k8s-node03:~# nerdctl run -d -p 80:80 nginx 
f3c40d58c1b98e90ef37da97b7fa6f5b8e9f44e7e40ba973678d53fef79b723f
root@k8s-node03:~# nerdctl ps -a                 
CONTAINER ID    IMAGE                             COMMAND                   CREATED           STATUS     PORTS                 NAMES
bf9d980bbed0    docker.io/library/nginx:latest    "/docker-entrypoint.…"    57 seconds ago    Created    0.0.0.0:80->80/tcp    nginx-bf9d9
f3c40d58c1b9    docker.io/library/nginx:latest    "/docker-entrypoint.…"    3 seconds ago     Up         0.0.0.0:80->80/tcp    nginx-f3c40
root@k8s-node03:~# 

  提示:安装了iptables工具以后,再次运行容器,对应容器就跑起来了;

  验证:访问对应niginx是否可以正常访问?

Ubuntu2204部署容器引擎Containerd

  提示:可以看到nginx可以正常暴露给容器外部网络访问;

  ok,基于ubuntu2204部署containerd和客户端工具的测试就到此为止;推荐使用nerdctl客户端工具,这个工具的命令和docker非常相似,熟悉docker命令的使用,nerdctl也就不难使用了;文章来源地址https://www.toymoban.com/news/detail-409056.html

到了这里,关于Ubuntu2204部署容器引擎Containerd的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【云原生 | Kubernetes 系列】— 部署K8S 1.28版本集群部署(基于Containerd容器运行)

    主机名 IP地址 备注 k8s-master01 192.168.0.109 master k8s-node1 192.168.0.108 node1 k8s-node2 192.168.0.107 node1 k8s-node3 192.168.0.105 node1 1、主机配置 2、升级内核 3、配置内核转发以及过滤 4、安装ipset ipvsadm,IPVS(IP Virtual Server)是一个用于负载均衡的 Linux 内核模块,它可以用来替代 kube-proxy 默认的

    2024年02月20日
    浏览(85)
  • 基于containerd容器运行时,kubeadmin部署k8s 1.28集群

    centos7u9 序号 主机名 ip地址 CPU 内存 硬盘 1 k8s-master1 192.168.1.200 2C 2G 100G 2 k8s-worker1 192.168.1.201 2C 2G 100G 3 k8s-worker2 192.168.1.202 2C 2G 100G 1.3.1主机名配置 vi /etc/sysconfig/network-scripts/ifcfg-ens33 1.3.3主机名与IP地址解析(hosts) vi /etc/hosts 1.3.4防火墙配置 关闭防火墙firewalld 1.3.5SELINUX配置 修改

    2024年02月01日
    浏览(67)
  • K8s基础2——部署单Master节点K8s集群、切换containerd容器运行时、基本命令

    两种部署方式: kubeadm工具部署 。Kubeadm 是一个K8s 部署工具,提供 kubeadm init 和kubeadm join,用于快速部署 Kubernetes集群。 kubeadm 工具功能: kubeadm init:初始化一个 Master 节点。 kubeadm join:将工作节点加入集群。 kubeadm upgrade:升级 K8s 版本。 kubeadm token:管理 kubeadm join 使用的令

    2024年02月12日
    浏览(54)
  • 《Kubernetes部署篇:Ubuntu20.04基于containerd部署kubernetes1.24.12单master集群》

    如下图所示: 主机名 K8S版本 系统版本 内核版本 IP地址 备注 k8s-master-62 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.62 master节点 k8s-worker-63 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.63 worker节点 k8s-worker-64 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.64 worker节点 说明:分别在对应的

    2023年04月25日
    浏览(51)
  • 【C站首发】全网最新Kubernetes(K8s)1.28版本探秘及部署 基于Containerd容器运行时(100年证书kubeadm)

    序号 操作系统及版本 备注 1 CentOS7u9 需求 CPU 内存 硬盘 角色 主机名 值 8C 8G 1024GB master k8s-master01 值 8C 16G 1024GB worker(node) k8s-worker01 值 8C 16G 1024GB worker(node) k8s-worker02 1.3.1 主机名配置 由于本次使用3台主机完成kubernetes集群部署,其中1台为master节点,名称为k8s-master01;其中2台为wor

    2024年02月08日
    浏览(67)
  • ubuntu server 2204 安装(图解)

    实体机+U盘安装 写给没有安装经验的,所以详细些 1.下载 下载ubuntu镜像 官方: ubuntu server 2.烧录 可以使用rufus烧录镜像 官方: rufus 选择下载的.ios镜像,选择烧录到的U盘,开始,中间如果杀毒软件报警,请放行。 所有都选默认即可,如果烧录的时候提示下载额外组件,请务必

    2024年02月20日
    浏览(38)
  • cuda 安装和卸载 (Ubuntu 2204)

    cuda需要Nvidia显卡或计算卡,AMD或intel显卡不行(但是也有套他们的标准) 就算是亮机卡也可使用,比如GT710这种 建议使用ubuntu来装,因为cuda就是在这个平台上开发的,当然别的linux系统也行 以下操作在ubuntu server 2204、debian12、debian11中都操作过,如果没有安装linux系统,可以

    2024年02月04日
    浏览(38)
  • Ubuntu2204安装pycharm社区版

    最近在学习人工智能相关的知识,比较流行的开源框架对windows操作系统的支持并不太友好,因此把学习测试的环境搭在了Ubuntu2204上。一开始我都是在win10系统中的pycharm上写python代码,然后再上传到Ubuntu2204中运行测试,这么做降低了工作效率。于是试着在Ubuntu2204中安装了社区

    2024年02月01日
    浏览(40)
  • K8S最新版本集群部署(v1.28) + 容器引擎Docker部署(下)

    🔼上一集:K8S最新版本集群部署(v1.28) + 容器引擎Docker部署(上) *️⃣主目录:温故知新专栏 🔽下一集:Kubernetes可视化管理工具Kuboard部署使用及k8s常用命令梳理记录 kubectl 是使用 Kubernetes API 与 Kubernetes 集群的控制面进行通信的命令行工具。详见官网安装步骤 📕下载kube

    2024年02月09日
    浏览(53)
  • K8S最新版本集群部署(v1.28) + 容器引擎Docker部署(上)

    🔼上一集:win11+vmware17+centos7.9环境搭建 *️⃣主目录:温故知新专栏 🔽下一集:K8S最新版本集群部署(v1.28) + 容器引擎Docker部署(下) 之前部署过dolphinscheduler3.1.8,看页面增加了K8S模块,所以想着部署一下K8S,学习一下,而且海豚调度也提供了K8S部署方式,经过一番了解,发现

    2024年02月11日
    浏览(54)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包