Skip to content

Instantly share code, notes, and snippets.

@kevinsimper
Last active May 3, 2024 09:54
Show Gist options
  • Save kevinsimper/e5fc695ab9e93eb6b354e0386b4b4509 to your computer and use it in GitHub Desktop.
Save kevinsimper/e5fc695ab9e93eb6b354e0386b4b4509 to your computer and use it in GitHub Desktop.
kubectl get — no-headers secret | awk '{print $1}' | \
xargs -I{} sh -c 'kubectl get secret -o yaml "$1" > "$1.yaml"' — {}
@Skitionek
Copy link

Skitionek commented Feb 26, 2020

If this command does not work, you might try this version:

kubectl get secret -A -o custom-columns=:.metadata.name,:.metadata.namespace --no-headers | 
xargs  -n 2 sh -c '(kubectl get secret -n $3 -o yaml $2; echo "---") >> $2.yaml' -- {}

It:

  • doesn't use left/right quotation marks
  • doesn't rely on the order of columns returned by kubectl get
  • get secrets in all namespaces
  • aggregate secrets with same name but from different namespaces as separate documents in same file (use '---')

cons:

  • it always append to files so you need to manually delete them if you are calling it again

@tp-drosssmith
Copy link

thanks for this time saving one liner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment