Skip to content

Instantly share code, notes, and snippets.

@mattmattox
Created March 16, 2022 22:39
Show Gist options
  • Save mattmattox/73f6949fe1ecdf7644422ce69f0b2e0f to your computer and use it in GitHub Desktop.
Save mattmattox/73f6949fe1ecdf7644422ce69f0b2e0f to your computer and use it in GitHub Desktop.
Dump all namespaced scoped k8s objects for all namespaces
#!/bin/bash
objects=`kubectl api-resources --verbs=list --namespaced -o name`
for namespace in `kubectl get ns -o name | awk -F '/' '{print $2}'`
do
echo "Namespace: $namespace"
mkdir -p namespace/"$namespace"
for object in $objects
do
mkdir -p namespace/"$namespace"/"$object"
echo "Object: $object"
for item in `kubectl -n $namespace get $object -o name | awk -F '/' '{print $2}'`
do
echo "item: $item"
kubectl -n $namespace get $object $item -o yaml > namespace/"$namespace"/"$object"/"$item".yaml
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment