Last active
January 24, 2024 08:35
-
-
Save jim80net/cd27985d72301a9344072b574142aa39 to your computer and use it in GitHub Desktop.
Revisions
-
jim80net revised this gist
Nov 20, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ # Prerequisites: # [GNU Parallel](https://www.gnu.org/software/parallel/) # [kubectl-neat](https://github.com/itaysk/kubectl-neat) # [mikefarah/yq](https://github.com/mikefarah/yq) # -
jim80net created this gist
Nov 20, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ # Prerequisites: # [kubectl-neat](https://github.com/itaysk/kubectl-neat) # [mikefarah/yq](https://github.com/mikefarah/yq) # # Usage: # - Copy and paste the below into your active shell session. Alternatively, add to your shell initialization scripts. # - kubectl_export <namespace> # The folder structure will be created: <namespace>/<kind>/<resource_name>.yaml # # Inspired from https://www.studytonight.com/post/how-to-list-all-resources-in-a-kubernetes-namespace function kubectl_export { NAMESPACE=${1:?"Supply a namespace with this command"} mkdir -p $NAMESPACE kubectl api-resources --verbs=list --namespaced -o name | grep -v "events.events.k8s.io" | grep -v "events" | sort | uniq | parallel --tag --env NAMESPACE -- '\ kubectl get {} -n '$NAMESPACE' 2>&1 | grep -vq "No resources found in '$NAMESPACE' namespace" && \ mkdir -p '$NAMESPACE'/{} && \ kubectl neat get -- {} -n '$NAMESPACE' --ignore-not-found -o yaml | yq --split-exp "\"'$NAMESPACE'/{}/\" + .metadata.name" ".items[]" ' } export -f kubectl_export