Kubernetes | 二进制安装Containerd v1.6.6

从官网下载二进制包,解压到 /usr/local 目录。
下载链接:https://github.com/containerd/containerd/releases/download/v1.6.6/containerd-1.6.6-linux-amd64.tar.gz

root@timo:~# tar Cxzvf /usr/local containerd-1.6.6-linux-amd64.tar.gz
bin/
bin/containerd-shim
bin/containerd
bin/containerd-shim-runc-v1
bin/containerd-stress
bin/containerd-shim-runc-v2
bin/ctr
root@timo:~# ls /usr/local/bin/
containerd  containerd-shim  containerd-shim-runc-v1  containerd-shim-runc-v2  containerd-stress  ctr
root@timo:~# 

配置文件没有提供,可以通过命令手动生成。
有两处需要修改。
1、SystemdCgroup = false改为SystemdCgroup = true
2、k8s.gcr.io改为registry.aliyuncs.com/google_containers

root@timo:~# mkdir -p /etc/containerd
root@timo:~# containerd config default > /etc/containerd/config.toml
root@timo:~# sed -i "s#SystemdCgroup = false#SystemdCgroup = true#" /etc/containerd/config.toml
root@timo:~# sed -i "s#k8s.gcr.io#registry.aliyuncs.com/google_containers#" /etc/containerd/config.toml

Service启动文件也没有提供,直接从官网下载。
下载链接:https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

containerd命令是存放在 /usr/local/bin 目录的,如果是在别的路径,需要修改ExecStart参数。

root@timo:~# mv containerd.service /etc/systemd/system/containerd.service 
root@timo:~# cat /etc/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/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@timo:~# 

上面步骤都完成就可以启动containerd了。

root@timo:~# systemctl daemon-reload
root@timo:~# systemctl enable --now containerd
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /etc/systemd/system/containerd.service.
root@timo:~# 
root@timo:~# ss -lnpt | grep containerd 
LISTEN    0         4096             127.0.0.1:38949            0.0.0.0:*        users:(("containerd",pid=5195,fd=18))                                          
root@timo:~# ps -ef | grep containerd
root        5195       1  0 12:39 ?        00:00:00 /usr/local/bin/containerd
root        5298    4480  0 12:39 pts/1    00:00:00 grep --color=auto containerd
root@timo:~# 

containerd提供了个 ctr 命令可以启动容器,启动一个redis容器试试。

root@timo:~# ctr images pull docker.io/library/redis:alpine
docker.io/library/redis:alpine:                                                   resolved       |++++++++++++++++++++++++++++++++++++++| 
index-sha256:5916c280afae05baf0dc9a0cc82fa8e51477bdbfc72f60a5c14fd2b7735bcf07:    done           |++++++++++++++++++++++++++++++++++++++| 
manifest-sha256:58ff33524a6664b35e50c1a243f07096eb05b479dc65e06f3592197353ca10fa: done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:abe61b7e68d2f0e1b0ec8a60132416ee2a6347b65d999622e3fcdf8ef0b099c6:    done           |++++++++++++++++++++++++++++++++++++++| 
config-sha256:f934e82c14d178bda705b7c6363b065f3fc49bcbaf7914c181b117c65c566a1e:   done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:2408cc74d12b6cd092bb8b516ba7d5e290f485d3eb9672efc00f0583730179e8:    done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:e90389148883be3c6500b090644113cf690b528e6f057515568a36bfd0b0d87c:    done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:c6c08b6ea4d56366e32f458bcaeb9933840882cfa4ac9073d0d42649e34d1a16:    done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:a1a4b4673a2365320badae5b96d7638c5901770884781d8695c8378499c72e73:    done           |++++++++++++++++++++++++++++++++++++++| 
layer-sha256:e14aa32bdd63af41851e289cafde7077de5e474d6521ca720bbfae51e29b401d:    done           |++++++++++++++++++++++++++++++++++++++| 
elapsed: 16.1s                                                                    total:  11.3 M (718.9 KiB/s)                                     
unpacking linux/amd64 sha256:5916c280afae05baf0dc9a0cc82fa8e51477bdbfc72f60a5c14fd2b7735bcf07...
done: 9.498455ms        
root@timo:~# ctr run -d docker.io/library/redis:alpine redis
ctr: failed to create shim task: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/containerd/io.containerd.runtime.v2.task/default/redis/log.json: no such file or directory): exec: "runc": executable file not found in $PATH: unknown
root@timo:~# 

直接报错了,报错很明显是缺少 runc,那就下载吧。

containerd在v1.6.4版本以后使用v1.1.2的runc和v1.1.1的cni。

image.png

下载链接:https://github.com/opencontainers/runc/releases/download/v1.1.2/runc.amd64

root@timo:~# install -m 755 runc.amd64 /usr/local/sbin/runc
root@timo:~# ls /usr/local/sbin/runc
/usr/local/sbin/runc
root@timo:~# runc -v
runc version 1.1.2
commit: v1.1.2-0-ga916309f
spec: 1.0.2-dev
go: go1.17.10
libseccomp: 2.5.3
root@timo:~# 

顺便把CNI插件也安装上。
下载链接:https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz

root@timo:~# mkdir -p /opt/cni/bin
root@timo:~# 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
root@timo:~# 

runc安装之后,前面的redis容器再重新启动试试。

root@timo:~# ctr container ls
CONTAINER    IMAGE                             RUNTIME                  
redis        docker.io/library/redis:alpine    io.containerd.runc.v2    
root@timo:~# 
root@timo:~# ctr task start -d redis
root@timo:~# ctr task ls 
TASK     PID     STATUS    
redis    5602    RUNNING
root@timo:~# 

containerd自带的 ctr 命令仅用于调试,建议下载 crictl
下载链接:https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.24.2/crictl-v1.24.2-linux-amd64.tar.gz

root@timo:~# tar xzvf crictl-v1.24.2-linux-amd64.tar.gz
crictl
root@timo:~# install -m 755 crictl /usr/local/bin/crictl
root@timo:~# ls /usr/local/bin/crictl
/usr/local/bin/crictl
root@timo:~# 
root@timo:~# crictl -v
crictl version v1.24.2
root@timo:~# 

生成 crictl 的配置文件,用于连接到containerd。
建议做一下,可以将报错给屏蔽掉。

root@timo:~# crictl images 
WARN[0000] image connect using default endpoints: [unix:///var/run/dockershim.sock unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead. 
ERRO[0000] unable to determine image API version: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or directory" 
IMAGE               TAG                 IMAGE ID            SIZE
root@timo:~# 
root@timo:~# cat > /etc/crictl.yaml <<EOF
> runtime-endpoint: unix:///run/containerd/containerd.sock
> image-endpoint: unix:///run/containerd/containerd.sock
> timeout: 10
> debug: false
> EOF
root@timo:~#
root@timo:~# cat /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
root@timo:~#
root@timo:~# crictl images
IMAGE               TAG                 IMAGE ID            SIZE
root@timo:~# crictl pull busybox 
Image is up to date for sha256:62aedd01bd8520c43d06b09f7a0f67ba9720bdc04631a8242c65ea995f3ecac8
root@timo:~# crictl images 
IMAGE                       TAG                 IMAGE ID            SIZE
docker.io/library/busybox   latest              62aedd01bd852       778kB
root@timo:~# 

温馨提示
containerd-<VERSION>-<OS>-<ARCH>.tar.gz 默认没提供runc和cni插件。
cri-containerd-(cni-)<VERSION>-<OS-<ARCH>.tar.gz 提供了runc和cni插件,但runc的依赖包libseccomp没有安装,有两种方式。
1、下载二进制的runc,替换掉原来的(推荐)。
2、Ubuntu的apt-get或CentOS的yum安装libseccomp。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343

推荐阅读更多精彩内容