国内拉取google kubernetes镜像

常用镜像仓库

DockerHub镜像仓库:
https://hub.docker.com/

google镜像仓库:
https://gcr.io/google-containers/
https://gcr.io/kubernetes-helm/
https://gcr.io/google-containers/pause

coreos镜像仓库:
https://quay.io/repository/

elastic镜像仓库:
https://www.docker.elastic.co/

RedHat镜像仓库:
https://access.redhat.com/containers

阿里云镜像仓库:
https://cr.console.aliyun.com

华为云镜像仓库:
https://console.huaweicloud.com/swr

国内镜像源

部分国外镜像仓库无法访问,但国内有对应镜像源,可以从以下镜像源拉取到本地然后重改tag即可:
阿里云镜像仓库

可以拉取k8s.gcr.io镜像

#示例
docker pull k8s.gcr.io/pause:3.2

#改为
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2
  • 1
  • 2
  • 3
  • 4
  • 5

dockerhub镜像仓库

可以拉取k8s.gcr.io镜像

#示例
docker pull k8s.gcr.io/pause:3.1
docker pull k8s.gcr.io/kube-apiserver:v1.17.3

#改为
docker pull googlecontainersmirrors/pause:3.1
docker pull googlecontainersmirrors/kube-apiserver:v1.17.3
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

七牛云镜像仓库

可以拉取quay.io镜像

#示例
docker pull quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0

#改为
docker pull quay-mirror.qiniu.com/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0
  • 1
  • 2
  • 3
  • 4
  • 5

dockerhub搜索镜像
很多国外镜像已经有热心网友传到了dockerhub,例如gcr.io/kubernetes-helm/tiller:v2.16.5这个镜像,直接搜索关键字,找到排序靠前的然后在dockerhub确认并拉取即可:

# docker search tiller
NAME                                    DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
jessestuart/tiller                      Nightly multi-architecture (amd64, arm64, ar  19                                      [OK]
sapcc/tiller                            Mirror of https://gcr.io/kubernetes-helm/til  9                                       
ist0ne/tiller                           https://gcr.io/kubernetes-helm/tiller           ....                                                                       
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述

dockerhub镜像国内加速

阿里云镜像加速
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://uyah70su.mirror.aliyuncs.com"]
}
EOF
  • 1
  • 2
  • 3
  • 4
  • 5

daocloud dockerhub镜像加速
https://www.daocloud.io/mirror

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
  • 1

西北农林大学dockerhub镜像加速
https://mirrors.nwafu.edu.cn/help/reverse-proxy/dockerhub

{
  "registry-mirrors": ["https://dockerhub.mirrors.nwafu.edu.cn/"]
}
  • 1
  • 2
  • 3

华为云dockerhub镜像加速
https://console.huaweicloud.com/swr

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<- 'EOF'
{
    "registry-mirrors": ["https://7bafc985f90c43b887a96c2b846cf984.mirror.swr.myhuaweicloud.com"]
}
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

然后重新启动 Docker 服务:

sudo systemctl daemon-reload && sudo systemctl restart docker
  • 1

验证加速器是否生效
执行 $ docker info,如果从结果中看到了如下内容,说明配置成功。

$ docker info | grep Mirrors -A1
Registry Mirrors:
 https://uyah70su.mirror.aliyuncs.com/

#验证镜像拉取速度
$ time docker pull centos
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

直接拉取国外镜像

如果你已经在本地windows上使用番茄工具,默认可以通过它的1080端口来拉取镜像。
在安装docker的linux服务器执行以下操作,其中192.168.0.103是你本地windows能上网的网卡IP:

mkidr -p /etc/systemd/system/docker.service.d

cat > /etc/systemd/system/docker.service.d/http-proxy.conf  <<EOF
[Service]
Environment="HTTP_PROXY=http://192.168.0.103:1080"
EOF

systemctl daemon-reload && systemctl restart docker
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

注意还要在客户端里鼠标右键勾选允许其他设备连接。以上配置完成后即可直接拉取google镜像

# docker pull k8s.gcr.io/kube-apiserver:v1.16.1
v1.16.1: Pulling from kube-apiserver
39fafc05754f: Already exists 
010af2aa5529: Pull complete 
Digest: sha256:80feeaed6c6445ab0ea0c27153354c3cac19b8b028d9b14fc134f947e716e25e
Status: Downloaded newer image for k8s.gcr.io/kube-apiserver:v1.16.1
k8s.gcr.io/kube-apiserver:v1.16.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

创建个人仓库

我们也可以在dockerhub或阿里云创建个人仓库,把需要的最新版本镜像从google仓库push到个人仓库,一般有几下几种方法:
1.购买云服务器
购买1台能同时访问国外和国内网络的云服务器,使用docker login登录dockerhub或阿里云仓库,docker push命令推送上去然后再拉取到本地即可。
如果不想购买服务器又能够访问国外网络,建议使用google提供的cloud shell:
https://console.cloud.google.com/cloudshell
它类似一个永久免费的拥有5G存储空间的linux服务器,能够执行所有docker命令和bash命令,最重要的是它能够访问全球网络。

2.Travis CI推送镜像
使用travis CI+GitHub将镜像push到国内镜像仓库。

3.Github镜像构建功能
使用github的dockerfile构建功能,将镜像构建到国内仓库。
参考:https://blog.csdn.net/networken/article/details/85215714

Travis CI推送dokcer镜像

下面介绍第2种方法,使用travis CI+GitHub的方法将镜像拉取到阿里云或者dockehub。

创建github仓库
首先登录github创建一个仓库,名称自定义,仓库包含如下2个文件:

  • img-list.txt 外网镜像列表文件
  • .travis.yaml travisCI自动构建文件

示例仓库:https://github.com/willzhang/pull-docker-images

.travis.yaml 内容如下,主要从国外镜像仓库pull镜像,打tag,并push到阿里云或dockerhub.

language: bash

services:
  - docker

env:
  global:
    #change the registry name and username/password to yourself's.
    - DOCKER_HUB=willdockerhub
    - ALI_REGISTRY=registry.cn-shenzhen.aliyuncs.com/images_mirror

before_script:
  - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
  - docker login $ALI_REGISTRY -u $ALI_USERNAME  -p $ALI_PASSWORD

script:
  - echo "start pull and retag and push"
  - |
    for image in $(cat img-list.txt)
    do
    	image_name=${image##*/}
    	docker pull $image
    	docker tag $image $DOCKER_HUB/$image_name
        docker tag $image $ALI_REGISTRY/$image_name
    	
    	# push到dockerhub
    	docker push $DOCKER_HUB/$image_name
    	# push到阿里云仓库
    	docker push $ALI_REGISTRY/$image_name
    done
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

img-list.txt主要包含国内无法拉取的镜像列表,注意必须为完整镜像路径和名称,示例如下:

gcr.io/google-containers/kube-apiserver-amd64:v1.12.0
quay.io/external_storage/nfs-client-provisioner:latest
  • 1
  • 2

.travis.yaml文件监测github仓库的代码变动,当有代码变动时比如img-list.txt写入新的镜像列表时将触发tarvis的自动构建
这里需要登录阿里云或dockerhub才能执行docker push操作,其中$ALI_USERNAME这类变量在TravisCI管理界面定义好即可。

TravisCI配置

访问travis官网: https://www.travis-ci.com, 使用github账号登录。

开启需要进行自动化构建的仓库即可:
在这里插入图片描述
另外需要点击右上角的more options —》settings选项,定义写在.travis.yaml中的账号密码等敏感参数。
在这里插入图片描述
当对github仓库执行git commit、git push操作时将自动触发构建,执行仓库中的脚本,这里的构建结果如下:
在这里插入图片描述
登录阿里云或dockerhub查看,imagepath.txt 列表中的镜像已经成功被push上来:
注意:push到阿里云的镜像默认为私有的,可以手动改为公开的。
在这里插入图片描述
在这里插入图片描述
日常拉取镜像方法:
修改img-list.txt,写入需要拉取的镜像完整路径,保存后travis-CI监测到仓库代码变动,自动触发构建,几分钟后镜像就会被自动拉取到个人仓库。

参考:
https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
https://blog.csdn.net/nklinsirui/article/details/80581286
https://www.cnblogs.com/xuxinkun/p/11025020.html

猜你喜欢

转载自blog.csdn.net/kongliand/article/details/110819023