Skip to content

Instantly share code, notes, and snippets.

@thomaschaplin
Created February 26, 2025 14:16
Show Gist options
  • Select an option

  • Save thomaschaplin/dc9fd574a4dc8b6165083a548e7473cb to your computer and use it in GitHub Desktop.

Select an option

Save thomaschaplin/dc9fd574a4dc8b6165083a548e7473cb to your computer and use it in GitHub Desktop.
Unused CRD Detector for Kubernetes

Unused CRD Detector for Kubernetes

This script lists all Custom Resource Definitions (CRDs) in a Kubernetes cluster and checks how many instances exist for each CRD. It only prints CRDs that have at least one instance.

Prerequisites

  • kubectl
  • jq

Usage

Run the following command in a terminal:

kubectl get crds -o json | jq -r '.items[].metadata.name' | while read crd; do                                                                                                                 
    count=$(kubectl get "$crd" --no-headers 2>/dev/null | wc -l)
    if [ "$count" -gt 0 ]; then
        echo "$crd: $count"
    fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment