<p>I have a k8s cluster and get the list of images if I run:</p>

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

<p>-this works.</p>

<p>Now, I have to list all images which do not start with a particular string, say "random.domain.com"</p>

<p>how to filter out attribute values using jsonpath?</p>

<p>I have tried out below.</p>

<pre><code>kubectl get pods --all-namespaces -o jsonpath="{..image}[?(@.image!="random.domain.com")]" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c
</code></pre>

<p>As a workaround, I am using -</p>

<pre><code>kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" |\
tr -s '[[:space:]]' '\n' |sort |uniq -c| grep -v "random.domain.com"
</code></pre>

<p>But wanted to know how we can get this done by using jsonpath.</p>

<p>Thanks.</p>

Avishek2585835
<p>I have no idea how to work with jsonpath (atm). but here how you can do that with <code>jq</code></p>

<pre><code>kubectl get pods -o json | \ 
 jq '[.items[].spec.containers[].image | select(. | startswith("random.domain.com") | not )] | unique'
</code></pre>

<p>AFAIS, according to the <a href="https://kubernetes.io/docs/reference/kubectl/jsonpath/" rel="nofollow noreferrer">documentation</a>, you can't do that with JSON path itself</p>
