Skip to content

Instantly share code, notes, and snippets.

Last active March 6, 2024 23:18
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Kevinrob/4c7f1e5dbf6ce4e94d6ba2bfeff37aeb to your computer and use it in GitHub Desktop.
Save Kevinrob/4c7f1e5dbf6ce4e94d6ba2bfeff37aeb to your computer and use it in GitHub Desktop.
Clean up microk8s registry
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' \

kubectl get pods --namespace="container-registry"
kubectl exec -it --namespace="container-registry" registry-... bash
bin/registry garbage-collect /etc/docker/registry/config.yml

Copy link

Kevinrob commented Jul 7, 2020

Does this remove all the images in microk8s registry ?
I still see all of the images in it.

Yes, it should 👍
Do you have any errors when running it?

Copy link

jmastr commented Apr 26, 2022


$ microk8s disable registry
$ microk8s disable storage:destroy-storage
$ microk8s enable registry 

Disable registry:

$ microk8s disable registry                                                                                                            
Disabling the private registry                                                                                                                                                                                  
namespace "container-registry" deleted                                                                                                                                                                          
persistentvolumeclaim "registry-claim" deleted                                                                                                                                                                  
deployment.apps "registry" deleted                                                                                                                                                                              
service "registry" deleted                                                                                                                                                                                      
configmap "local-registry-hosting" deleted                                                                                                                                                                      
configmap/local-registry-hosting created
The registry is disabled. Use 'microk8s disable storage:destroy-storage' to free the storage space.

Free the storage space:

$ microk8s disable storage:destroy-storage                                                                                             
Disabling default storage
deployment.apps "hostpath-provisioner" deleted "microk8s-hostpath" deleted
serviceaccount "microk8s-hostpath" deleted "microk8s-hostpath" deleted "microk8s-hostpath" deleted
Storage removed
Storage space reclaimed

Recreate registry again:

$ microk8s enable registry                                                                                                             
The registry will be created with the default size of 20Gi.
You can use the "size" argument while enabling the registry, eg microk8s.enable registry:size=30Gi
Enabling default storage class
deployment.apps/hostpath-provisioner created created
serviceaccount/microk8s-hostpath created created created
Storage will be available soon
Applying registry manifest
namespace/container-registry created
persistentvolumeclaim/registry-claim created
deployment.apps/registry created
service/registry created
configmap/local-registry-hosting configured
The registry is enabled

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