k8s 使用 containerd 运行时配置 http 私服

简介

Kubernetes 从 v1.20 开始弃用 Docker,并推荐用户切换到基于容器运行时接口(CRI)的容器引擎,如 containerd、cri-o 等。

目前使用的环境中使用了 Kubernetes v1.22.3,containerd 1.4.3,containerd 在配置私服配置上与直接使用 docker 有一定区别。

今天简单聊一下如何配置私服,默认使用 dockerhub 官方镜像 registry:v2harbor 配置的私服为 http,未做配置时 k8s 拉镜像时会以 https 协议访问。

假定已创建好的私服地址为 http://10.211.55.2:5000,进行如下修改

编辑 worker 节点上 /etc/containerd/config.toml,查找plugins."io.containerd.grpc.v1.cri".registry.mirrors配置

相关配置中调整为如下内容

bash 复制代码
[plugins."io.containerd.grpc.v1.cri".registry]
      [plugins."io.containerd.grpc.v1.cri".registry.auths]
      [plugins."io.containerd.grpc.v1.cri".registry.configs]
        [plugins."io.containerd.grpc.v1.cri".registry.configs."k8s-harbor:10001".tls]
          insecure_skip_verify = true
      [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."k8s-harbor:10001"]
          endpoint = ["http://k8s-harbor:10001"]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
          endpoint = ["https://registry.cn-hangzhou.aliyuncs.com"]

参考 [plugins."io.containerd.grpc.v1.cri".registry.mirrors."10.211.55.2:5000"] 行添加私服配置,使用该配置可以直接配置相关 endpoint 为 http 地址。

重启 containerd,使配置生效

bash 复制代码
systemctl restart containerd

这时候,使用 crictl pull 命令就可以获取 http 协议私服上的镜像了。

但是使用ctr命令还是不行,原因:

ctr does not read the /etc/containerd/config.toml config file, this config is used by cri, which means kubectl or crictl would use it.

ctr命令拉取http格式的镜像地址方式:

bash 复制代码
$. ctr image pull --plain-http <image>
# eg: 
$. ctr i pull --plain-http k8s-harbor:10001/my-project/spring-boot-k8s:0.0.1-SNAPSHOT

k8s 使用 containerd 运行时配置 http 私服 - 简书

相关推荐
容器魔方13 分钟前
中选名单出炉|18位学生入选开源之夏KubeEdge课题,欢迎加入!
云原生·容器·云计算
love530love2 小时前
Docker 稳定运行与存储优化全攻略(含可视化指南)
运维·人工智能·windows·docker·容器
人生匆匆2 小时前
docker进入启动失败的容器
运维·docker·容器
2501_915918413 小时前
接口漏洞怎么抓?Fiddler 中文版 + Postman + Wireshark 实战指南
websocket·网络协议·tcp/ip·http·网络安全·https·udp
御控工业物联网4 小时前
御控网关如何实现MQTT、MODBUS、OPCUA、SQL、HTTP之间协议转换
数据库·sql·http
退役小学生呀4 小时前
十、K8s集群资源合理化分配
linux·云原生·容器·kubernetes·k8s
en-route5 小时前
HTTP cookie
网络·网络协议·http
yqcoder5 小时前
2. 你可以说一下 http 版本的发展过程吗
网络·网络协议·http
Johny_Zhao13 小时前
Docker + CentOS 部署 Zookeeper 集群 + Kubernetes Operator 自动化运维方案
linux·网络安全·docker·信息安全·zookeeper·kubernetes·云计算·系统运维
代码老y15 小时前
Docker:容器化技术的基石与实践指南
运维·docker·容器