LarryDpk
发布于 2020-08-09 / 3363 阅读
0

Kubernetes备份所有集群中的资源为yaml文件

想要备份Kubernetes集群上的所有资源为yaml文件,以便随时恢复或部署到其它集群。

准备以下脚本为backup.sh

for n in $(kubectl get -o=name pvc,configmap,serviceaccount,secret,ingress,service,deployment,statefulset,hpa,job,cronjob)
do
    mkdir -p $(dirname $n)
    kubectl get -o=yaml --export $n > $n.yaml
done

注意新版本的Kubernetes不再支持--export,去掉即可。
然后执行该脚本即可:

sh backup.sh

备份完会创建对应目录放yaml文件:

$ tree

参考资料:

Is there a way to generate yml files that will produce the existing cluster