5

仅需添加1个参数,即可飞速拉取Rancher镜像!

 3 years ago
source link: http://dockone.io/article/2434282
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

仅需添加1个参数,即可飞速拉取Rancher镜像!

作者简介


王海龙,SUSE/Rancher中国社区技术经理,负责Rancher中国技术社区的维护和运营。拥有7年的云计算领域经验,经历了OpenStack到Kubernetes的技术变革,无论底层操作系统Linux,还是虚拟化KVM或是Docker容器技术都有丰富的运维和实践经验。

离线安装部署可以让企业在内网环境顺利运行Rancher,但是在国内网络环境中进行Rancher离线安装时,由于镜像本身较大以及网络的影响下载所需的镜像耗时较长。

Rancher 提供的 rancher-images.txt 有 100+个镜像,压缩后的大小也将近 8G。从 Rancher release(https://github.com/rancher/rancher/releases) 下载的 rancher-save-images.sh 默认从 dockerhub 拉取镜像。如果所有镜像都从 dockerhub 下载,那将是一个非常艰巨的任务。

为了进一步提升国内用户体验,Rancher 针对国内环境做了一些优化, 在 rancher-save-images.sh 中增加了 --from-aliyun true 参数, 来支持从国内的阿里云镜像仓库去拉取 rancher-images.txt 的镜像。

注意:
  1. 从 Rancher v2.4.15 和 v2.5.8 开始支持--from-aliyun true 参数。
  2. 从 Rancher release 中下载的 rancher-save-images.sh 暂不支持 --from-aliyun
    true
    参数。
  3. 支持 --from-aliyun true 参数的 rancher-save-images.sh 可以从http://mirror.rancher.cn --> rancher 获得。
1、获取支持 --from-aliyun true 参数的 rancher-save-images.sh

浏览器访问 http://mirror.rancher.cn,然后导航到 rancher 目录下,选择对应的 rancher 版本,下载 rancher-save-images.sh。rancher-images.txtrancher-load-images.shhttp://mirror.rancher.cn 或 Rancher release 下载均可,无差别。

图片

2、从阿里云镜像仓库拉取镜像并打包

root@ip-172-31-21-94:~/image# ./rancher-save-images.sh -h
USAGE: ./rancher-save-images.sh [--image-list rancher-images.txt] [--images rancher-images.tar.gz] [--from-aliyun true]
[-l|--image-list path] text file with list of images; one image per line.
[-i|--images path] tar.gz generated by docker save.
[--from-aliyun true|false] get an image from aliyun
[-h|--help] Usage message
root@ip-172-31-21-94:~/image#
root@ip-172-31-21-94:~/image# ./rancher-save-images.sh --from-aliyun true
Image pull success: registry.cn-hangzhou.aliyuncs.com/rancher/busybox
Image pull success: registry.cn-hangzhou.aliyuncs.com/rancher/backup-restore-operator:v1.0.4-rc4
Image pull success: registry.cn-hangzhou.aliyuncs.com/rancher/cis-operator:v1.0.4
Image pull success: registry.cn-hangzhou.aliyuncs.com/rancher/configmap-reload:v0.3.0-rancher4
Image pull success: registry.cn-hangzhou.aliyuncs.com/rancher/coredns-coredns:1.6.2
...


从以上日志中可以看出使用 --from-aliyun true 指定了从阿里云镜像仓库拉取镜像,速度比从 dockerhub 拉镜像快了 N 倍。

脚本执行成功后会在当前目录生成 rancher-images.tar.gz 的镜像压缩包。

3、推送镜像到私有镜像库

这一步,你将使用脚本将文件 rancher-images.tar.gz 中的镜像上传到您自己的私有镜像库。

文件 rancher-images.txt 、 rancher-images.tar.gz 应该和 rancher-load-images.sh 脚本在同一目录下。

登录私有镜像库

docker login harbor.kingsd.top

推送镜像

./rancher-load-images.sh --registry harbor.kingsd.top

等待执行成功后,就可以在私有镜像仓库中看到所有 Rancher 需要的镜像已经上传完毕。

本文的操作步骤和Rancher官方文档的离线安装基本相同,只不过在本文中 rancher-save-images.sh 从 http://mirror.rancher.cn 下载,并且在执行 rancher-save-images.sh 时增加了 --from-aliyun true 参数来指定从阿里云镜像仓库下载。

希望通过这篇文章可以大大提升Rancher国内用户的离线安装体验,如果有任何Rancher相关的经验分享或是使用疑问欢迎扫描文末二维码加入技术交流群,和各位Rancher用户一起交流。
在这里插入图片描述

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK