1.考虑到国内网络pull部分镜像速度很慢,每次升级k8s集群后,对控制节点和工作节点各进行一次镜像备份,便于快速恢复
2.可以定期对工作节点镜像进行一次全备份
#!/bin/bash
#create backup_dir
BACKUP_DATE=`date '+%Y%m%d_%H%M%S'`
BACKUP_DIR="images_bakup/"$BACKUP_DATE
cd ~ && mkdir -p $BACKUP_DIR
cd $BACKUP_DIR
# docker save
docker images | grep -v REPOSITORY > /tmp/k8s-images.txt
cat /tmp/k8s-images.txt | while read line
do
echo $line
REPOSITORY=""
TAG=""
# REPOSITORY= echo $line | awk '{print $1}'
# TAG= echo $line | awk '{print $2}'
eval $(echo $line | awk '{printf("REPOSITORY=%s;TAG=%s",$1,$2)}')
image=$REPOSITORY":"$TAG
echo $image > /tmp/image.txt && sed -i "s/\//./g" /tmp/image.txt
filename=$(cat /tmp/image.txt) && rm -f /tmp/image.txt
docker save -o $filename".tar" $image
done
rm -f /tmp/k8s-images.txt