获取kubeadmin部署时所需的images镜像脚本


 背景

通过kubeadm部署kubernetes时,kubeadm默认会自动从google下载相应的版本

通过kubeadm config images list查看需要下载的image及其版本

kubeadm config images list

k8s.gcr.io/kube-apiserver:v1.24.0
k8s.gcr.io/kube-controller-manager:v1.24.0
k8s.gcr.io/kube-scheduler:v1.24.0
k8s.gcr.io/kube-proxy:v1.24.0
k8s.gcr.io/pause:3.7
k8s.gcr.io/etcd:3.5.3-0
k8s.gcr.io/coredns/coredns:v1.8.6

阿里的image源中会同步google的最新版本,只需要从的镜像源registry.aliyuncs.com/google_containers下载相应的版本,并将下载的image重新tag成kubeadm config images list的版本即可。kubernetes所有节点都要下载,不然部署集群或加入集群时将无法正常加入

下载镜像脚本

cat images_install.sh

#!/bin/bash
apiserver_version="v1.24.0"
controller_version="v1.24.0"
scheduler_version="v1.24.0"
proxy_version="v1.24.0"
pause_version="3.7"
etcd_version="3.5.3-0"
coredns_version="v1.8.6"

grc_uri="k8s.gcr.io"
aliyuncs_uri="registry.aliyuncs.com/google_containers"
#docker pull
docker pull ${aliyuncs_uri}/kube-apiserver:${apiserver_version}
docker pull ${aliyuncs_uri}/kube-controller-manager:${controller_version}
docker pull ${aliyuncs_uri}/kube-scheduler:${scheduler_version}
docker pull ${aliyuncs_uri}/kube-proxy:${proxy_version}
docker pull ${aliyuncs_uri}/pause:${pause_version}
docker pull ${aliyuncs_uri}/etcd:${etcd_version}
docker pull ${aliyuncs_uri}/coredns:${coredns_version}

#tag images
docker tag ${aliyuncs_uri}/kube-apiserver:${apiserver_version} ${grc_uri}/kube-apiserver:${apiserver_version}
docker tag ${aliyuncs_uri}/kube-controller-manager:${controller_version} ${grc_uri}/kube-controller-manager:${controller_version}
docker tag ${aliyuncs_uri}/kube-scheduler:${scheduler_version} ${grc_uri}/kube-scheduler:${scheduler_version}
docker tag ${aliyuncs_uri}/kube-proxy:${proxy_version} ${grc_uri}/kube-proxy:${proxy_version}
docker tag ${aliyuncs_uri}/pause:${pause_version} ${grc_uri}/pause:${pause_version}
docker tag ${aliyuncs_uri}/etcd:${etcd_version} ${grc_uri}/etcd:${etcd_version}
docker tag ${aliyuncs_uri}/coredns:${coredns_version} ${grc_uri}/coredns/coredns:${coredns_version}

#remove aliyun images
docker rmi ${aliyuncs_uri}/kube-apiserver:${apiserver_version}
docker rmi ${aliyuncs_uri}/kube-controller-manager:${controller_version}
docker rmi ${aliyuncs_uri}/kube-scheduler:${scheduler_version}
docker rmi ${aliyuncs_uri}/kube-proxy:${proxy_version}
docker rmi ${aliyuncs_uri}/pause:${pause_version}
docker rmi ${aliyuncs_uri}/etcd:${etcd_version}
docker rmi ${aliyuncs_uri}/coredns:${coredns_version}