Skip to content

Instantly share code, notes, and snippets.

@patrickshan
Created August 16, 2022 11:10
Show Gist options
  • Save patrickshan/e431dc2ef90ed1e8a4d15029a341a908 to your computer and use it in GitHub Desktop.
Save patrickshan/e431dc2ef90ed1e8a4d15029a341a908 to your computer and use it in GitHub Desktop.
Find and print out namespace and pod name for all naked pods in a Kubernete cluster
kubectl get pods -A -ojson | jq -c '.items[] | select(.metadata.ownerReferences == null) | "\(.metadata.namespace) => \(.metadata.name)"'
@patrickshan
Copy link
Author

backup all the naked pods specs after filtering out some fields:

kubectl get pods -A -oyaml | yq '.items[] | select(.metadata | has("ownerReferences") | not) | split_doc' | yq 'del(.status, .metadata.uid, .metadata.resourceVersion, .metadata.creationTimestamp, .metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")'

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