当前位置:网站首页>「开源摘星计划」Containerd拉取Harbor中的私有镜像,云原生进阶必备技能
「开源摘星计划」Containerd拉取Harbor中的私有镜像,云原生进阶必备技能
2022-06-23 18:50:00 【51CTO】

【摘要】 配置 Containerd 拉取 harbor 私有仓库中的镜像,打工人必备技能!
本文已参与「开源摘星计划」,欢迎正在阅读的你加入。
活动链接: https://github.com/weopenprojects/WeOpen-Star
前言
在k8s的1.20版本发布之后,对外宣称在1.23.x不再使用doker shim作为默认的底层容器运行时,而是通过Container Runtime Interface(CRI)使用containerd来作为容器运行时, 因此原来在docker中配置的个人仓库环境不再起作用,导致k8s配置pods时拉取镜像失败, 本文将进行演示如何在 containerd 配置从Harbor私有仓库拉取镜像。
环境说明
- 操作系统:CentOS
- Harbor Version:2.3.5
- Containerd Version:1.6.5
- Harbor地址: https://192.168.2.22:443
Containerd使用二进制安装的方式,安装步骤见: https://blog.51cto.com/lidabai/5408290
Harbor使用https证书认证的方式部署的,部署文档见: https://blog.51cto.com/lidabai/5173694
修改containerd配置
配置Harbor私有镜像仓库地址
[[email protected] ~]
# vim /etc/containerd/config.toml
...
version
=
2
...
[plugins]
[plugins.
"io.containerd.grpc.v1.cri"]
[plugins.
"io.containerd.grpc.v1.cri".cni]
...
########################################################配置以下部分:
[plugins.
"io.containerd.grpc.v1.cri".registry]
config_path
=
""
[plugins.
"io.containerd.grpc.v1.cri".registry.auths]
[plugins.
"io.containerd.grpc.v1.cri".registry.headers]
[plugins.
"io.containerd.grpc.v1.cri".registry.mirrors]
[plugins.
"io.containerd.grpc.v1.cri".registry.mirrors.
"docker.io"]
endpoint
= [
"https://kvuwuws2.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com"]
[plugins.
"io.containerd.grpc.v1.cri".registry.mirrors.
"harbor.lidabai"]
#名称
endpoint
= [
"https://192.168.2.22:443"]
#Harbor的Url地址
[plugins.
"io.containerd.grpc.v1.cri".registry.configs]
[plugin.
"io.containerd.grpc.v1.cri".registry.configs.
"harbor.lidabai".tls]
#tle,harbor 证书认证配置
insecure_skip_verify
=
true
#是否跳过证书认证
ca_file
=
"/etc/containerd/harbor/ca.crt"
# CA 证书
cert_file
=
"/etc/containerd/harbor/harbor.crt"
# harbor 证书
key_file
=
"/etc/containerd/harbor/harbor.key"
# harbor 私钥
[plugin.
"io.containerd.grpc.v1.cri".registry.configs.
"harbor.lidabai".auth]
#auth,配置注册表凭据
username
=
"admin"
#Harbor用户名
password
=
"Harbor12345"
#Harbor密码
auth
=
""
identitytoken
=
""
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.

重启containerd.service服务
重新加载载 systemd 的 daemon守护进程并重启containerd.service服务,然后k8s集群节点便可正常从Harbor拉取镜像了。
拉取镜像
虽然上面的方式可以使k8s直接拉取镜像,但是在利用 ctl命令 进行手动拉取镜像此时会报如下错误(巨坑-经过无数次失败测试,原本以为是CA证书签发的harbor证书问题),即使你在config.toml中配置insecure_skip_verify为true也是不行的,可以添加-k参数跳过证书校验。
查看下载的镜像
刚才我们下载镜像时通过-n参数指定了namespace。在查看时也要通过-n指定namespace,否则看不到。

踩坑记录
unexpected status code [manifests 1.28]: 401 Unauthorized
【问题描述】
下载Harbor中的私有镜像时报错:
[[email protected] app]
# ctr -n harbor.lidabai images pull 192.168.2.22:443/lidabai/busybox:1.28 -k
ctr: failed to resolve reference
"192.168.2.22:443/lidabai/busybox:1.28": unexpected status code [manifests
1.28]:
401 Unauthorized
- 1.
- 2.

【原因】401未经授权
【解决】通过-u参数指定Harbor用户名和密码。

x509: certificate signed by unknown authority
【报错描述】在拉取镜像时报出错误:
[[email protected] ~]
# ctr images pull 192.168.2.22:443/library/prepare:v2.5.1
error
=
"failed to do request: Head \"https://192.168.2.22:443/v2/library/prepare/manifests/v2.5.1\": x509: certificate signed by unknown authority"
host
=
"192.168.2.22:443"
ctr: failed to resolve reference
"192.168.2.22:443/library/prepare:v2.5.1": failed to
do request: Head
"https://192.168.2.22:443/v2/library/prepare/manifests/v2.5.1": x509: certificate signed by unknown authority
- 1.
- 2.
- 3.

【解决办法】:
1)通过-k参数跳过证书校验。

2)指定CA证书、Harbor相关证书文件路径。
$ mkdir /etc/containerd/harbor/
#创建证书存放目录
$ scp /app/harbor-cert/{ca.pem,harbor.pem,harbor-key.pem}
192.168.2.41:/etc/containerd/harbor/
$ ctr
-n harbor.lidabai images pull
192.168.2.22:443/library/prepare:v2.5.1 \
--tlscacert /etc/containerd/harbor/ca.pem \
#或ca.crt
--tlscert /etc/containerd/harbor/harbor.pem \
#或harbor.crt
--tlskey /etc/containerd/harbor/harbor-key.pem
#或harbor.key
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
精品文章阅读
Harbor高可用集群设计及部署(实操+视频),基于离线安装方式
Harbor进阶:使用Harbor存储Helm chart
Python实现Harbor私有镜像仓库的垃圾自动化
Harbor jobservice组件异常问题处理
Harbor高可用设计: 使用外部Redis缓存部分
如何将dockerhub上的镜像迁移到Harbor私有镜像仓库中?
边栏推荐
猜你喜欢

宝安区航城街道领导一行莅临联诚发参观调研

LeetCode 1079. 活字印刷

Zabbix监控- Aruba AP运行数据

Ready to migrate to the cloud? Please accept this list of migration steps

函數的定義和函數的參數

Hardware development notes (6): basic process of hardware development, making a USB to RS232 module (5): creating USB package library and associating principle graphic devices

The golden nine silver ten, depends on this detail, the offer obtains the soft hand!

TCP/UDP基本原理

为什么你的数据图谱分析图上只显示一个值?

解读2022年度敏捷教练行业现状报告
随机推荐
UST 崩盘后,稳定币市场格局将迎来新机遇?
Application of JDBC in performance test
Advanced network accounting notes (III)
vs2022scanf函数的使用,使用scanf的报错-返回值被忽略:解决·方法
Elastricearch's fragmentation principle of the second bullet
Leetcode daily question - 30 Concatenate substrings of all words
Is it safe to make new debt
How to avoid the "black swan" incident in the gene field: a security war behind a preventive "recall"
Helix QAC更新至2022.1版本,将持续提供高标准合规覆盖率
Principles of microcomputer Chapter 5 notes arrangement
Design of hardware switch with programmable full function rate limiter
盘点四种WiFi加密标准:WEP、WPA、WPA2、WPA3
TCP/UDP基本原理
CV image classification
Matrix analysis notes (III-1)
JDBC 在性能测试中的应用
Is it safe to pay new debts
[comparative learning] koa JS, gin and asp Net core - Middleware
[cloud trends] the four highlights of Huawei cloud store brand new release are here
Programmable data plane (paper reading)