skip to Main Content

I’m getting a low disk space warning on a server where my microk8s and applications are installed. When I run the microk8s ctr image ls command, multiple images appear for an application. Does the "docker image prune -f" command in Docker have an equivalent in microk8s? Or is there a way possible?

3

Answers


  1. If you want to delete all custom added images from the built-in library, you can do this:

    # get all images that start with localhost:32000, output the results into image_ls file
    sudo microk8s ctr images ls name~='localhost:32000' | awk {'print $1'} > image_ls 
    # loop over file, remove each image
    cat image_ls | while read line || [[ -n $line ]];
    do
        microk8s ctr images rm $line
    done;
    

    Put it into a .sh file and run the script

    Login or Signup to reply.
  2. You can use crictl to prune unused images since crictl is compatible with containerd

    1. Install crictl using this https://github.com/kubernetes-sigs/cri-tools/blob/edf14e37007994d69f9b8cb3b1483a79b365b8eb/docs/crictl.md#install-crictl
    2. Check if crictl is working using microk8s containerd
      sudo crictl --runtime-endpoint unix:///var/snap/microk8s/common/run/containerd.sock images
    3. To prune unused image sudo crictl --runtime-endpoint unix:///var/snap/microk8s/common/run/containerd.sock rmi --prune

    The docs said that you can also use CONTAINER_RUNTIME_ENDPOINT but I can’t to get that working.

    Update:
    You can also use config file, add below to /etc/crictl.yaml:

    runtime-endpoint: unix:///var/snap/microk8s/common/run/containerd.sock
    
    Login or Signup to reply.
  3. A one liner:

    sudo microk8s ctr i ls name~='localhost:32000' -q|while read z;do sudo microk8s ctr i rm $z;done
    

    You can remove the filter name~='localhost:32000' or use it to match specific tag you want to clean up, example: name~=':v5.2.0'.

    NOTE: If no filter is specified, all local images will be removed

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search