Rancher K3s 配置 registry mirror 加
2024-04-13 本文已影响0人
偷油考拉
一、目标
如下仓库,使用对应的大陆mirror加速下载
- docker.io
endpoint = ["https://mirror.ccs.tencentyun.com"] - quay.io
endpoint = ["https://quay.tencentcloudcr.com"] - registry.k8s.io
endpoint = ["https://registry.aliyuncs.com/v2/google_containers"] - gcr.io
endpoint = ["https://gcr.m.daocloud.io"] - k8s.gcr.io
endpoint = ["https://registry.aliyuncs.com/google_containers"] - ghcr.io
endpoint = ["https://ghcr.m.daocloud.io"]
二、配置 mirror
参考文档 https://docs.k3s.io/installation/registry-mirror
添加配置文件 /etc/rancher/k3s/registries.yaml
cat > /etc/rancher/k3s/registries.yaml <<EOF
mirrors:
docker.io:
endpoint:
- "https://registry.cn-hangzhou.aliyuncs.com/"
quay.io:
endpoint:
- "https://quay.tencentcloudcr.com/"
registry.k8s.io:
endpoint:
- "https://registry.aliyuncs.com/v2/google_containers"
gcr.io:
endpoint:
- "https://gcr.m.daocloud.io/"
k8s.gcr.io:
endpoint:
- "https://registry.aliyuncs.com/google_containers"
ghcr.io:
endpoint:
- "https://ghcr.m.daocloud.io/"
EOF
然后重启 k3s
systemctl restart k3s
附录 一
如上配置后,会在/var/lib/rancher/k3s/agent/etc/containerd
下创建目录 certs.d/。该目录存放containerd mirror配置文件。
如下文件应该可以拷贝到其他 containerd 运行时使用。
certs.d/docker.io/hosts.toml
# File generated by k3s. DO NOT EDIT.
server = "https://registry-1.docker.io/v2"
[host."https://registry.cn-hangzhou.aliyuncs.com/v2"]
capabilities = ["pull", "resolve"]
[root@VM-201-137-centos containerd]#
certs.d/gcr.io/hosts.toml
# File generated by k3s. DO NOT EDIT.
server = "https://gcr.io/v2"
[host."https://gcr.m.daocloud.io/v2"]
capabilities = ["pull", "resolve"]
certs.d/ghcr.io/hosts.toml
# File generated by k3s. DO NOT EDIT.
server = "https://ghcr.io/v2"
[host."https://ghcr.m.daocloud.io/v2"]
capabilities = ["pull", "resolve"]
certs.d/k8s.gcr.io/hosts.toml
# File generated by k3s. DO NOT EDIT.
server = "https://k8s.gcr.io/v2"
[host."https://registry.aliyuncs.com/google_containers"]
capabilities = ["pull", "resolve"]
override_path = true
cat certs.d/quay.io/hosts.toml
# File generated by k3s. DO NOT EDIT.
server = "https://quay.io/v2"
[host."https://quay.tencentcloudcr.com/v2"]
capabilities = ["pull", "resolve"]
certs.d/registry.k8s.io/hosts.toml
#File generated by k3s. DO NOT EDIT.
server = "https://registry.k8s.io/v2"
[host."https://registry.aliyuncs.com/v2/google_containers"]
capabilities = ["pull", "resolve"]
override_path = true