containerd配置HTTP私仓

本文涉及的产品
性能测试 PTS,5000VUM额度
函数计算FC,每月15万CU 3个月
容器镜像服务 ACR,镜像仓库100个 不限时长
简介: 在240个字符内,以下是摘要:在Ubuntu 22.04上,配置K8S基础环境后,安装Docker并设置镜像加速,接着部署私有的Harbor仓库(HTTP访问)。要将镜像推送到Harbor,需编辑Docker的`daemon.json`加入不安全注册表,然后重启服务。通过`docker login`、`docker tag`和`docker push`推送到Harbor。此外,配置`containerd`以信任Harbor的HTTP地址,更新`/etc/containerd/certs.d/`,重启服务后,使用`ctr`拉取和推送镜像至Harbor。

1. 🛠️ 基础环境配置

📌 安装基础环境请参考:
[Ubuntu 22.04] 安装K8S基础环境准备脚本

2. 🐳 Docker安装

📌 docker安装请参考:
[Ubuntu 22.04] 安装docker,并设置镜像加速

3. 🚢 部署Harbor,HTTP访问

📌 [Ubuntu 22.04] 安装Harbor#HTTP方式

🔍 浏览器中输入:http://192.168.11.20,即可访问刚才部署的harbor

4. 📦 部署ContainerD

📌 containerd的安装请参考:
[[Ubuntu 22.04] 安装containerd]

5. 🔄 修改docker配置文件,向harbor中推入镜像

🎯 目标:向第三步部署的harbor仓库中推入镜像仓库

根据目前的环境,有两种方式可以向harbor中推入镜像。其一是通过dockerharbor中推入镜像仓库。其二是通过containerdharbor中推入镜像

由于目前我们对于containerd并不熟悉,因此我们先直接通过dockerharbor中推入镜像,由于我们自己搭建的harbor是私有仓库,并且是HTTP的方式,因此我们需要配置docker的配置文件。

你可以重新找一台机器安装docker做实验,或者直接使用harbor那台机器也可以,这里我直接使用harbor那台机器上的docker工具,向harbor推送镜像。

配置修改如下,主要是增加了insecure-registries配置,如果你的配置文件中包含其它的配置,请不要直接执行,否则会覆盖你的配置。;另外,请一定要注意80端口,这个不能省略,否则docker会以https的方式访问harbor

tee /etc/docker/daemon.json << 'EOF'
{
    "registry-mirrors": [
        "http://hub-mirror.c.163.com",
        "https://mirror.baidubce.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com",
        "https://dockerproxy.com",
        "https://ccr.ccs.tencentyun.com",
        "https://registry.cn-hangzhou.aliyuncs.com"
    ],
    "insecure-registries": ["192.168.11.20:80"]
}
EOF

systemctl restart docker.service

这里我随便推送harbor的一个镜像到我自己的harbor仓库当中,操作如下,第一步:重新打tag, 第二步:docker push这里需要注意的是,再推送镜像之前,一定要在登录harbor,提前建立仓库目录,否则推送会被拒绝,另外,静态的Tag所指向的仓库端口必须要显式指定80端口,否则默认使用443端口

root@harbor-http:~/harbor#
root@harbor-http:~/harbor#
root@harbor-http:~/harbor# cat /etc/docker/daemon.json
{
    "registry-mirrors": [
        "http://hub-mirror.c.163.com",
        "https://mirror.baidubce.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com",
        "https://dockerproxy.com",
        "https://ccr.ccs.tencentyun.com",
        "https://registry.cn-hangzhou.aliyuncs.com"
    ],
    "insecure-registries": ["192.168.11.20:80","192.168.11.30"]
}
root@harbor-http:~/harbor# docker images
REPOSITORY                    TAG       IMAGE ID       CREATED        SIZE
goharbor/redis-photon         v2.8.2    6f4498a430ca   7 weeks ago    121MB
goharbor/harbor-registryctl   v2.8.2    fa61a236a6d6   7 weeks ago    142MB
goharbor/registry-photon      v2.8.2    f80e71363231   7 weeks ago    79.3MB
goharbor/nginx-photon         v2.8.2    3d009028f260   7 weeks ago    120MB
goharbor/harbor-log           v2.8.2    2914d282d9bf   7 weeks ago    127MB
goharbor/harbor-jobservice    v2.8.2    40118f1568a8   7 weeks ago    141MB
goharbor/harbor-core          v2.8.2    0bbbd1f379fc   7 weeks ago    165MB
goharbor/harbor-portal        v2.8.2    3e74e0758aa4   7 weeks ago    127MB
goharbor/harbor-db            v2.8.2    5126635ae9f0   7 weeks ago    174MB
goharbor/prepare              v2.8.2    eb3cf3cdd17a   7 weeks ago    163MB
hello-world                   latest    9c7a54a9a43c   2 months ago   13.3kB
root@harbor-http:~/harbor#
root@harbor-http:~/harbor# docker tag goharbor/harbor-core:v2.8.2 192.168.11.20:80/goharbor/harbor-core:v2.8.2
root@harbor-http:~/harbor#
root@harbor-http:~/harbor# docker login -u admin -p harbor666 192.168.11.20:80
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
root@harbor-http:~/harbor#
root@harbor-http:~/harbor# docker push 192.168.11.20:80/goharbor/harbor-core:v2.8.2
The push refers to repository [192.168.11.20:80/goharbor/harbor-core]
c8ec2ddada08: Pushed
e1c4f1102d2f: Pushed
17583ba2a843: Pushed
0a049ad6bb06: Pushed
557ccce847e1: Pushed
9cb5dd968a55: Pushed
06d8a79a810a: Pushed
88edeb5b4944: Pushed
c00acf6f4f58: Pushed
21e7914e06fb: Pushed
v2.8.2: digest: sha256:654efa193924544a680f1cc7aaadb8d9fb4e1dcaa8c84a74c71b7fe861973838 size: 2411
root@harbor-http:~/harbor#
root@harbor-http:~/harbor# docker images
REPOSITORY                              TAG       IMAGE ID       CREATED        SIZE
goharbor/redis-photon                   v2.8.2    6f4498a430ca   7 weeks ago    121MB
goharbor/harbor-registryctl             v2.8.2    fa61a236a6d6   7 weeks ago    142MB
goharbor/registry-photon                v2.8.2    f80e71363231   7 weeks ago    79.3MB
goharbor/nginx-photon                   v2.8.2    3d009028f260   7 weeks ago    120MB
goharbor/harbor-log                     v2.8.2    2914d282d9bf   7 weeks ago    127MB
goharbor/harbor-jobservice              v2.8.2    40118f1568a8   7 weeks ago    141MB
192.168.11.20:80/goharbor/harbor-core   v2.8.2    0bbbd1f379fc   7 weeks ago    165MB
goharbor/harbor-core                    v2.8.2    0bbbd1f379fc   7 weeks ago    165MB
goharbor/harbor-portal                  v2.8.2    3e74e0758aa4   7 weeks ago    127MB
goharbor/harbor-db                      v2.8.2    5126635ae9f0   7 weeks ago    174MB
goharbor/prepare                        v2.8.2    eb3cf3cdd17a   7 weeks ago    163MB
hello-world                             latest    9c7a54a9a43c   2 months ago   13.3kB
root@harbor-http:~/harbor#

6. 配置containerd

mkdir -p /etc/containerd/certs.d/192.168.11.20:80
tee /etc/containerd/certs.d/192.168.11.20:80/hosts.toml << 'EOF'
server = "http://192.168.11.20:80"

[host."http://192.168.11.20:80"]
  capabilities = ["pull", "resolve", "push"]
  skip_verify = true
EOF

systemctl restart containerd.service

6.1. 拉取镜像验证

执行:ctr image pull --plain-http=true 192.168.11.20:80/goharbor/harbor-core:v2.8.2

root@containerd:~#
root@containerd:~# ctr image ls -q
docker.io/library/redis:alpine
root@containerd:~# cat /etc/containerd/certs.d/192.168.11.20\:80/hosts.toml
server = "http://192.168.11.20:80"

[host."http://192.168.11.20:80"]
  capabilities = ["pull", "resolve", "push"]
  skip_verify = true
root@containerd:~#
root@containerd:~#
root@containerd:~# ctr image pull --plain-http=true  192.168.11.20:80/goharbor/harbor-core:v2.8.2
192.168.11.20:80/goharbor/harbor-core:v2.8.2:                                     resolved       |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:654efa193924544a680f1cc7aaadb8d9fb4e1dcaa8c84a74c71b7fe861973838: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:aea1be403dd1c4dce59794761f350e4706eb70771631535689e2b06a0a241001:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:548383ab94bf8b81b55cabf36298e0b14cca610a07a1ebd5bba013fa61ffab96:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:06212d50621c9654d97e7ec78e972b5017e139b11763375ee4c28bace1fcc087:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:cf14510ec51c323f283e583a5aabfa33337680e953b07d83162a6c5b5d72defc:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:b6c3d89688aed77dcbea624088f7613ac0923ca1f0398c42f0c79503a03baed6:    done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:0bbbd1f379fc1f577c5db15c9deac4a218637e4af0196d97e6771f59d9815355:   done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:b3381433ebd4d04b664639ab510a6659fec0268dc222de8fb085da676f017cb4:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:b70a76c262e454573e9550cb64962b84a338d78d6f1db4ee9464cce0a8a47dcd:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:378fedafb8051764d80ec29260e7bf3101aabe84b72b23c5829deb2a445391a8:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:f9cd03857d3ab614d97d896de3496a66dffaf4cf5b2051cda730d028d6def94e:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:a3c670ddffbdf7be0c56baae8213258ee6cf339929c86b29905dd11808c80a34:    done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 0.5 s                                                                    total:  47.1 M (94.2 MiB/s)
unpacking linux/amd64 sha256:654efa193924544a680f1cc7aaadb8d9fb4e1dcaa8c84a74c71b7fe861973838...
done: 1.256989921s
root@containerd:~#
root@containerd:~#
root@containerd:~# ctr image ls -q
192.168.11.20:80/goharbor/harbor-core:v2.8.2
docker.io/library/redis:alpine
root@containerd:~#

6.2. 推送镜像验证

执行:ctr image push --plain-http=true -u admin:harbor666 192.168.11.20:80/goharbor/harbor-core:v2.8.3

root@containerd:~#
root@containerd:~# ctr image ls -q
192.168.11.20:80/goharbor/harbor-core:v2.8.2
docker.io/library/redis:alpine
root@containerd:~#
root@containerd:~# ctr image tag  192.168.11.20:80/goharbor/harbor-core:v2.8.2 192.168.11.20:80/goharbor/harbor-core:v2.8.3
192.168.11.20:80/goharbor/harbor-core:v2.8.3
root@containerd:~# ctr image ls -q
192.168.11.20:80/goharbor/harbor-core:v2.8.2
192.168.11.20:80/goharbor/harbor-core:v2.8.3
docker.io/library/redis:alpine
root@containerd:~#
root@containerd:~# ctr image push --plain-http=true -u admin:harbor666  192.168.11.20:80/goharbor/harbor-core:v2.8.3
manifest-sha256:654efa193924544a680f1cc7aaadb8d9fb4e1dcaa8c84a74c71b7fe861973838: done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:0bbbd1f379fc1f577c5db15c9deac4a218637e4af0196d97e6771f59d9815355:   done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 0.2 s                                                                    total:  7.7 Ki (38.4 KiB/s)
root@containerd:~#
root@containerd:~#

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
5月前
|
网络协议
windows_server2012搭建iis并配置http重定向 iis转发
windows_server2012搭建iis并配置http重定向 iis转发
317 1
|
3月前
|
XML 安全 Android开发
Flutter配置Android和IOS允许http访问
Flutter配置Android和IOS允许http访问
117 3
|
4月前
|
存储 运维 监控
函数计算产品使用问题之如何在控制台配置HTTP触发器并使用HTTP请求触发
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
|
4月前
|
网络协议 应用服务中间件 nginx
Nginx的http块sendfile,keepalive_timeout的配置指令说明
Nginx的http块sendfile,keepalive_timeout的配置指令说明
|
5月前
|
Java 应用服务中间件 Apache
Apache HTTP配置反向代理入门
Apache HTTP配置反向代理入门
421 0
Apache HTTP配置反向代理入门
|
5月前
|
XML Web App开发 JSON
HTTP代理神器Fiddler的配置
HTTP代理神器Fiddler的配置
|
5月前
|
Windows
iis配置http重定向302转发get请求并去掉最后的斜杠/ iis重定向 iis去除url最后的斜杠 iis重定向链接斜杠(已解决)
iis配置http重定向302转发get请求并去掉最后的斜杠/ iis重定向 iis去除url最后的斜杠 iis重定向链接斜杠(已解决)
161 0
|
6月前
|
网络协议 Java 应用服务中间件
HTTP协议与Tomcat在IJ中配置
本文是对自己学习JavaWeb学习的笔记的总结,添加了一些自己的东西,然后进行一次复盘,并加深一下学习的理解和印象.其中内容主要包括对http协议的详细介绍,java常见服务器的初步介绍,以及IJ旧版和新版的tomcat服务器的配置图解教程
|
6月前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
171 1
|
Web App开发 新零售 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
1.尽可能地了解需求,系统层面适用开闭原则 2.模块化,低耦合,能快速响应变化,也可以避免一个子系统的问题波及整个大系统 3.
750 0