上传K8S镜像到私有仓库

简介

  • 由于GFW的存在,导致使用无法下载到K8S的镜像。
  • 本文将介绍上传K8S镜像到Docker Hub中,加速部署K8S集群。

上传镜像

获取镜像

  • 获取指定版本K8S所需的镜像:
1
kubeadm config images list --kubernetes-version v1.17.5

下载镜像

  • 通过能访问外网的VPS下载镜像:
1
2
3
4
5
6
7
docker pull k8s.gcr.io/pause:3.1
docker pull k8s.gcr.io/etcd:3.4.3-0
docker pull k8s.gcr.io/coredns:1.6.5
docker pull k8s.gcr.io/kube-proxy:v1.17.5
docker pull k8s.gcr.io/kube-apiserver:v1.17.5
docker pull k8s.gcr.io/kube-scheduler:v1.17.5
docker pull k8s.gcr.io/kube-controller-manager:v1.17.5

上传镜像

  • 在终端登录Docker Hub
1
docker login -u <UserName> -p <Password>
  • 为镜像设置tag
1
2
3
4
5
6
7
docker tag k8s.gcr.io/pause:3.1 xiaocoder/pause:3.1
docker tag k8s.gcr.io/etcd:3.4.3-0 xiaocoder/etcd:3.4.3-0
docker tag k8s.gcr.io/coredns:1.6.5 xiaocoder/coredns:1.6.5
docker tag k8s.gcr.io/kube-proxy:v1.17.5 xiaocoder/kube-proxy:v1.17.5
docker tag k8s.gcr.io/kube-apiserver:v1.17.5 xiaocoder/kube-apiserver:v1.17.5
docker tag k8s.gcr.io/kube-scheduler:v1.17.5 xiaocoder/kube-scheduler:v1.17.5
docker tag k8s.gcr.io/kube-controller-manager:v1.17.5 xiaocoder/kube-controller-manager:v1.17.5
  • 上传镜像到Docker Hub
1
2
3
4
5
6
7
docker push xiaocoder/pause:3.1
docker push xiaocoder/etcd:3.4.3-0
docker push xiaocoder/coredns:1.6.5
docker push xiaocoder/kube-proxy:v1.17.5
docker push xiaocoder/kube-apiserver:v1.17.5
docker push xiaocoder/kube-scheduler:v1.17.5
docker push xiaocoder/kube-controller-manager:v1.17.5

使用镜像

手动

  • Master节点下载镜像并设置tag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
docker pull xiaocoder/pause:3.1
docker pull xiaocoder/etcd:3.4.3-0
docker pull xiaocoder/coredns:1.6.5
docker pull xiaocoder/kube-proxy:v1.17.5
docker pull xiaocoder/kube-apiserver:v1.17.5
docker pull xiaocoder/kube-scheduler:v1.17.5
docker pull xiaocoder/kube-controller-manager:v1.17.5

docker tag xiaocoder/pause:3.1 k8s.gcr.io/pause:3.1
docker tag xiaocoder/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag xiaocoder/coredns:1.6.5 k8s.gcr.io/coredns:1.6.5
docker tag xiaocoder/kube-proxy:v1.17.5 k8s.gcr.io/kube-proxy:v1.17.5
docker tag xiaocoder/kube-apiserver:v1.17.5 k8s.gcr.io/kube-apiserver:v1.17.5
docker tag xiaocoder/kube-scheduler:v1.17.5 k8s.gcr.io/kube-scheduler:v1.17.5
docker tag xiaocoder/kube-controller-manager:v1.17.5 k8s.gcr.io/kube-controller-manager:v1.17.5
  • Node节点下载镜像并设置tag
1
2
3
4
5
docker pull xiaocoder/pause:3.1
docker pull xiaocoder/kube-proxy:v1.17.5

docker tag xiaocoder/pause:3.1 k8s.gcr.io/pause:3.1
docker tag xiaocoder/kube-proxy:v1.17.5 k8s.gcr.io/kube-proxy:v1.17.5
  • 初始化Master节点:
1
2
3
4
5
kubeadm init \
--service-cidr 10.20.0.0/16 \
--kubernetes-version v1.17.5 \
--pod-network-cidr 10.10.0.0/16 \
--apiserver-advertise-address 172.18.20.10

自动

  • 初始化Master节点:
1
2
3
4
5
6
kubeadm init \
--service-cidr 10.20.0.0/16 \
--kubernetes-version v1.17.5 \
--pod-network-cidr 10.10.0.0/16 \
--apiserver-advertise-address 172.18.20.2 \
--image-repository docker.io/xiaocoder
  • 已包含的版本:
    • v1.17.5

阿里云

  • 初始化Master节点:
1
2
3
4
5
6
kubeadm init \
--service-cidr 10.20.0.0/16 \
--kubernetes-version v1.17.5 \
--pod-network-cidr 10.10.0.0/16 \
--apiserver-advertise-address 172.18.20.2 \
--image-repository registry.aliyuncs.com/google_containers

请作者喝瓶肥宅快乐水