<p>I am using kops as kubernetes deployment.</p>
<p>I noticed that whenever an image with same tag number is entered in deployment file the system takes the previous image if <code>imagepullpolicy</code> is not set to <code>always</code></p>
<p>Is there any way in which I can see all the cached images of a container in kubernetes environment ?</p>
<p>Like suppose I have an image <code>test:56</code> currently running in a deployment and <code>test:1</code> to <code>test:55</code> were used previously, so does kubernetes cache those images ? and if yes where can those be found ?</p>

<ul>
<li><strong>Comments on your environment:</strong>

<blockquote>
  <p>I noticed that whenever an image with same tag number is entered in deployment file the system takes the previous image if  <code>imagepullpolicy</code>  is not set to  <code>always</code></p>
</blockquote></li>
</ul>

<p>A <a href="https://kubernetes.io/docs/concepts/containers/images/#pre-pulled-images" rel="nofollow noreferrer">pre-pulled image</a> can be used to preload certain images for speed or as an alternative to authenticating to a private registry, optimizing performance.</p>

<p>The docker will always cache all images that were used locally.</p>

<p>Since you are using EKS, keep in mind that if you have node health management (meaning a node will be replaced if it fails) the new node won't have the images cached from the old one so it's always a good idea to store your images on a Registry like <a href="https://kubernetes.io/docs/concepts/containers/images/#using-amazon-elastic-container-registry" rel="nofollow noreferrer">your Cloud Provider Registry</a> or a local registry.</p>

<ul>
<li><strong>Let's address your first question:</strong>

<blockquote>
  <p>Is there any way in which I can see all the cached images of a container in kubernetes environment ?</p>
</blockquote></li>
</ul>

<p>Yes, you must use <code>docker images</code> to list the images stored in your environment.</p>

<ul>
<li><strong>Second question:</strong>

<blockquote>
  <p>Like suppose I have an image <code>test:56</code> currently running in a deployment and <code>test:1</code> to <code>test:55</code> were used previously, so does Kubernetes cache those images ? and if yes where can those be found ?</p>
</blockquote></li>
</ul>

<p>I prepared an example for you:</p>

<ul>
<li>I deployed several pods based on the official busybox image:</li>
</ul>

<pre><code>$ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.28.4
pod/busy284 created
$ kubectl run busy293 --generator=run-pod/v1 --image=busybox:1.29.3
pod/busy284 created
$ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.28
pod/busy28 created
$ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.29
pod/busy29 created
$ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.30
pod/busy284 created
$ kubectl run busybox --generator=run-pod/v1 --image=busybox
pod/busybox created
</code></pre>

<p>Now let's check the images stored in <code>docker images</code></p>

<pre><code>$ docker images
REPOSITORY                                TAG                   IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy                     v1.17.3               ae853e93800d        5 weeks ago         116MB
k8s.gcr.io/kube-controller-manager        v1.17.3               b0f1517c1f4b        5 weeks ago         161MB
k8s.gcr.io/kube-apiserver                 v1.17.3               90d27391b780        5 weeks ago         171MB
k8s.gcr.io/kube-scheduler                 v1.17.3               d109c0821a2b        5 weeks ago         94.4MB
kubernetesui/dashboard                    v2.0.0-beta8          eb51a3597525        3 months ago        90.8MB
k8s.gcr.io/coredns                        1.6.5                 70f311871ae1        4 months ago        41.6MB
k8s.gcr.io/etcd                           3.4.3-0               303ce5db0e90        4 months ago        288MB
kubernetesui/metrics-scraper              v1.0.2                3b08661dc379        4 months ago        40.1MB
busybox                                   latest                83aa35aa1c79        10 days ago         1.22MB
busybox                                   1.30                  64f5d945efcc        10 months ago       1.2MB
busybox                                   1.29                  758ec7f3a1ee        15 months ago       1.15MB
busybox                                   1.29.3                758ec7f3a1ee        15 months ago       1.15MB
busybox                                   1.28                  8c811b4aec35        22 months ago       1.15MB
busybox                                   1.28.4                8c811b4aec35        22 months ago       1.15MB
</code></pre>

<p>You can see all the pushed images listed.</p>

<p>It's good to clean old resources from your system using the command <code>docker system prune</code> to free space on your server from time to time. </p>

<p>If you have any doubt, let me know in the comments.</p>
