Answers: <p>This depends on anchore kai (which you just download and drop in your path. <a href="https://github.com/anchore/kai/releases" rel="nofollow noreferrer">https://github.com/anchore/kai/releases</a>) and jq which you probably already have installed. This also assumes your kubectl is configured and pointed to the cluster with needed credentials to read everything you need to acquire.</p>
  <pre><code>kai -i \
    |jq --raw-output '.results[] \
      | {&quot;namespace&quot;: .namespace, &quot;image&quot;: .images[].tag, &quot;digest&quot;: .images[].repoDigest} \
      | [.namespace, .image, .digest] \
      | @csv' \
    `
  </code></pre>
  <p>The first line is getting the images using kai. The <code>-i</code> outputs the inventory to the commandline. This is in a json format. Then I use <code>jq</code> to get the results in line 2. In line 3 I re-arrange the results so the namespace is associated with each image in the same array. Then I dump these into a bunch of individual rows in line 4 and finally in line 5 output that to stdout in a CSV format instead of json.</p>
  <p>You'll get a count of the images per namespace to stderr and the csv to stdout so you can simply add  <code>&gt; inventory.csv</code> to the end of the command to save it off to a file. You'll still see the stderr output to the screen so you can follow along.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-04-04T20:37:33.863Z
Answers: 2023-04-04T20:37:33.863Z
Answers: Josiah
Body: <p>I'd like to get a CSV for our security team with all the container images running in our kubernetes cluster right now including the image digests and namespace. How can I do that?</p>
  
Tags: <kubernetes>
Title: How to list all images running in a cluster in CSV format?
UserDisplayName: Josiah
ThreadText: # How to list all images running in a cluster in CSV format?
  
  (Asked by: username_0 on 2023-04-04)
  
  I'd like to get a CSV for our security team with all the container images running in our kubernetes cluster right now including the image digests and namespace. How can I do that?
  
  **Tags:** kubernetes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-04-04. Score: 0
  
  This depends on anchore kai (which you just download and drop in your path. <https://github.com/anchore/kai/releases>) and jq which you probably already have installed. This also assumes your kubectl is configured and pointed to the cluster with needed credentials to read everything you need to acquire.
  
  ```
  kai -i \
    |jq --raw-output '.results[] \
      | {"namespace": .namespace, "image": .images[].tag, "digest": .images[].repoDigest} \
      | [.namespace, .image, .digest] \
      | @csv' \
    `
  
  ```
  
  The first line is getting the images using kai. The `-i` outputs the inventory to the commandline. This is in a json format. Then I use `jq` to get the results in line 2. In line 3 I re-arrange the results so the namespace is associated with each image in the same array. Then I dump these into a bunch of individual rows in line 4 and finally in line 5 output that to stdout in a CSV format instead of json.
  
  You'll get a count of the images per namespace to stderr and the csv to stdout so you can simply add `> inventory.csv` to the end of the command to save it off to a file. You'll still see the stderr output to the screen so you can follow along.
  
  
  ---
  
  