Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we see cached images in kubernetes?

I am using kops as kubernetes deployment.

I noticed that whenever an image with same tag number is entered in deployment file the system takes the previous image if imagepullpolicy is not set to always

Is there any way in which I can see all the cached images of a container in kubernetes environment ?

Like suppose I have an image test:56 currently running in a deployment and test:1 to test:55 were used previously, so does kubernetes cache those images ? and if yes where can those be found ?

like image 457
Shahid ali Khan Avatar asked Mar 20 '20 13:03

Shahid ali Khan


People also ask

Does k8s cache images?

Kubernetes itself doesn't cache the images, it is the underlying OCI runtime that does the caching.

Are Docker images cached?

The concept of Docker images comes with immutable layers. Every command you execute results in a new layer that contains the changes compared to the previous layer. All previously built layers are cached and can be reused.

Where are Docker images stored in Kubernetes?

If you use the default storage driver overlay2, then your Docker images are stored in /var/lib/docker/overlay2 . There, you can find different files that represent read-only layers of a Docker image and a layer on top of it that contains your changes.


1 Answers

  • Comments on your environment:

    I noticed that whenever an image with same tag number is entered in deployment file the system takes the previous image if imagepullpolicy is not set to always

A pre-pulled image can be used to preload certain images for speed or as an alternative to authenticating to a private registry, optimizing performance.

The docker will always cache all images that were used locally.

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 your Cloud Provider Registry or a local registry.

  • Let's address your first question:

    Is there any way in which I can see all the cached images of a container in kubernetes environment ?

Yes, you must use docker images to list the images stored in your environment.

  • Second question:

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

I prepared an example for you:

  • I deployed several pods based on the official busybox image:
$ 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

Now let's check the images stored in docker images

$ 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

You can see all the pushed images listed.

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

If you have any doubt, let me know in the comments.

like image 184
Will R.O.F. Avatar answered Sep 20 '22 14:09

Will R.O.F.