script backup namespace,deployment etc.. from kubernetes

2/12/2019

I'm looking for a bash script that could backup all the kubernetes in a yaml format or json it's good too:) I already backup the kubernetes conf files already.

/etc/kubernetes
/etc/systemd/system/system/kubelet.service.d

etc...

Now I'm just looking to save the

namespaces

deployment

etc...

-- morla
bash
google-kubernetes-engine
kubernetes
shell

2 Answers

2/12/2019

try the below command. you can include all the namespaces that you want to backup

mkdir -p /root/k8s-backup

kubectl cluster-info dump --namespaces default,kube-system  --output-directory=/root/k8s-backup
-- P Ekambaram
Source: StackOverflow

2/12/2019

You can dump your entire cluster info into one file using:

kubectl cluster-info dump > cluster_dump.txt

The above command will dump all the yaml and container logs into one file

Or if you just want yaml files, you can write a script of some commands which includes

kubectl get deployment -o yaml > deployment.yaml
kubectl get statefulset -o yaml > statefulset.yaml
kubectl get daemonset -o yaml > daemonset.yaml

Then you have to keep the namespace also in mind while creating the script. This gives you fair idea what to do

-- Prafull Ladha
Source: StackOverflow