Skip to content

List All Container Images Running in a Cluster #27475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BahmaniAlireza opened this issue Apr 8, 2021 · 8 comments · Fixed by #28030
Closed

List All Container Images Running in a Cluster #27475

BahmaniAlireza opened this issue Apr 8, 2021 · 8 comments · Fixed by #28030
Assignees
Labels
needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@BahmaniAlireza
Copy link

BahmaniAlireza commented Apr 8, 2021

Hi,

I've tested this example :

      kubectl get pods --all-namespaces -o jsonpath="{..image}" |\
      tr -s '[[:space:]]' '\n' |\
      sort |\
      uniq -c

It returns image names double, because "{..image}" recursively search in the output of JSON, So at the first, it will find the "image" word in "spec.containers.image" and at the second time, it will find the "image" word in "containerStatuses.image".
It means you will see the image name two times for each pod at least.

Please change your example.

Best Regards,
Alireza Bahmani.

@k8s-ci-robot
Copy link
Contributor

@BahmaniAlireza: This issue is currently awaiting triage.

SIG Docs takes a lead on issue triage for this website, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 8, 2021
@sftim
Copy link
Contributor

sftim commented Apr 9, 2021

Hi @BahmaniAlireza

What's the URL of the page where you've seen a problem?

@Priyankasaggu11929
Copy link
Member

Priyankasaggu11929 commented May 18, 2021

@Priyankasaggu11929
Copy link
Member

The issue is, the following command produces 2 times (the count of image in a single pod).

As @BahmaniAlireza mentioned, it is because the command count both the occurrence from the spec & status sections from a single pod json manifest.

❯ kubectl get pods --all-namespaces -o jsonpath="{..image}" |tr -s '[[:space:]]' '\n' |sort |uniq -c
      6 quay.io/app-sre/deployment-validation-operator:latest
      2 quay.io/openshift-release-dev/ocp-release@sha256:c7e8f18e8116356701bd23ae3a23fb9892dd5ea66c8300662ef30563d7104f39
      8 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:02cbb763ee20ba10a2eb54cc18e6cc5848b69ac991fd9b5a513d0c8a8ecdae91
      6 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:03cd77cc134a7bfcaa14c111b76234749b9b8cb0986ab25e2fb2afeb0ba7fb6b
      4 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:055d8e5c8a106134bf725bdd542e544285b5cd10a5e1c7e02d527c50f81ef0f5
      2 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:06633a70761c391052f3f5e482731a8fbbcf70df6aa082b8de916e04d0101f98
     10 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:249b4e56b532da7bf19c91ec620694d708743712dc028d9466fc236a5adcc54d

Ideally it should be:

❯ kubectl get pods --all-namespaces -o jsonpath="{..image}" |tr -s '[[:space:]]' '\n' |sort |uniq -c
      3 quay.io/app-sre/deployment-validation-operator:latest
      1 quay.io/openshift-release-dev/ocp-release@sha256:c7e8f18e8116356701bd23ae3a23fb9892dd5ea66c8300662ef30563d7104f39
      4 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:02cbb763ee20ba10a2eb54cc18e6cc5848b69ac991fd9b5a513d0c8a8ecdae91
      3 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:03cd77cc134a7bfcaa14c111b76234749b9b8cb0986ab25e2fb2afeb0ba7fb6b
      2 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:055d8e5c8a106134bf725bdd542e544285b5cd10a5e1c7e02d527c50f81ef0f5
      1 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:06633a70761c391052f3f5e482731a8fbbcf70df6aa082b8de916e04d0101f98
     5 quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:249b4e56b532da7bf19c91ec620694d708743712dc028d9466fc236a5adcc54d

@Priyankasaggu11929
Copy link
Member

Following could be one of the fix for it:

      kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}"  |\
      tr -s '[[:space:]]' '\n' |\
      sort |\
      uniq -c

@ms-choudhary
Copy link
Contributor

/assign

@ms-choudhary
Copy link
Contributor

@Priyankasaggu11929 There are other references as well. These would return duplicate images as well, right? I've updated those as well for now.

kubectl get pods --namespace kube-system -o jsonpath="{..image}"

@Priyankasaggu11929
Copy link
Member

Hi @ms-choudhary,

yes, I feel those also need to be fixed. Let's wait for @sftim to provide their review. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants