好的,下面是如何将 阿里云镜像仓库配置为 containerd 的默认镜像源,包括登录凭证保存的方法:
✅ 步骤一:编辑 containerd 配置文件
默认配置文件路径通常是:
Bash
1
/etc/containerd/config.toml如不存在,可先生成默认配置:
Bash
1
containerd config default > /etc/containerd/config.toml✅ 步骤二:修改 config.toml
找到或添加以下内容,配置阿里云作为默认镜像源并带上认证:
纯文本
1
2
3
4
5
6
7
[plugins."io.containerd.grpc.v1.cri".registry]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.cn-hangzhou.aliyuncs.com"]
endpoint = ["https://registry.cn-hangzhou.aliyuncs.com"]
[plugins."io.containerd.grpc.v1.cri".registry.configs."registry.cn-hangzhou.aliyuncs.com".auth]
username = "你的阿里云用户名"
password = "你的密码或Token"🔐 如果你用的是镜像加速器,比如registry.aliyuncs.com/google_containers,也可以加多个mirrors。
✅ 步骤三:重启 containerd
Bash
1
systemctl restart containerd✅ 验证是否配置成功
你可以尝试拉取镜像:
Bash
1
ctr images pull registry.cn-hangzhou.aliyuncs.com/your_namespace/your_image:latest或者用
crictl 拉取(K8s 场景):Bash
1
crictl pull registry.cn-hangzhou.aliyuncs.com/your_namespace/your_image:latest📦 可选:K8s 中使用
如你是 Kubernetes 中使用 containerd,确保 kubelet 使用的是这个 containerd 配置(默认是的):
Bash
1
ps aux | grep kubelet | grep containerd是否还需要为 Kubernetes 设置阿里云加速的 sandbox 镜像?或者我也可以帮你配置 fallback registry。
评论栏
分享你的想法,或参与下面的讨论。
参与讨论
支持 Markdown、代码和图片
友善交流,让讨论更有价值。
更多留言
加载中…