<p>I am using Kubernetes to deploy all my microservices provided by Azure Kubernetes Services.</p>

<p>Whenever I release an update of my microservice which is getting frequently from last one month, it pulls the new image from the Azure Container Registry.</p>

<p>I was trying to figure out where do these images reside in the cluster? </p>

<p>Just like Docker stores, the pulled images in /var/lib/docker &amp; since the Kubernetes uses Docker under the hood may be it stores the images somewhere too.</p>

<p>But if this is the case, how can I delete the old images from the cluster that are not in use anymore?</p>

<p>Clusters with Linux node pools created on Kubernetes v1.19 or greater default to containerd for its container runtime (<a href="https://learn.microsoft.com/en-us/azure/aks/cluster-configuration#container-runtime-configuration" rel="nofollow noreferrer">Container runtime configuration</a>).</p>
<p>To manually remove unused images on a node running containerd:</p>
<p>Identity node names:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl get nodes
</code></pre>
<p>Start an interactive debugging container on a node (<a href="https://learn.microsoft.com/en-us/azure/aks/ssh" rel="nofollow noreferrer">Connect with SSH to Azure Kubernetes Service</a>):</p>
<pre class="lang-sh prettyprint-override"><code>kubectl debug node/aks-agentpool-11045208-vmss000003 -it --image=mcr.microsoft.com/aks/fundamental/base-ubuntu:v0.0.11
</code></pre>
<p>Setup <code>crictl</code> on the debugging container (<a href="https://github.com/kubernetes-sigs/cri-tools/releases" rel="nofollow noreferrer">check for newer releases of crictl</a>):</p>
<blockquote>
<p>The host node's filesystem is available at <code>/host</code>, so configure <code>crictl</code> to use the host node's <code>containerd.sock</code>.</p>
</blockquote>
<pre class="lang-sh prettyprint-override"><code>curl -sL https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.23.0/crictl-v1.23.0-linux-amd64.tar.gz | tar xzf - -C /usr/local/bin \
    &amp;&amp; export CONTAINER_RUNTIME_ENDPOINT=unix:///host/run/containerd/containerd.sock IMAGE_SERVICE_ENDPOINT=unix:///host/run/containerd/containerd.sock
</code></pre>
<p>Remove unused images on the node:</p>
<pre class="lang-sh prettyprint-override"><code>crictl rmi --prune
</code></pre>
