想要备份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
Code for all: GitHub
欢迎关注微信公众号<南瓜慢说>,将持续为你更新...
Recommendations:
Cloud Native
Terraform
Container: Docker/Kubernetes
Spring Boot / Spring Cloud
Https
如何制定切实可行的计划并好好执行