Last active
November 24, 2021 09:59
-
-
Save tanelmae/d09899288b6f4ee20c7f9cf8b3bc91d4 to your computer and use it in GitHub Desktop.
Kubernetes ingress report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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