<p>I run an application which needs a list of all client ips for synchronization. I run this application in Kubernetes and make requests against <code>https://kubernetes/api/v1/pods</code> from these client-pods. So I am searching for a reliable way to identify all pods, which are created by the same deployment (replication set) this way.</p>

<p>Thereby it is important, that the pods are also identified correctly during a rolling-upgrade.</p>

<p>I do have a couple of ideas I want to share, even that none really convinces me:</p>

<p><strong>1) Using labels (<code>?labelSelector=label=value</code>):</strong></p>

<p>1.a) Define a <strong>custom label</strong> only these pods have: Valid solution, but since the solution should be really general, I don't want to define a special label, the pods need to have. Also this way I can not be sure to add other pods which got the label.</p>

<p>1.b) Use the auto-generated <strong>pod-template-hash</strong> label: Sadly this one gets changed during a rolling-update, so which the update takes place, the selector does not work correctly.</p>

<p><strong>2) Using custom fields (<code>?fieldSelector</code>)</strong></p>

<p>I thought of using either a subpart of the <code>name</code> or <code>ownerReference.name</code> attributes. Sadly the fieldSelector is <a href="https://github.com/kubernetes/kubernetes/issues/15128__" rel="nofollow noreferrer">badly documented</a> or does not work at all. I also thought of parsing the full list of pods via <code>jq</code>, but don't really like the dependency.</p>

<p><strong>3) Identify all pods by referencing a common service</strong></p>

<p>I see now way to recognize which pod belongs to which service (beside using labels again)</p>

<hr>

<p>Are there any other ideas to identify sibling-pods? I am kind of surprised that I did not find a simular question.</p>

<p>That is what the <code>app</code> selector is typically used for.</p>

<p>You can use kubectl to list pods for a deployment. </p>

<p>The following is from the <a href="https://kubernetes.io/docs/tutorials/stateless-application/run-stateless-application-deployment/" rel="nofollow noreferrer">official docs</a>:</p>

<blockquote>
  <p>List the pods created by the deployment:  </p>
</blockquote>

<pre><code>kubectl get pods -l app=nginx

  NAME                                     READY     STATUS    RESTARTS  
  AGE  nginx-deployment-1771418926-7o5ns   1/1       Running   0        
  16h  nginx-deployment-1771418926-r18az   1/1       Running   0
</code></pre>

<p>You can also list Pods by yaml file:</p>

<p><code>$ kubectl get pod -f ./pod.yaml</code></p>
