在 /etc/containerd/config.toml 中按下面的方式添加镜像加速器
[plugins]
[plugins."io.containerd.grpc.v1.cri".registry]
...
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://xxxxxx.mirror.aliyuncs.com"]
pull image 时没有走镜像加速器
# nerdctl pull docker.io/daprio/daprd:1.8.3
INFO[0011] trying next host error="failed to authorize: failed to fetch anonymous token: Get \"https://auth.docker.io/token?scope=repository%3Adaprio%2Fdaprd%3Apull&service=registry.docker.io\": net/http: TLS handshake timeout" host=registry-1.docker.io
请问如何解决这个问题?
上面的配置方式是旧版 conainterd 采用的,已经 deprecated,改用新版配置方法解决了
/etc/containerd/config.toml
中, 在 [plugins."io.containerd.grpc.v1.cri".registry]
下面添加 config_path [plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
/etc/containerd/certs.d/docker.io/
,在其中添加包含下面内容的 hosts.toml
文件[host."https://xxxxxx.mirror.aliyuncs.com"]
capabilities = ["pull"]
systemctl restart containerd
https://microk8s.io/docs/registry-private
Configure registry mirrors
Under specific circumstances (e.g. geographical restrictions, network firewalls), certain image registries may not be available. For example, for Chinese mainland users k8s.gcr.io is not available, and a mirror such as registry.cn-hangzhou.aliyuncs.com/google_containers can be used instead.
In order to configure a registry mirror for registry.k8s.io and have it point to registry.cn-hangzhou.aliyuncs.com/google_containers, the following configuration is required:
sudo mkdir -p /var/snap/microk8s/current/args/certs.d/registry.k8s.io
echo '
server = "registry.k8s.io"
[host."https://registry.aliyuncs.com/v2/google_containers"]
capabilities = ["pull", "resolve"]
override_path = true
' | sudo tee -a /var/snap/microk8s/current/args/certs.d/registry.k8s.io/hosts.toml
A restart of the containerd daemon helps but is not required, since changes should take effect immediately.
sudo snap restart microk8s