Skip to content

Instantly share code, notes, and snippets.

@Kevinrob
Last active March 6, 2024 23:18
Show Gist options
  • 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
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 get pods --namespace="container-registry"
kubectl exec -it --namespace="container-registry" registry-... bash
bin/registry garbage-collect /etc/docker/registry/config.yml

@misaacson
Copy link

Quick question: What is the $ doing in tr -d $'\r' \?

@Kevinrob
Copy link
Author

Quick question: What is the $ doing in tr -d $'\r' \?

@misaacson It's for removing new line character from awk output

@misaacson
Copy link

Quick question: What is the $ doing in tr -d $'\r' \?

@misaacson It's for removing new line character from awk output

Correct, though that can be done with just tr -d '\r', I was curious about the $ character specifically. It appears to work fine without it, so I was just wondering if I am missing something. Bash is probably my least used scripting language.

@Kevinrob
Copy link
Author

Quick question: What is the $ doing in tr -d $'\r' \?

@misaacson It's for removing new line character from awk output

Correct, though that can be done with just tr -d '\r', I was curious about the $ character specifically. It appears to work fine without it, so I was just wondering if I am missing something. Bash is probably my least used scripting language.

I don't really know 😁 I'm not an expert of Bash too 😅

@furqanbaqai
Copy link

Thanks, mate

@adharshmk96
Copy link

adharshmk96 commented Jun 19, 2020

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

@Kevinrob
Copy link
Author

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?

@jmastr
Copy link

jmastr commented Apr 26, 2022

TL;DR:

$ 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
storageclass.storage.k8s.io "microk8s-hostpath" deleted
serviceaccount "microk8s-hostpath" deleted
clusterrole.rbac.authorization.k8s.io "microk8s-hostpath" deleted
clusterrolebinding.rbac.authorization.k8s.io "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
storageclass.storage.k8s.io/microk8s-hostpath created
serviceaccount/microk8s-hostpath created
clusterrole.rbac.authorization.k8s.io/microk8s-hostpath created
clusterrolebinding.rbac.authorization.k8s.io/microk8s-hostpath 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