Tomasz
Tomasz

Reputation: 5162

List all pulled docker images from k8s worker node

I have EKS Cluster with three worker nodes. Now I would like to list all pulled docker images, how can I do it?

I searched across documentation and couldn't find any direct way to access it. I could possibly attach key pair for worker node and try to ssh to it, but I would like to avoid that.

Upvotes: 5

Views: 5516

Answers (3)

devops-admin
devops-admin

Reputation: 2003

inside the workerNode run the below command if containerd is the runtime engine of the kubernetes cluster.

sudo crictl images list
OR
crictl images list

###########EXMAPLE OUTPUT########
root@kind-control-plane:/# crictl images list
IMAGE                                           TAG                  IMAGE ID            SIZE
docker.io/kennethreitz/httpbin                  latest               b138b9264903f       214MB
docker.io/kindest/kindnetd                      v20240202-8f1494ea   4950bb10b3f87       27.8MB
docker.io/kindest/local-path-helper             v20230510-486859a6   be300acfc8622       3.05MB
docker.io/kindest/local-path-provisioner        v20240202-8f1494ea   0500518ebaa68       19.4MB
ghcr.io/solo-io/gloo-gateway/glood              2.0.0-beta1          948aab2071390       55.4MB
registry.k8s.io/coredns/coredns                 v1.11.1              cbb01a7bd410d       18.2MB
registry.k8s.io/etcd                            3.5.10-0             a0eed15eed449       56.6MB
registry.k8s.io/kube-apiserver-amd64            v1.29.2              a2336270923ab       86.2MB
registry.k8s.io/kube-apiserver                  v1.29.2              a2336270923ab       86.2MB
registry.k8s.io/kube-controller-manager-amd64   v1.29.2              21704b3a9676f       80.3MB
registry.k8s.io/kube-controller-manager         v1.29.2              21704b3a9676f       80.3MB
registry.k8s.io/kube-proxy-amd64                v1.29.2              95d40da343e92       83.5MB
registry.k8s.io/kube-proxy                      v1.29.2              95d40da343e92       83.5MB
registry.k8s.io/kube-scheduler-amd64            v1.29.2              f60003f4b3479       60.6MB
registry.k8s.io/kube-scheduler                  v1.29.2              f60003f4b3479       60.6MB
registry.k8s.io/pause                           3.7                  221177c6082a8       311kB

Upvotes: 3

victortv
victortv

Reputation: 8942

I made a python script that parses the output of kubectl get node -o json and displays in a format similar to docker images, but only with the fields repository, tag and size (missing image_id and created).

#!/usr/bin/python
# Usage: kubectl get node [optional: name of node] -o json | python k8s_node_images.py
import sys
import json
data = json.load(sys.stdin)
try:
    nodes = data['items']
except KeyError:
    nodes = [data]
for node in nodes:
    node_name = node['metadata']['name']
    print("\nNODE {}".format(node_name))
    print("REPOSITORY".ljust(48)+"  "+TAG".ljust(16)+"  "+SIZE")
    images = node['status']['images']
    for image in images:
        if len(image['names'])<2:
            continue
        names = image['names'][1].rsplit(":",1)
        name = names[0]
        tag = names[1]
        size = image['sizeBytes']
        size_mb = "{0:.1f}MB".format(size/1000000.)
        print(name.ljust(48)+"  "+tag.ljust(16)+"  "+size_mb)

In my tests, the output shows the same repositories as running docker images on each node (my older images are present).

Upvotes: 2

FL3SH
FL3SH

Reputation: 3328

For all nodes

kubectl get node  -o json | jq -r '.items[].status.images[].names'

For 'worker-node'

kubectl get node worker-node -o json | jq -r '.status.images[].names'

Upvotes: 5

Related Questions