487. 【kubernetes】二进制方式安装-containerd

kubernetes 1.20 版本宣布弃用docker,kubernetes 1.24 版本正式移除docker,本着开发人员对于新技术的探索精神(作死精神),这篇开始基于 kubernetes 1.25 版本搭建集群。想要搭建包含docker版本的kubernetes集群的同学,可以移步文章末尾,查看七镜之前写的相关文章。

一、github中的containerd下载地址

点击下载:containerd-1.6.9-linux-amd64.tar.gz

二、解压安装 containerd

[root@k8s_master k8s]#  tar -zxvf containerd-1.6.9-linux-amd64.tar.gz 
bin/
bin/ctr
bin/containerd
bin/containerd-shim
bin/containerd-stress
bin/containerd-shim-runc-v2
bin/containerd-shim-runc-v1
[root@k8s_master k8s]#  cp bin/* /usr/local/bin/

三、开机自动启动

编辑 service 文件

vim /usr/lib/systemd/system/containerd.service

文件内容如下:

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

[Service]
# uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration
# Environment="ENABLE_CRI_SANDBOXES=sandboxed"
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

启动 containerd:

[root@k8s_master local]#  systemctl daemon-reload
[root@k8s_master local]#  systemctl enable --now containerd
[root@k8s_master local]#  systemctl status containerd
● containerd.service - containerd container runtime
   Loaded: loaded (/usr/lib/systemd/system/containerd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-11-13 05:54:39 PST; 8s ago
     Docs: https://containerd.io
  Process: 4621 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
 Main PID: 4623 (containerd)
    Tasks: 11
   Memory: 19.8M
   CGroup: /system.slice/containerd.service
           └─4623 /usr/local/bin/containerd

Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.278882504-08:00" level=info msg="Start subscribing containerd event"
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.278953951-08:00" level=info msg="Start recovering state"
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.279008746-08:00" level=info msg="Start event monitor"
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.279022071-08:00" level=info msg="Start snapshots syncer"
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.279030108-08:00" level=info msg="Start cni network conf syn...efault"
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.279034770-08:00" level=info msg="Start streaming server"
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.279331034-08:00" level=info msg=serving... address=/run/con...k.ttrpc
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.279373899-08:00" level=info msg=serving... address=/run/con...rd.sock
Nov 13 05:54:39 k8s_master containerd[4623]: time="2022-11-13T05:54:39.279859901-08:00" level=info msg="containerd successfully bo...26879s"
Nov 13 05:54:39 k8s_master systemd[1]: Started containerd container runtime.
Hint: Some lines were ellipsized, use -l to show in full.

可以看已经正常运行了。

四、解压安装 runc

下载地址:runc.amd64
安装命令:install -m 755 runc.amd64 /usr/local/sbin/runc

五、解压安装 cni

下载地址:cni-plugins-linux-amd64-v1.1.1.tgz
安装命令:

[root@k8s_master k8s]#  mkdir -p /opt/cni/bin
[root@k8s_master k8s]#  tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tgz
./
./macvlan
./static
./vlan
./portmap
./host-local
./vrf
./bridge
./tuning
./firewall
./host-device
./sbr
./loopback
./dhcp
./ptp
./ipvlan
./bandwidth

六、解压安装 nerdctl

下载地址:nerdctl-1.0.0-linux-amd64.tar.gz

tar -zxvf nerdctl-1.0.0-linux-amd64.tar.gz
cp nerdctl /usr/bin/

七、containerd 初体验

  1. 下载镜像
ctr images pull docker.io/library/redis:alpine

487. 【kubernetes】二进制方式安装-containerd_第1张图片
2.运行容器(redis实例)

[root@k8s_master k8s]#  nerdctl run -it -p 6379:6379 --name redis redis:alpine
1:C 13 Nov 2022 14:52:23.234 #  oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 13 Nov 2022 14:52:23.234 #  Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 13 Nov 2022 14:52:23.234 #  Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 13 Nov 2022 14:52:23.235 #  You requested maxclients of 10000 requiring at least 10032 max file descriptors.
1:M 13 Nov 2022 14:52:23.235 #  Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 13 Nov 2022 14:52:23.235 #  Current maximum open files is 1024. maxclients has been reduced to 992 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 13 Nov 2022 14:52:23.235 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 7.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

1:M 13 Nov 2022 14:52:23.236 #  WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 13 Nov 2022 14:52:23.236 #  Server initialized
1:M 13 Nov 2022 14:52:23.236 #  WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 13 Nov 2022 14:52:23.236 * Ready to accept connections

487. 【kubernetes】二进制方式安装-containerd_第2张图片
3. 验证
通过redis 客户端连接试试:
487. 【kubernetes】二进制方式安装-containerd_第3张图片

【附加】八、生成自定义配置

mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml

【附加】 九、安装 crictl

安装命令:

VERSION="v1.25.0"
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
rm -f crictl-$VERSION-linux-amd64.tar.gz

修改配置文件:

cat>/etc/crictl.yaml <

安装成功

相关阅读(旧版,k8s version: 1.23.1):
184. 【kubernetes】二进制文件方式安装 Kubernetes 集群(一)
185. 【docker】二进制方式安装 Docker
186. 【kubernetes】二进制文件方式安装 Kubernetes 集群(二)
187. 【kubernetes】二进制文件方式安装 Kubernetes 集群(三)
220. 【kubernetes】二进制文件方式安装 Kubernetes 集群(四)

你可能感兴趣的:(kubernetes,docker,运维)