Skip to content

Instantly share code, notes, and snippets.

@jenrik
Last active February 1, 2025 12:03
Show Gist options
  • Save jenrik/81bf4ceb0d6cd549af946383850b6950 to your computer and use it in GitHub Desktop.
Save jenrik/81bf4ceb0d6cd549af946383850b6950 to your computer and use it in GitHub Desktop.
List all resources, including custom resources, in a Kubernetes namespace
#!/bin/sh
set -e
NAMESPACE="$1"
if [ "${NAMESPACE}x" = "x" ]; then
echo "usage: $(basename "$0") <namespace>" >&2
exit 1
fi
kubectl api-resources --namespaced -o name | while read -r resource; do
if [ "$(kubectl -n "$NAMESPACE" get -o go-template='{{ len .items }}' "$resource" 2>/dev/null)" -gt 0 ]; then
echo "$(tput bold)Resource:$(tput sgr0) $resource"
kubectl -n "$NAMESPACE" get "$resource"
echo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment