作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
由于某种不可描述的问题我国网络是无法直接访问Google,YouTube等网站,因此你需要购买,自建或者在网上找一些免费的VPN工具。这不我最近在通过kubeadm部署k8s集群就遇到了想要访问"k8s.gcr.io"却无法正常访问,索性的是可以通过阿里云找到共有仓库。
一.抛出问题
如上图所示,默认情况下是无法直接访问Google的镜像仓库"k8s.gcr.io",此时咱们有三种解决方案:
(1)在互联网上找一些免费的VPN进行FQ操作或者在网上购买收费的VPN,推荐使用收费版本的,因为免费版本的VPN并不太稳定而且下载速度也并不是很理想,付费的VPN相对来说稳定性比较强,但是这种情况存在一个风险,因为你的所有操作都会被提供VPN的服务商在后台记录;
(2)在互联网上购买VPS服务器,自己搭建VPN,前提是你购买的VPS可以访问国外的各种网站,直接购买国内的阿里云服务器可以你搭建出来VPN也是白搭,这种方案也需要掏钱,但相比于上面的那种方式安全性较强,因为你访问的记录在你的VPS中有记录,你想干啥就干啥;
(3)我们的目的就是下载Google的镜像而已,可以在其它国内站点下载即可,而且很多国人已经很热心的提供了下载连接,如果你没有经常FQ的需求其实没有必要采取上面两种方案(而且有很多公司也会为员工购买FQ的工具,自己搭建VPN服务器的一般就是一些运维或开发人员喜欢干这事)。
本篇博客采取第三种方案,直接在国内的其它网站(比如阿里云的镜像网站)下载需要的镜像,下载后给镜像重新更名为kubeadm工具指定的镜像名称即可。
二.登录阿里云账户找到k8s相关的仓库
1>.登录阿里云账户,如下图所示,点击"菜单logo"
2>.点击"产品与服务",弹出如下图所示的对话框后再点击"容器镜像服务"
3>.如下图所示,点击"镜像搜索",并输入搜索关键词"google_containers/kube-apiserver"
4>.查看镜像仓库信息
5>.将docker服务器的仓库设置为"阿里云镜像"
[root@master200.yinzhengjie.org.cn ~]# grep Environment /usr/lib/systemd/system/docker.service #温馨提示,如果你有自己的VPN是设置代理的,但是没有VPN建议将这两行注释掉
#Environment="HTTPS_PROXY=http://www.yinzhengjie.org.cn:10086"
#Environment="NO_PROXY=127.0.0.0/8,172.200.0.0/21"
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://tuv7rqqq.mirror.aliyuncs.com"]
}
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# systemctl daemon-reload
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# systemctl restart docker.service
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker info | tail
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://tuv7rqqq.mirror.aliyuncs.com/
Live Restore Enabled: false
[root@master200.yinzhengjie.org.cn ~]#
三.登录阿里云并下载k8s镜像
1>.登录阿里云账号
[root@master200.yinzhengjie.org.cn ~]# docker login --username=你的阿里云账号 registry.cn-beijing.aliyuncs.com #使用咱们自己的账户登录阿里云(没有就去注册一个即可),登陆后咱们就可以从阿里云仓库下载相应的K8S镜像啦~
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@master200.yinzhengjie.org.cn ~]#
2>.下载镜像
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
v1.17.2: Pulling from google_containers/kube-apiserver
597de8ba0c30: Pull complete
46657ede464b: Pull complete
Digest: sha256:0b8d8fc93a97f8b606c023dadd9b2398cbba41cf3f663d760d6ae1d8b244adee
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
v1.17.2: Pulling from google_containers/kube-controller-manager
597de8ba0c30: Already exists
f28ab085fb92: Pull complete
Digest: sha256:9730a49ed564ec69db38b73f3c959d22869c1b9dca76d9e457fa46dbae7726e4
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
v1.17.2: Pulling from google_containers/kube-scheduler
597de8ba0c30: Already exists
b8b03bc99641: Pull complete
Digest: sha256:5386d6b086c2da29dd81412b627a0bf045f2542b4019ca7c44c5ed5ab50e27f7
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
v1.17.2: Pulling from google_containers/kube-proxy
597de8ba0c30: Already exists
3f0663684f29: Pull complete
e1f7f878905c: Pull complete
3029977cf65d: Pull complete
cc627398eeaa: Pull complete
d3609306ce38: Pull complete
e535ca5345c7: Pull complete
Digest: sha256:4a1b15c88bcfb832de4d3b8e7f59c8249007554174e3e345897bcad4e7537faf
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
3.1: Pulling from google_containers/pause
cf9202429979: Pull complete
Digest: sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
3.4.3-0: Pulling from google_containers/etcd
39fafc05754f: Pull complete
3736e1e115b8: Pull complete
79de61f59f2e: Pull complete
Digest: sha256:4198ba6f82f642dfd18ecf840ee37afb9df4b596f06eef20e44d0aec4ea27216
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
1.6.5: Pulling from google_containers/coredns
c6568d217a00: Pull complete
fc6a9081f665: Pull complete
Digest: sha256:608ac7ccba5ce41c6941fca13bc67059c1eef927fd968b554b790e21cc92543c
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
3>.查看已经下载的镜像
[root@master200.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.17.2 cba2a99699bd 2 weeks ago 116MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.17.2 41ef50a5f06a 2 weeks ago 171MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.17.2 da5fd66c4068 2 weeks ago 161MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler v1.17.2 f52d4c527ef2 2 weeks ago 94.4MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.6.5 70f311871ae1 3 months ago 41.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 2 years ago 742kB
[root@master200.yinzhengjie.org.cn ~]#
四.将下载的镜像更名并删除之前下载的镜像
1>.对下载的镜像打tag
[root@master200.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.17.2 cba2a99699bd 2 weeks ago 116MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.17.2 41ef50a5f06a 2 weeks ago 171MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.17.2 da5fd66c4068 2 weeks ago 161MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler v1.17.2 f52d4c527ef2 2 weeks ago 94.4MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.6.5 70f311871ae1 3 months ago 41.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 2 years ago 742kB
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2 k8s.gcr.io/kube-apiserver:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2 k8s.gcr.io/kube-controller-manager:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2 k8s.gcr.io/kube-scheduler:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2 k8s.gcr.io/kube-proxy:v1.17.2
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5 k8s.gcr.io/coredns:1.6.5
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy v1.17.2 cba2a99699bd 2 weeks ago 116MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.17.2 cba2a99699bd 2 weeks ago 116MB
k8s.gcr.io/kube-apiserver v1.17.2 41ef50a5f06a 2 weeks ago 171MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.17.2 41ef50a5f06a 2 weeks ago 171MB
k8s.gcr.io/kube-controller-manager v1.17.2 da5fd66c4068 2 weeks ago 161MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.17.2 da5fd66c4068 2 weeks ago 161MB
k8s.gcr.io/kube-scheduler v1.17.2 f52d4c527ef2 2 weeks ago 94.4MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler v1.17.2 f52d4c527ef2 2 weeks ago 94.4MB
k8s.gcr.io/coredns 1.6.5 70f311871ae1 3 months ago 41.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.6.5 70f311871ae1 3 months ago 41.6MB
k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 2 years ago 742kB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 2 years ago 742kB
[root@master200.yinzhengjie.org.cn ~]#
2>.删除之前的下载的镜像
[root@master200.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy v1.17.2 cba2a99699bd 2 weeks ago 116MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.17.2 cba2a99699bd 2 weeks ago 116MB
k8s.gcr.io/kube-controller-manager v1.17.2 da5fd66c4068 2 weeks ago 161MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.17.2 da5fd66c4068 2 weeks ago 161MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.17.2 41ef50a5f06a 2 weeks ago 171MB
k8s.gcr.io/kube-apiserver v1.17.2 41ef50a5f06a 2 weeks ago 171MB
k8s.gcr.io/kube-scheduler v1.17.2 f52d4c527ef2 2 weeks ago 94.4MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler v1.17.2 f52d4c527ef2 2 weeks ago 94.4MB
k8s.gcr.io/coredns 1.6.5 70f311871ae1 3 months ago 41.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.6.5 70f311871ae1 3 months ago 41.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 2 years ago 742kB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 2 years ago 742kB
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy@sha256:4a1b15c88bcfb832de4d3b8e7f59c8249007554174e3e345897bcad4e7537faf
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager@sha256:9730a49ed564ec69db38b73f3c959d22869c1b9dca76d9e457fa46dbae7726e4
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler@sha256:5386d6b086c2da29dd81412b627a0bf045f2542b4019ca7c44c5ed5ab50e27f7
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/coredns@sha256:608ac7ccba5ce41c6941fca13bc67059c1eef927fd968b554b790e21cc92543c
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd@sha256:4198ba6f82f642dfd18ecf840ee37afb9df4b596f06eef20e44d0aec4ea27216
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause@sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver@sha256:0b8d8fc93a97f8b606c023dadd9b2398cbba41cf3f663d760d6ae1d8b244adee
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]# docker image rm -f registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
[root@master200.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy v1.17.2 cba2a99699bd 2 weeks ago 116MB
k8s.gcr.io/kube-apiserver v1.17.2 41ef50a5f06a 2 weeks ago 171MB
k8s.gcr.io/kube-controller-manager v1.17.2 da5fd66c4068 2 weeks ago 161MB
k8s.gcr.io/kube-scheduler v1.17.2 f52d4c527ef2 2 weeks ago 94.4MB
k8s.gcr.io/coredns 1.6.5 70f311871ae1 3 months ago 41.6MB
k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 2 years ago 742kB
[root@master200.yinzhengjie.org.cn ~]#
[root@master200.yinzhengjie.org.cn ~]#
五.博主推荐阅读
使用kubeadm部署kubernetes(简称k8s)集群实战篇:
https://developer.aliyun.com/article/1604378