Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattmattox/6fd74b9f857ebbdcc29a167f46e9b591 to your computer and use it in GitHub Desktop.
Save mattmattox/6fd74b9f857ebbdcc29a167f46e9b591 to your computer and use it in GitHub Desktop.

Revisions

  1. mattmattox created this gist May 26, 2022.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/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

    mkdir -p clusterobjects
    for clusterobject in `kubectl api-resources --verbs=list --namespaced=false -o name`
    do
    echo "Cluster Object: $clusterobject"
    mkdir -p clusterobjects/"$clusterobject"
    for clusteritem in `kubectl get $clusterobject -o name | awk -F '/' '{print $2}'`
    do
    echo "Cluster Item: $clusteritem"
    kubectl get $clusterobject $clusteritem -o yaml > clusterobjects/"$clusterobject"/"$clusteritem".yaml
    done
    done