containerd 保存认证信息

Containerd

  • 约 4 分钟
  • 926 字
好的,下面是如何将 阿里云镜像仓库配置为 containerd 的默认镜像源,包括登录凭证保存的方法:

✅ 步骤一:编辑 containerd 配置文件

默认配置文件路径通常是:
Bash
/etc/containerd/config.toml
如不存在,可先生成默认配置:
Bash
containerd config default > /etc/containerd/config.toml

✅ 步骤二:修改 config.toml

找到或添加以下内容,配置阿里云作为默认镜像源并带上认证:
纯文本
[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
systemctl restart containerd

✅ 验证是否配置成功

你可以尝试拉取镜像:
Bash
ctr images pull registry.cn-hangzhou.aliyuncs.com/your_namespace/your_image:latest
或者用 crictl 拉取(K8s 场景):
Bash
crictl pull registry.cn-hangzhou.aliyuncs.com/your_namespace/your_image:latest

📦 可选:K8s 中使用

如你是 Kubernetes 中使用 containerd,确保 kubelet 使用的是这个 containerd 配置(默认是的):
Bash
ps aux | grep kubelet | grep containerd

是否还需要为 Kubernetes 设置阿里云加速的 sandbox 镜像?或者我也可以帮你配置 fallback registry。

评论栏

分享你的想法,或参与下面的讨论。

参与讨论

支持 Markdown、代码和图片

撰写评论
正在加载编辑器…

友善交流,让讨论更有价值。

更多留言

加载中…