阿里云拉取k8s.gcr.io 镜像

1、创建GitHub仓库

创建一个GitHub仓库,主要用于配置Dockerfile。

示例:https://github.com/guonanjun/k8s-repo

Dockerfile示例:

FROM k8s.gcr.io/kube-apiserver:v1.17.2
MAINTAINER guonanjun <guonj89@163.com>

主要目的是利用阿里云这个中介帮我们下载镜像。

2、创建阿里云镜像仓库

登录阿里云容器镜像服务。

地址:https://cr.console.aliyun.com/cn-shenzhen/instances/repositories

创建镜像并关联GitHub账号,并且注意要选择海外机器构建。

选择具体的仓库,添加构建规则。

3、增加拉取脚本

mkdir -p /opt/shell/k8s
vi /opt/shell/k8s/pull-img-from-ali.sh

添加以下内容:

#!/bin/bash
KUBE_VERSION=v1.17.2
PAUSE_VERSION=3.1
ETCD_VERSION=3.4.3-0
COREDNS_VERSION=1.6.5

docker pull registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-apiserver:${KUBE_VERSION}
docker pull registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-controller-manager:${KUBE_VERSION}
docker pull registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-scheduler:${KUBE_VERSION}
docker pull registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-proxy:${KUBE_VERSION}
docker pull registry.cn-shenzhen.aliyuncs.com/guonanjun/pause:${PAUSE_VERSION}
docker pull registry.cn-shenzhen.aliyuncs.com/guonanjun/etcd:${ETCD_VERSION}
docker pull registry.cn-shenzhen.aliyuncs.com/guonanjun/coredns:${COREDNS_VERSION}

docker tag registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-apiserver:${KUBE_VERSION}  k8s.gcr.io/kube-apiserver:${KUBE_VERSION}
docker tag registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-controller-manager:${KUBE_VERSION}  k8s.gcr.io/kube-controller-manager:${KUBE_VERSION}
docker tag registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-scheduler:${KUBE_VERSION}  k8s.gcr.io/kube-scheduler:${KUBE_VERSION}
docker tag registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-proxy:${KUBE_VERSION}  k8s.gcr.io/kube-proxy:${KUBE_VERSION}
docker tag registry.cn-shenzhen.aliyuncs.com/guonanjun/pause:${PAUSE_VERSION} k8s.gcr.io/pause:${PAUSE_VERSION}
docker tag registry.cn-shenzhen.aliyuncs.com/guonanjun/etcd:${ETCD_VERSION} k8s.gcr.io/etcd:${ETCD_VERSION}
docker tag registry.cn-shenzhen.aliyuncs.com/guonanjun/coredns:${COREDNS_VERSION} k8s.gcr.io/coredns:${COREDNS_VERSION}

docker rmi registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-apiserver:${KUBE_VERSION}
docker rmi registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-controller-manager:${KUBE_VERSION}
docker rmi registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-scheduler:${KUBE_VERSION}
docker rmi registry.cn-shenzhen.aliyuncs.com/guonanjun/kube-proxy:${KUBE_VERSION}
docker rmi registry.cn-shenzhen.aliyuncs.com/guonanjun/pause:${PAUSE_VERSION}
docker rmi registry.cn-shenzhen.aliyuncs.com/guonanjun/etcd:${ETCD_VERSION}
docker rmi registry.cn-shenzhen.aliyuncs.com/guonanjun/coredns:${COREDNS_VERSION}

拉取镜像:

chmod +x /opt/shell/k8s/pull-img-from-ali.sh
/opt/shell/k8s/pull-img-from-ali.sh

未经允许不得转载:君子如兰 » 阿里云拉取k8s.gcr.io 镜像

赞 (0)