当前位置:网站首页>「开源摘星计划」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 473. 火柴拼正方形
- How to use the low code platform of the Internet of things for process management?
- ElastricSearch第二弹之分片原理
- 盘点四种WiFi加密标准:WEP、WPA、WPA2、WPA3
- Elastricearch's fragmentation principle of the second bullet
- Kinsoku jikou desu新浪股票接口变动
- Idea console displays Chinese garbled code
- 打新债有条件吗 打新债安全吗
- How to avoid the "black swan" incident in the gene field: a security war behind a preventive "recall"
- CV background introduction
猜你喜欢

好用的人事管理软件有哪些?人事管理系统软件排名!

Leaders of Hangcheng street, Bao'an District and their delegation visited lianchengfa for investigation

Principles of microcomputer Chapter VIII notes arrangement

TCP/UDP基本原理

Zabbix监控- Aruba AP运行数据

基于SSM实现微博系统

LeetCode 1079. movable-type printing

Helix QAC is updated to 2022.1 and will continue to provide high standard compliance coverage

LeetCode 每日一题——30. 串联所有单词的子串

硬件开发笔记(六): 硬件开发基本流程,制作一个USB转RS232的模块(五):创建USB封装库并关联原理图元器件
随机推荐
JDBC 在性能測試中的應用
官宣.NET 7 预览版5
Principles of microcomputer Chapter 6 notes arrangement
打新债 要求 打新债安全吗
增加双因素认证,不惧密码泄露,更不惧123456
Check four WiFi encryption standards: WEP, WPA, WPA2 and WPA3
打新债有条件吗 打新债安全吗
Uniswap founder: no independent token will be issued for genie, and Genie products will be integrated into the uniswap interface
Interpreting the 2022 agile coaching industry status report
墨天轮访谈 | IvorySQL王志斌—IvorySQL,一个基于PostgreSQL的兼容Oracle的开源数据库
What conditions do you need to meet to fight new debts? Is it safe to fight new debts
FlagAI飞智:AI基础模型开源项目,支持一键调用OPT等模型
How to write a great online user manual in 7 steps
[cloud trends] the four highlights of Huawei cloud store brand new release are here
Leaders of Hangcheng street, Bao'an District and their delegation visited lianchengfa for investigation
GL Studio 5 安装与体验
Advanced network accounting notes (6)
Flagai Feizhi: AI basic model open source project, which supports one click call of OPT and other models
LeetCode 473. 火柴拼正方形
Robust extraction of specific signals with time structure (Part 1)