[Kubernetes (K8S)] A few ways to download images from k8s.gcr.io

The biggest problem in deploying Kubernetes (K8S) is mirror downloading too slowly. It is difficult to download images from hub such as k8s.gcr.io in a domestic environment because network limit.

There are a fee ways:

  1. Directly designate a domestic mirror (such as an Alibaba Cloud mirror) to pull and download images.

  2. After successfully pulling the images in the mirror, tag it to become the corresponding mirror of k8s.gcr.io.

  3. Finally delete the image tag pulled from the mirror.


Make sure that the imagePullPolicy policy is IfNotPresent, that is, if there is a local mirror, use the local mirror instead of pulling!


Or put the downloaded image in the Harbor private repository, and then point the image download source to the harbor private repository address.

Example

Remember to replace coredns:1.7.0 with your prefer image and version.

Pull and tag one image.

1
2
3
4
5
6
7
$ REGISTRY_MIRROR=registry.aliyuncs.com/google_containers

$ IMAGE_VERSION=coredns:1.7.0

$ docker pull ${REGISTRY_MIRROR}/${IMAGE_VERSION} && \
docker tag ${REGISTRY_MIRROR}/${IMAGE_VERSION} k8s.gcr.io/${IMAGE_VERSION} && \
docker rmi ${REGISTRY_MIRROR}/${IMAGE_VERSION}

Pull and tag multiple images.

Remember to replace coredns:1.7.0 and pause:3.2 with your prefer image and version.

1
2
3
4
5
6
7
8
9
10
$ REGISTRY_MIRROR=registry.aliyuncs.com/google_containers

$ IMAGE_VERSIONS="coredns:1.7.0 pause:3.2"

$ for IMAGE_VERSION in ${IMAGE_VERSIONS}; \
do \
docker pull ${REGISTRY_MIRROR}/${IMAGE_VERSION} && \
docker tag ${REGISTRY_MIRROR}/${IMAGE_VERSION} k8s.gcr.io/${IMAGE_VERSION} && \
docker rmi ${REGISTRY_MIRROR}/${IMAGE_VERSION}; \
done

References

[1] 无法直接在国内网络环境下从k8s.gcr.io下载镜像问题 - 散尽浮华 - 博客园 - https://www.cnblogs.com/kevingrace/p/12778066.html

[2] Harbor - https://goharbor.io/