Skip to content

Instantly share code, notes, and snippets.

@tanelmae
Last active November 24, 2021 09:59
Show Gist options
  • Save tanelmae/d09899288b6f4ee20c7f9cf8b3bc91d4 to your computer and use it in GitHub Desktop.
Save tanelmae/d09899288b6f4ee20c7f9cf8b3bc91d4 to your computer and use it in GitHub Desktop.
Kubernetes ingress report
# Lists:
# - number of ingresses
# - number of ingress classes used
# - ingress classes used
# - ingresses without explicit ingress class with name and namespace
# - ingresses by class with name and namespace
# Dependencies: kubectl, jq
function ingress-report() {
echo "Loading ingresses from the cluster"
local INGRESSES=$(kubectl get ingresses -o json --all-namespaces)
echo "Total number of ingress resources: $(echo $INGRESSES | jq '.items | length')"
echo "Classes in use (includes implicit class): $(echo $INGRESSES | jq -r '[.items[].metadata.annotations["kubernetes.io/ingress.class"]] | unique | length')"
echo "-----------------------------------"
echo "Ingresses without an explicit class:"
echo $INGRESSES | jq -r '.items | map(select(.metadata.annotations["kubernetes.io/ingress.class"] == null)) | .[] | " - namespace: \(.metadata.namespace), name: \(.metadata.name)"'
for i in $(echo $INGRESSES | jq -r '[.items[].metadata.annotations["kubernetes.io/ingress.class"]] | unique | .[]'); do
if [ $i == "null" ]; then
continue
fi
echo "-----------------------------------"
echo "Ingresses for class $i"
echo Count: $(echo $INGRESSES | jq --arg i $i -r '.items | map(select(.metadata.annotations["kubernetes.io/ingress.class"] == $i)) | length')
echo $INGRESSES | jq --arg i $i -r '.items | map(select(.metadata.annotations["kubernetes.io/ingress.class"] == $i )) | .[] | " - namespace: \(.metadata.namespace), name: \(.metadata.name)"'
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment