Kubernetes – Save all manifest of an existing cluster

 

To save all manifests, create a BASH script:

vim k8s.sh

 

With the following contents:

#!/bin/bash

DIR='k8s-manifests/namespaces'

mkdir -p $DIR

for NAMESPACE in $(kubectl get -o=name namespaces | cut -d '/' -f2)
do
	for TYPE in $(kubectl get -n $NAMESPACE -o=name pvc,configmap,serviceaccount,secret,ingress,service,deployment,statefulset,hpa,job,cronjob)
	do
	    mkdir -p $(dirname $DIR/$NAMESPACE/$TYPE)
	    kubectl get -n $NAMESPACE -o=yaml $TYPE > $DIR/$NAMESPACE/$TYPE.yaml
	done
done

 

Add the execution bit and run it:

chmod +x k8s.sh
./k8s.sh

 

After executing in the current directory in the folder "k8s-manifests" will be saved all manifests ordered by namespaces and types.

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments