In order to save all manifests, create a BASH script by running:

nano 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 a+x ./k8s.sh

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

Speak with an expert on our team to discuss Cloud solutions tailored to your business.

You’ll receive free recommendations tailored to your business.