Skip to content

Instantly share code, notes, and snippets.

@davidalger
Last active April 8, 2021 07:14
Show Gist options
  • Save davidalger/e500dc8e5f0e642a30e8f21caef74406 to your computer and use it in GitHub Desktop.
Save davidalger/e500dc8e5f0e642a30e8f21caef74406 to your computer and use it in GitHub Desktop.
List all non-Google/GKE/k8s/Stackdriver images in a cluster using fully qualified names and without tags.
#!/usr/bin/env bash
kubectl get all --all-namespaces -o yaml \
| grep \ image: \
| egrep -iv 'image:\ sha256|(gke|k8s)\.gcr\.io|gcr\.io/(gke|google|stackdriver|kubernetes)-.*' \
| perl -pe 's#^[\W-]+image:\W+([^\@:]+)([:@].+)?$#$1#i' \
| perl -pe 's#^([a-z0-9-_]+)$#docker.io/library/$1#i' \
| perl -pe 's#^([a-z0-9-_/]+)$#docker.io/$1#i' \
| sort -n | uniq
@davidalger
Copy link
Author

To install for use with Krew:

curl -s https://gist.githubusercontent.com/davidalger/e500dc8e5f0e642a30e8f21caef74406/raw/kubectl-list_images \
    > /usr/local/bin/kubectl-list_images

chmod +x /usr/local/bin/kubectl-list_images

To run it:

kubectl list-images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment