Skip to content

Instantly share code, notes, and snippets.

@zAbuQasem
Created January 2, 2026 15:59
Show Gist options
  • Select an option

  • Save zAbuQasem/64fc91c583239a4748156f00578ca97f to your computer and use it in GitHub Desktop.

Select an option

Save zAbuQasem/64fc91c583239a4748156f00578ca97f to your computer and use it in GitHub Desktop.
List all resources in a namespace
k8s_list_ns_apis() {
local ns="$1"
# If no namespace provided, use fzf to pick from all namespaces
if [[ -z "$ns" ]]; then
ns="$(
kubectl get ns \
-o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \
| fzf --prompt='Namespaces > ' --height=10 --reverse
)"
if [[ -z "$ns" ]]; then
echo "No namespace selected, aborting." >&2
return 1
fi
fi
echo "Listing API resources that have objects in namespace: $ns" >&2
kubectl api-resources --verbs=list --namespaced -o name \
| while read -r r; do
# If there is at least one object of this resource type in the namespace, print it
if kubectl -n "$ns" get "$r" --ignore-not-found -o name 2>/dev/null | grep -q .; then
echo "$r"
fi
done \
| sort -u
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment