<p>Can I use <code>kubectl get pods</code> with some sort of field selector or selector that supports getting a single pod based upon a container environment variable?</p>

<p>I'd like to get this pod, and only this pod out of thousands and thousands, based upon the value of <code>ENVIRONMENT_VARIABLE</code> with <code>kubectl</code>.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: my-pod
  namespace: default
spec:
  containers:
  - env:
    - name: ENVIRONMENT_VARIABLE
      value: abc123
    image: my-images
    imagePullPolicy: IfNotPresent
    name: my-pod
</code></pre>

<p><code>kubectl get pods --field-selector</code> no, field is not supported</p>

<p><code>kubectl get pods -l</code> it's not a label</p>

<p>What else can I try, if anything?</p>

duffn
<p>I have a pod <code>my-pod</code> with an environment variable <code>PORT</code> with value <code>8080</code> like:</p>

<pre><code>  metadata:
  ...
    name: my-pod
  ...
  spec:
    containers:
    - env:
      - name: PORT
        value: "8080"
  ...
</code></pre>

<p>and I can use <code>kubectl</code> to filter this pod like:</p>

<pre><code>$ kubectl get pods --all-namespaces \
-o=jsonpath=\
'{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].env[?(@.name=="PORT")]}{"\n"}{end}' | \
grep 8080

output is:

my-pod  map[name:PORT value:8080]
</code></pre>

<p>So, you can try:</p>

<pre><code>kubectl get pods --all-namespaces \
-o=jsonpath=\
'{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].env[?(@.name=="ENVIRONMENT_VARIABLE")]}{"\n"}{end}' | \
grep abc123
</code></pre>
