List All Container Images Running in a Cluster

    You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as control plane hosts. If you do not already have a cluster, you can create one by using or you can use one of these Kubernetes playgrounds:

    To check the version, enter .

    List all Container images in all namespaces

    • Fetch all Pods in all namespaces using kubectl get pods --all-namespaces
    • Format the output to include only the list of Container image names using -o jsonpath={.items[*].spec.containers[*].image}. This will recursively parse out the image field from the returned json.
      • See the for further information on how to use jsonpath.
    • Format the output using standard tools: tr, sort,
      • Use tr to replace spaces with newlines
      • Use uniq to aggregate image counts

    The jsonpath is interpreted as follows:

    • .items[*]: for each returned value
    • .spec: get the spec
    • : for each container
    • .image: get the image

    Note: When fetching a single Pod by name, for example kubectl get pod nginx, the .items[*] portion of the path should be omitted because a single Pod is returned instead of a list of items.

    List Container images filtering by Pod label

    To target only Pods matching a specific label, use the -l flag. The following matches only Pods with labels matching app=nginx.

    To target only pods in a specific namespace, use the namespace flag. The following matches only Pods in the namespace.

    List Container images using a go-template instead of jsonpath

    • Jsonpath reference guide
    • reference guide