Lework Study hard, improve every day.

使用国内镜像点获取谷歌容器镜像

2019-07-29
lework
本文 12302 字,阅读全文约需 36 分钟

由于种种原因吧,我们在下载k8s组件镜像的时候,常常会遇到下载龟速的问题,很多小伙伴在自己的docker hub中定时同步谷歌镜像,当然国内也有公司为此做了镜像站点, Azure,阿里云等等。

在使用docker hub下载镜像时,需要加上docker的国内加速站点.

常规下载谷歌镜像站点

# docker pull gcr.azk8s.cn/google_containers/pause-amd64:3.1
3.1: Pulling from google_containers/pause-amd64
67ddbfb20a22: Pull complete
Digest: sha256:59eec8837a4d942cc19a52b8c09ea75121acc38114a2c68b98983ce9356b8610
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/pause-amd64:3.1
# docker tag gcr.azk8s.cn/google_containers/pause-amd64:3.1 gcr.io/google_containers/pause-amd64:3.1
# docker images
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
gcr.azk8s.cn/google_containers/pause-amd64   3.1                 da86e6ba6ca1        19 months ago       742kB
gcr.io/google_containers/pause-amd64         3.1                 da86e6ba6ca1        19 months ago       742kB

这种下载一个镜像还行,如果是多个的话,那就要累死了,为此我写了一个脚本,减轻我们的一些工作。

便捷脚本

查看帮助

# curl -sSL https://git.io/getgcr | bash
Download the Google docker image through the proxy node

Usage: bash [[[-p proxy] [-i image] | [-t tag] | [-f file]] | [-h]]
  -p,--proxy      Specify proxy node url
  -i,--image      Specify the image name
  -t,--tag        Specify the image tag and download the k8s family bucket.
  -f,--file       Specify a file path containing the name
  -h,--help       View help


Example:
  bash gcr.io/google_containers/pause-amd64:3.1
  bash "k8s.gcr.io/kube-{apiserver,controller-manager,proxy,scheduler}:v1.14.3"
  bash -i k8s.gcr.io/pause-amd64:3.1
  bash -p registry.aliyuncs.com/google_containers -i k8s.gcr.io/pause-amd64:3.1
  bash -t v1.14.3
  bash -f ./images.txt

下载一个镜像

# curl -sSL https://git.io/getgcr | bash -s gcr.io/google_containers/pause-amd64:3.1
[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] gcr.io/google_containers/pause-amd64:3.1
3.1: Pulling from google_containers/pause-amd64
Digest: sha256:59eec8837a4d942cc19a52b8c09ea75121acc38114a2c68b98983ce9356b8610
Status: Image is up to date for gcr.azk8s.cn/google_containers/pause-amd64:3.1
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
gcr.io/google_containers/pause-amd64   3.1                 da86e6ba6ca1        19 months ago       742kB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/pause-amd64:3.1
Untagged: gcr.azk8s.cn/google_containers/pause-amd64@sha256:59eec8837a4d942cc19a52b8c09ea75121acc38114a2c68b98983ce9356b8610
[Result:] Pull image success.

下载多个镜像

# curl -sSL https://git.io/getgcr | bash -s "k8s.gcr.io/kube-{apiserver,controller-manager,proxy,scheduler}:v1.15.1"
[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-apiserver:v1.15.1
v1.15.1: Pulling from google_containers/kube-apiserver
39fafc05754f: Pull complete 
5899bcec7bbf: Pull complete 
Digest: sha256:304a1c38707834062ee87df62ef329d52a8b9a3e70459565d0a396479073f54c
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-apiserver:v1.15.1
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-apiserver   v1.15.1             68c3eb07bfc3        11 days ago         207MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-apiserver:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-apiserver@sha256:304a1c38707834062ee87df62ef329d52a8b9a3e70459565d0a396479073f54c
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-controller-manager:v1.15.1
v1.15.1: Pulling from google_containers/kube-controller-manager
39fafc05754f: Already exists 
5c943020ad72: Pull complete 
Digest: sha256:9abae95e428e228fe8f6d1630d55e79e018037460f3731312805c0f37471e4bf
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-controller-manager:v1.15.1
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-controller-manager   v1.15.1             d75082f1d121        11 days ago         159MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-controller-manager:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-controller-manager@sha256:9abae95e428e228fe8f6d1630d55e79e018037460f3731312805c0f37471e4bf
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-proxy:v1.15.1
v1.15.1: Pulling from google_containers/kube-proxy
39fafc05754f: Already exists 
db3f71d0eb90: Pull complete 
3a8a38f10886: Pull complete 
Digest: sha256:08186f4897488e96cb098dd8d1d931af9a6ea718bb8737bf44bb76e42075f0ce
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-proxy:v1.15.1
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy   v1.15.1             89a062da739d        11 days ago         82.4MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-proxy:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-proxy@sha256:08186f4897488e96cb098dd8d1d931af9a6ea718bb8737bf44bb76e42075f0ce
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-scheduler:v1.15.1
v1.15.1: Pulling from google_containers/kube-scheduler
39fafc05754f: Already exists 
66ca8e0fb424: Pull complete 
Digest: sha256:d0ee18a9593013fbc44b1920e4930f29b664b59a3958749763cb33b57e0e8956
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-scheduler:v1.15.1
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-scheduler   v1.15.1             b0b3c4c404da        11 days ago         81.1MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-scheduler:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-scheduler@sha256:d0ee18a9593013fbc44b1920e4930f29b664b59a3958749763cb33b57e0e8956
[Result:] Pull image success.

指定一个版本,下载k8s所有组件

# curl -sSL https://git.io/getgcr | bash -s - -t v1.15.1
[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-apiserver:v1.15.1
v1.15.1: Pulling from google_containers/kube-apiserver
Digest: sha256:304a1c38707834062ee87df62ef329d52a8b9a3e70459565d0a396479073f54c
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-apiserver:v1.15.1
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-apiserver   v1.15.1             68c3eb07bfc3        11 days ago         207MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-apiserver:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-apiserver@sha256:304a1c38707834062ee87df62ef329d52a8b9a3e70459565d0a396479073f54c
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-controller-manager:v1.15.1
v1.15.1: Pulling from google_containers/kube-controller-manager
Digest: sha256:9abae95e428e228fe8f6d1630d55e79e018037460f3731312805c0f37471e4bf
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-controller-manager:v1.15.1
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-controller-manager   v1.15.1             d75082f1d121        11 days ago         159MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-controller-manager:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-controller-manager@sha256:9abae95e428e228fe8f6d1630d55e79e018037460f3731312805c0f37471e4bf
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-scheduler:v1.15.1
v1.15.1: Pulling from google_containers/kube-scheduler
Digest: sha256:d0ee18a9593013fbc44b1920e4930f29b664b59a3958749763cb33b57e0e8956
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-scheduler:v1.15.1
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-scheduler   v1.15.1             b0b3c4c404da        11 days ago         81.1MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-scheduler:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-scheduler@sha256:d0ee18a9593013fbc44b1920e4930f29b664b59a3958749763cb33b57e0e8956
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-proxy:v1.15.1
v1.15.1: Pulling from google_containers/kube-proxy
Digest: sha256:08186f4897488e96cb098dd8d1d931af9a6ea718bb8737bf44bb76e42075f0ce
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-proxy:v1.15.1
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy   v1.15.1             89a062da739d        11 days ago         82.4MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-proxy:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-proxy@sha256:08186f4897488e96cb098dd8d1d931af9a6ea718bb8737bf44bb76e42075f0ce
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/pause-amd64:3.1
3.1: Pulling from google_containers/pause-amd64
Digest: sha256:59eec8837a4d942cc19a52b8c09ea75121acc38114a2c68b98983ce9356b8610
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/pause-amd64:3.1
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/pause-amd64   3.1                 da86e6ba6ca1        19 months ago       742kB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/pause-amd64:3.1
Untagged: gcr.azk8s.cn/google_containers/pause-amd64@sha256:59eec8837a4d942cc19a52b8c09ea75121acc38114a2c68b98983ce9356b8610
[Result:] Pull image success.

指定代理节点

# curl -sSL https://git.io/getgcr | bash -s - -p registry.aliyuncs.com/google_containers -i k8s.gcr.io/pause-amd64:3.1
[Proxy:] registry.aliyuncs.com/google_containers/
[Image:] k8s.gcr.io/pause-amd64:3.1
3.1: Pulling from google_containers/pause-amd64
Digest: sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
Status: Downloaded newer image for registry.aliyuncs.com/google_containers/pause-amd64:3.1
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/pause-amd64   3.1                 da86e6ba6ca1        19 months ago       742kB
[Delete:] Delete Proxy image.
Untagged: registry.aliyuncs.com/google_containers/pause-amd64:3.1
Untagged: registry.aliyuncs.com/google_containers/pause-amd64@sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
[Result:] Pull image success.

从文件中读取需要下载的镜像

# cat images.txt
k8s.gcr.io/kube-proxy:v1.15.1
k8s.gcr.io/kube-scheduler:v1.15.1
k8s.gcr.io/kube-apiserver:v1.15.1
k8s.gcr.io/kube-controller-manager:v1.15.1
k8s.gcr.io/google_containers/pause-amd64:3.1

# curl -sSL https://git.io/getgcr | bash -s - -f images.txt
[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-proxy:v1.15.1
v1.15.1: Pulling from google_containers/kube-proxy
Digest: sha256:08186f4897488e96cb098dd8d1d931af9a6ea718bb8737bf44bb76e42075f0ce
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-proxy:v1.15.1
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy   v1.15.1             89a062da739d        11 days ago         82.4MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-proxy:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-proxy@sha256:08186f4897488e96cb098dd8d1d931af9a6ea718bb8737bf44bb76e42075f0ce
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-scheduler:v1.15.1
v1.15.1: Pulling from google_containers/kube-scheduler
Digest: sha256:d0ee18a9593013fbc44b1920e4930f29b664b59a3958749763cb33b57e0e8956
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-scheduler:v1.15.1
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-scheduler   v1.15.1             b0b3c4c404da        11 days ago         81.1MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-scheduler:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-scheduler@sha256:d0ee18a9593013fbc44b1920e4930f29b664b59a3958749763cb33b57e0e8956
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-apiserver:v1.15.1
v1.15.1: Pulling from google_containers/kube-apiserver
Digest: sha256:304a1c38707834062ee87df62ef329d52a8b9a3e70459565d0a396479073f54c
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-apiserver:v1.15.1
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-apiserver   v1.15.1             68c3eb07bfc3        11 days ago         207MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-apiserver:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-apiserver@sha256:304a1c38707834062ee87df62ef329d52a8b9a3e70459565d0a396479073f54c
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/kube-controller-manager:v1.15.1
v1.15.1: Pulling from google_containers/kube-controller-manager
Digest: sha256:9abae95e428e228fe8f6d1630d55e79e018037460f3731312805c0f37471e4bf
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/kube-controller-manager:v1.15.1
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-controller-manager   v1.15.1             d75082f1d121        11 days ago         159MB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/kube-controller-manager:v1.15.1
Untagged: gcr.azk8s.cn/google_containers/kube-controller-manager@sha256:9abae95e428e228fe8f6d1630d55e79e018037460f3731312805c0f37471e4bf
[Result:] Pull image success.

[Proxy:] gcr.azk8s.cn/google_containers/
[Image:] k8s.gcr.io/google_containers/pause-amd64:3.1
3.1: Pulling from google_containers/pause-amd64
Digest: sha256:59eec8837a4d942cc19a52b8c09ea75121acc38114a2c68b98983ce9356b8610
Status: Downloaded newer image for gcr.azk8s.cn/google_containers/pause-amd64:3.1
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/google_containers/pause-amd64   3.1                 da86e6ba6ca1        19 months ago       742kB
[Delete:] Delete Proxy image.
Untagged: gcr.azk8s.cn/google_containers/pause-amd64:3.1
Untagged: gcr.azk8s.cn/google_containers/pause-amd64@sha256:59eec8837a4d942cc19a52b8c09ea75121acc38114a2c68b98983ce9356b8610
[Result:] Pull image success.

大家可以把脚本下载到本地,就不需要每次运行还要从网络上下载了。

原文地址 https://lework.github.io/2019/07/29/get-gcr/

Similar Posts

Comments