提醒!
Azure的
*.azk8s.cn镜像源在2020年4月3日凌晨开始,只允许【Azure中国IP】访问,其他公网IP访问azk8s.cn都会返回403!项目原文如下
ACR does not provide public anonymous access functionality on Azure China, this feature is in public preview on global Azure.
相关issue,issue#60
说明
- 由于Dockerhub、k8s.gcr.io、Quay.io这些常用的容器镜像源都在国外,在国内访问经常不稳定,特别是托管在Google的k8s.gcr.io,对新手安装Kubernetes非常不方便
- Azure中国提供了容器镜像代理服务,速度也算比较文档,这里记录一下配置过程
- 项目说明:container-service-for-azure-china
配置镜像源
DockerHub
以前Docker公司在国内是有专门的镜像服务器的,后来不知道咋的就没了。
这里使用Azure中国的镜像代理
| 原镜像地址 | 替换为Azure中国的地址 |
|---|---|
alpine:3.10 | dockerhub.azk8s.cn/library/alpine:3.10 |
jenkins/jenkins:2.190.1 | dockerhub.azk8s.cn/jenkins/jenkins:2.190.1 |
Docker
编辑/etec/docker/daemon.json在registry-mirrors配置中添加https://dockerhub.azk8s.cn。
1 | { |
Dockerfile
在FROM镜像的时候,直接使用Azure中国的源。
需要注意的是,Docker代码在split的时候,如果只有
xxxx:tag会拉取/library/xxxx:tag。使用Azure中国的代理服务器,在处理这样的镜像时,需要自己手动添加一下
/library,否则会找不到镜像。
1 | FROM dockerhub.azk8s.cn/library/alpine:3.10 |
gcr.io
国内用gcr.io比较少,通常都是用来下载Kubernetes的容器镜像。
可以通过替换镜像地址的方式来进行下载。
k8s.gcr.io会被重定向到gcr.io/google_containers。
| 原镜像地址 | 替换为Azure中国的地址 |
|---|---|
k8s.gcr.io/pause:3.1 | gcr.azk8s.cn/google_containers/pause:3.1 |
gcr.io/abc/image:1111 | gcr.azk8s.cn/abc/image:1111 |
Quay.io
这里Quay也可以通过替换镜像的方式来下载
| 原镜像地址 | 替换为Azure中国的地址 |
|---|---|
quay.io/coreos/flannel:v0.11.0-amd64 | quay.azk8s.cn/coreos/flannel:v0.11.0-amd64 |
Azure中国原版项目说明
Container Registry Proxy
Since some well known container registries like docker.io, gcr.io are not accessible or very slow in China, we have set up container registry proxies on Azure China for public anonymous access:
The first docker pull of new image will be still slow, and then image would be cached, would be much faster in the next docker pull action.
| global | proxy in China | format | example |
|---|---|---|---|
| dockerhub (docker.io) | dockerhub.azk8s.cn | dockerhub.azk8s.cn//: | dockerhub.azk8s.cn/microsoft/azure-cli:2.0.61 dockerhub.azk8s.cn/library/nginx:1.15 |
| gcr.io | gcr.azk8s.cn | gcr.azk8s.cn//: | gcr.azk8s.cn/google_containers/hyperkube-amd64:v1.13.5 |
| quay.io | quay.azk8s.cn | quay.azk8s.cn//: | quay.azk8s.cn/deis/go-dev:v1.10.0 |
Note:
k8s.gcr.iowould redirect togcr.io/google-containers, following image urls are identical:
1 | k8s.gcr.io/pause-amd64:3.1 |
Container Registry Proxy Example
specify
defaultBackend.image.repositoryasgcr.azk8s.cn/google_containers/defaultbackendin nginx-ingress chart since originalk8s.gcr.iodoes not work in Azure China:1
helm install stable/nginx-ingress --set defaultBackend.image.repository=gcr.azk8s.cn/google_containers/defaultbackend --set defaultBackend.image.tag=1.4