Offline saving and loading of Kubernetes images (very fast)

Posted by Sarahlmorrow on Tue, 17 Dec 2019 20:04:08 +0100

The image of Kubernetes can be saved offline to a file, and then loaded from the file to realize offline installation (very fast).

For the kubernetes version 1.12.1 image used here, the corresponding version number can be modified for other versions.

1. Save to file - Save Images

Use the docker save command to save docker images to a file, and the - o parameter indicates the filename.

  • Before running the following script, it is recommended to create a separate directory for the image file.

As follows:

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 ""

The above A * is the Kubernetes system image, and B * is the image of several commonly used expansion modules. If you need other images, just follow the above script.

Save to the file k8s-images-save.sh and execute.

2. Copy images

Use USB flash disk or network or other network to transfer images to any place.

3. Load Images from file

Use the docker load command to load docker images from a file, and the - i parameter indicates the source filename. As follows:

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 "==================================================================="

Save as the file k8s-images-load.sh, and execute.

4. More follow-up operations

Topics: Docker Kubernetes sudo github