Skip to content

Instantly share code, notes, and snippets.

@lhotari
Forked from Kevinrob/clean.md
Created April 21, 2021 04:02
Show Gist options
  • Save lhotari/bf249e2127ae34c403665ff2d0a47bfe to your computer and use it in GitHub Desktop.
Save lhotari/bf249e2127ae34c403665ff2d0a47bfe to your computer and use it in GitHub Desktop.
Clean up microk8s registry
#!/bin/bash
registry=localhost:32000
repositories=$(curl ${registry}/v2/_catalog)
for repo in $(echo "${repositories}" | jq -r '.repositories[]'); do
echo $repo
tags=$(curl -sSL "http://${registry}/v2/${repo}/tags/list" | jq -r '.tags[]')
for tag in $tags; do
echo $tag
curl -v -sSL -X DELETE "http://${registry}/v2/${repo}/manifests/$(
curl -sSL -I \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"http://${registry}/v2/${repo}/manifests/$tag" \
| awk '$1 == "Docker-Content-Digest:" { print $2 }' \
| tr -d $'\r' \
)"
done
done
kubectl exec -it --namespace="container-registry" $(kubectl get pods --namespace="container-registry" -o name) -- \
bash -c "bin/registry garbage-collect /etc/docker/registry/config.yml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment