<p>How to list the kubenetes pods based on any particular exitCode value. For example i need to list all the pods which has exitCode value = 255.</p>

<p>I have tried below command and it will give all pods along with all exitcodes.</p>

<pre><code>kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{..exitCode}{'\n'}{end}"

kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{..exitCode}{'\n'}{end}"
</code></pre>

Ankit
<p>if I understand you correctly you may want to check out the <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/" rel="nofollow noreferrer">Field Selectors</a>.</p>

<blockquote>
  <p>Field selectors let you select Kubernetes resources based on the value
  of one or more resource fields. Here are some example field selector
  queries:</p>
  
  <ul>
  <li>metadata.name=my-service </li>
  <li>metadata.namespace!=default</li>
  <li>status.phase=Pending </li>
  </ul>
  
  <p>This kubectl command selects all Pods for which
  the value of the status.phase field is Running:</p>
  
  <p><code>kubectl get pods --field-selector status.phase=Running</code></p>
</blockquote>

<p>Here is some more <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get" rel="nofollow noreferrer">documentation</a> regarding this.</p>

<blockquote>
  <p>Selector (field query) to filter on, supports '=',
  '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The
  server only supports a limited number of field queries per type.</p>
</blockquote>

<p>Please let me know if that helped. </p>
