https://blog.csdn.net/m0_37814112/article/details/115863265

1、查看各版本镜像列表

下载kubeadm:链接

  1. kubeadm config images list --kubernetes-version=v1.19.9
  • 可以将docker官方地址<font style="color:rgb(248, 248, 242);background-color:rgb(40, 42, 54);">k8s.gcr.io</font>修改为阿里云地址<font style="color:rgb(248, 248, 242);background-color:rgb(40, 42, 54);">registry.cn-hangzhou.aliyuncs.com/google_containers</font>
  1. kubeadm config images list --kubernetes-version=v1.19.9 > k8s-images.list
  2. sed -i 's/k8s.gcr.io/registry.cn-hangzhou.aliyuncs.com\/google_containers/g' k8s-images.list
  3. vim k8s-images.list
  4. ##k8s-images-1.19.9
  5. registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.19.9
  6. registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.19.9
  7. registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.19.9
  8. registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.19.9
  9. registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2
  10. registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.13-0
  11. registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.7.0
  • 添加几个镜像
    • registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.9
  • 下载镜像脚本地址:链接

offline-installation-tool.sh

  1. # 导出镜像
  2. ./offline-installation-tool.sh -s -l k8s-images.list -d ./kubesphere-images
  3. # 导入镜像到私有仓库
  4. ./offline-installation-tool.sh -l k8s-images.list -d ./kubesphere-images -r dockerhub.kubekey.local
  1. vim push_image.sh
  2. #!/bin/bash
  3. old_url=registry.cn-hangzhou.aliyuncs.com/google_containers
  4. new_url=dockerhub.kubekey.local
  5. namespaceOverride=k8s
  6. images=(
  7. kube-apiserver:v1.19.9
  8. kube-controller-manager:v1.19.9
  9. kube-scheduler:v1.19.9
  10. kube-proxy:v1.19.9
  11. pause:3.2
  12. etcd:3.4.13-0
  13. coredns:1.7.0
  14. )
  15. for imagename in ${images[@]} ; do
  16. docker tag ${old_url}/${imagename} ${new_url}/${namespaceOverride}/${imagename}
  17. docker push ${new_url}/${namespaceOverride}/${imagename}
  18. done
  • 批量创建项目错误

一、获取k8s离线包Kubernetes下载篇:Kubernetes各版本镜像列表 - 图1

这个是shell文件是我直接从gitlab的项目里面拉去的,经过询问知道此文件是在window环境下面编写的,而linux环境在解析shell的时候没有忽视文件的换行符\r。因此在执行的时候出现的问题。 使用如下命令重构文件再执行文件即可,
  1. [root@VM-0-12-centos apps]# yum install dos2unix
  2. [root@VM-0-12-centos apps]# dos2unix m_api.sh

2、使用脚本下载

1. 方法一

  1. vim get_images.sh
  2. #!/bin/bash
  3. set -e
  4. KUBE_VERSION=v1.17.4
  5. KUBE_PAUSE_VERSION=3.1
  6. ETCD_VERSION=3.4.3-0
  7. CORE_DNS_VERSION=1.6.5
  8. GCR_URL=k8s.gcr.io
  9. ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers
  10. images=(kube-proxy:${KUBE_VERSION}
  11. kube-scheduler:${KUBE_VERSION}
  12. kube-controller-manager:${KUBE_VERSION}
  13. kube-apiserver:${KUBE_VERSION}
  14. pause:${KUBE_PAUSE_VERSION}
  15. etcd:${ETCD_VERSION}
  16. coredns:${CORE_DNS_VERSION})
  17. for imageName in ${images[@]} ; do
  18. docker pull $ALIYUN_URL/$imageName
  19. docker tag $ALIYUN_URL/$imageName $GCR_URL/$imageName
  20. docker rmi $ALIYUN_URL/$imageName
  21. done

2. 方法二

  1. vim get_image.sh
  2. #!/bin/bash
  3. url=registry.cn-hangzhou.aliyuncs.com/google_containers
  4. version=v1.19.9
  5. images=(`kubeadm config images list --kubernetes-version=$version|awk -F '/' '{print $2}'`)
  6. for imagename in ${images[@]} ; do
  7. docker pull $url/$imagename
  8. docker tag $url/$imagename k8s.gcr.io/$imagename
  9. docker rmi -f $url/$imagename
  10. done

说明:这里采用脚本的方式下载阿里云kubernetes核心镜像,然后修改tag,这样yaml文件的镜像名称就可以不用修改了。