<p>Consider the following <a href="https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/controllers/frontend.yaml" rel="nofollow noreferrer">example</a> provided in this <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/" rel="nofollow noreferrer">doc</a>.</p>
<p>What I'm trying to achieve is to see the 3 replicas names from inside the container.
following <a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/" rel="nofollow noreferrer">this guide</a> I was able to get the current pod name, but i need also the pod names from my replicas.</p>
<p>Ideally i would like to:</p>
<pre><code>print(k8s.get_my_replicaset_names())
</code></pre>
<p>or</p>
<pre><code>print(os.getenv(&quot;MY_REPLICASET&quot;))
</code></pre>
<p>and have a result like:</p>
<pre><code>[frontend-b2zdv,frontend-vcmts,frontend-wtsmm]
</code></pre>
<p>that is the pod names of all the container's replicas (also the current container of course) and eventually compare the current name in the name list to get my index in the list.</p>
<p>Is there any way to achieve this?</p>

<p>As you can read <a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api" rel="nofollow noreferrer">here</a>, the <strong>Downward API</strong> is used to expose <code>Pod</code> and <code>Container</code> fields to a running Container:</p>
<blockquote>
<p>There are two ways to expose Pod and Container fields to a running
Container:</p>
<ul>
<li>Environment variables</li>
<li><a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#the-downward-api" rel="nofollow noreferrer">Volume Files</a></li>
</ul>
<p>Together, these two ways of exposing Pod and Container fields are
called the  <em>Downward API</em>.</p>
</blockquote>
<p>It is not meant to expose any information about other objects/resources such as <code>ReplicaSet</code> or <code>Deployment</code>, that manage such a <code>Pod</code>.</p>
<p>You can see exactly what fields contains the <code>yaml</code> manifest that describes a running <code>Pod</code> by executing:</p>
<pre><code>kubectl get pods &lt;pod_name&gt; -o yaml
</code></pre>
<p>The example fragment of its output may look as follows:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  annotations:
    &lt;some annotations here&gt;
    ...
  creationTimestamp: &quot;2020-10-08T22:18:03Z&quot;
  generateName: nginx-deployment-7bffc778db-
  labels:
    app: nginx
    pod-template-hash: 7bffc778db
  name: nginx-deployment-7bffc778db-8fzrz
  namespace: default
  ownerReferences: 👈
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: ReplicaSet 👈
    name: nginx-deployment-7bffc778db 👈
 ...
</code></pre>
<p>As you can see, in <code>metadata</code> section it contains <code>ownerReferences</code> which in the above example contains one reference to a <code>ReplicaSet</code> object by which this <code>Pod</code> is managed. So you can get this particular <code>ReplicaSet</code> name pretty easily as it is part of a <code>Pod</code> yaml manifest.</p>
<p><strong>However, you cannot get this way information about other <code>Pods</code> managed by this <code>ReplicaSet</code> .</strong></p>
<p>Such information only can be obtained from the <strong>api server</strong> e.g by using <strong>kubectl</strong> client or programmatically with direct calls to the API.</p>
