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.
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'
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).