Kubernetes镜像的离线保存和载入(非常快)

原创
2018/10/10 10:13
阅读数 4.6K

把Kubernetes的镜像离线保存到文件,然后从文件载入就可以实现离线安装了(非常快)。

这里使用的Kubernetes 1.12.1版本的镜像,其它版本修改对应的版本号即可。

1、保存到文件-Save Images

使用docker save命令来保存docker images到文件,-o 参数指示文件名。

  • 运行下面的脚本之前,建议为镜像文件建立一个单独的目录。

如下:

echo "==================================================================="
echo "Save Kubernetes images to tar."
echo "This tool created by https://my.oschina.net/u/2306127"
echo "Please visit https://github.com/openthings/kubernetes-tools"

echo "###################################################################"
echo "Kubernetes core system images."
echo "-------------------------------------------------------------------"

echo "A1.>> k8s.gcr.io/kube-apiserver:v1.12.1"
sudo docker save k8s.gcr.io/kube-apiserver:v1.12.1 -o A1-k8s-kube-apiserver-v1.12.1.tar
echo ""

echo "A2.>> k8s.gcr.io/kube-controller-manager:v1.12.1"
sudo docker save k8s.gcr.io/kube-controller-manager:v1.12.1 -o A2-k8s-kube-controller-manager-v1.12.1.tar
echo ""

echo "A3.>> k8s.gcr.io/kube-scheduler:v1.12.1"
sudo docker save k8s.gcr.io/kube-scheduler:v1.12.1 -o A3-k8s-kube-scheduler-v1.12.1.tar
echo ""

echo "A4.>> k8s.gcr.io/kube-proxy:v1.12.1"
sudo docker save k8s.gcr.io/kube-proxy:v1.12.1 -o A4-k8s-kube-proxy-v1.12.1.tar
echo ""

echo "A5.>> k8s.gcr.io/pause:3.1"
sudo docker save k8s.gcr.io/pause:3.1 -o A5-k8s-pause-3.1.tar
echo ""

echo "A6.>> k8s.gcr.io/etcd:3.2.24"
sudo docker save k8s.gcr.io/etcd:3.2.24 -o A6-k8s-etcd-3.2.24.tar
echo ""

echo "A7.>> k8s.gcr.io/coredns:1.2.2"
sudo docker save k8s.gcr.io/coredns:1.2.2 -o A7-k8s-coredns-1.2.2.tar
echo ""

echo "==================================================================="
echo "B1.>> quay.io/coreos/flannel:v0.10.0-amd64"
sudo docker save quay.io/coreos/flannel:v0.10.0-amd64 -o B1-flannel-v0.10.0.tar
echo ""

echo "B2.>> k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0"
sudo docker save k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0 -o B2-dashboard-v1.10.0.tar
echo ""

echo "B3.>> gcr.io/kubernetes-helm/tiller:v2.11.0"
sudo docker save gcr.io/kubernetes-helm/tiller:v2.11.0 -o B3-helm-tiller-v2.11.0.tar 
echo ""

echo "B4.>> quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.14.0"
sudo docker save quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.14.0 -o B4-ingress-controller-0.14.0.tar
echo ""

echo "B5.>> k8s.gcr.io/defaultbackend:1.3"
sudo docker save k8s.gcr.io/defaultbackend:1.3 -o B5-k8s-defaultbackend-1.3.tar
echo ""

echo "==================================================================="
echo "Save kubernetes images Finished."
echo "This tool created by https://my.oschina.net/u/2306127"
echo "Please visit https://github.com/openthings/kubernetes-tools"
echo "==================================================================="
echo ""

上面的A*为Kubernetes系统镜像,B*为几个常用的扩展模块的镜像。如果还需要其它镜像,仿照上面编写脚本即可。

保存为文件k8s-images-save.sh,然后执行。

2、复制 images

使用U盘或网络或者其它网络,传送images到任何地方。

3、从文件载入-Load Images

使用docker load命令来从文件载入docker images,-i 参数指示源文件名。如下:

echo "==================================================================="
echo "Load Kubernetes images from tar."
echo "This tool created by https://my.oschina.net/u/2306127"
echo "Please visit https://github.com/openthings/kubernetes-tools"

echo "###################################################################"
echo "Kubernetes core system images."
echo "-------------------------------------------------------------------"

echo "A1<< k8s.gcr.io/kube-apiserver:v1.12.1"
sudo docker load -i A1-k8s-kube-apiserver-v1.12.1.tar
echo ""

echo "A2<< k8s.gcr.io/kube-controller-manager:v1.12.1"
sudo docker load -i A2-k8s-kube-controller-manager-v1.12.1.tar
echo ""

echo "A3<< k8s.gcr.io/kube-scheduler:v1.12.1"
sudo docker load -i A3-k8s-kube-scheduler-v1.12.1.tar
echo ""

echo "A4<< k8s.gcr.io/kube-proxy:v1.12.1"
sudo docker load -i A4-k8s-kube-proxy-v1.12.1.tar
echo ""

echo "A5<< k8s.gcr.io/pause:3.1"
sudo docker load -i A5-k8s-pause-3.1.tar
echo ""

echo "A6<< k8s.gcr.io/etcd:3.2.24"
sudo docker load -i A6-k8s-etcd-3.2.24.tar
echo ""

echo "A7<< k8s.gcr.io/coredns:1.2.2"
sudo docker load -i A7-k8s-coredns-1.2.2.tar
echo ""

echo "==================================================================="
echo "B1<< quay.io/coreos/flannel:v0.10.0-amd64"
sudo docker load -i B1-flannel-v0.10.0.tar
echo ""

echo "B2<< k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0"
sudo docker load -i B2-dashboard-v1.10.0.tar
echo ""

echo "B3<< gcr.io/kubernetes-helm/tiller:v2.11.0"
sudo docker load -i B3-helm-tiller-v2.11.0.tar 
echo ""

echo "B4<< quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.14.0"
sudo docker load -i B4-ingress-controller-0.14.0.tar
echo ""

echo "B5<< k8s.gcr.io/defaultbackend:1.3"
sudo docker load -i B5-k8s-defaultbackend-1.3.tar
echo ""

echo "==================================================================="
echo "Load kubernetes images Finished."
echo "This tool created by https://my.oschina.net/u/2306127"
echo "Please visit https://github.com/openthings/kubernetes-tools"
echo "==================================================================="

保存为文件k8s-images-load.sh,然后执行。

4、更多后续操作

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部