<p>I'd like to find out the other pods' name running in the same single-host cluster. All pods are single-application containers. I have pod A (written in Java) that acts as a TCP/IP server and a few other pods (written in C++) connect to the server.</p>
<p>In pod A, I can get IP address of clients (other pods). How do I get their pods' name? I can't run kubectl commands because pod A has no kubectl installed.</p>
<p>Thanks,</p>

Kevin N
<p>You can directly call kube-apiserver with cURL.</p>
<ul>
<li><p>First you need to have a serviceaccount binded to clusterrole to be able to send requests to apiserver.</p>
<p><code>kubectl create clusterrole listpods --verb=get,list,watch --resource=pods</code></p>
<p><code>kubectl create clusterrolebinding listpods --clusterrole=listpods --serviceaccount=default:default</code></p>
</li>
<li><p>Get a shell inside a container</p>
<p><code>kubectl exec -it deploy/YOUR_DEPLOYMENT -- sh</code></p>
</li>
<li><p>Define necessary parameters for your cURL, run below commands inside container</p>
<p><code>APISERVER=https://kubernetes.default.svc</code>
<code>SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount</code>
<code>NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)</code>
<code>TOKEN=$(cat ${SERVICEACCOUNT}/token)</code>
<code>CACERT=${SERVICEACCOUNT}/ca.crt</code></p>
</li>
<li><p>Send pods list request to apiserver</p>
<p><code>curl -s -k -H &quot;Authorization: Bearer $TOKEN&quot; -H 'Accept: application/json' $APISERVER/api/v1/pods | jq &quot;[ .items[] | .metadata.name ]&quot;</code></p>
</li>
</ul>
<p>Done ! It will return you a json list of &quot;<em>kubectl get pods</em>&quot;</p>
<p>For more examples, you can check <a href="https://docs.openshift.com/container-platform/3.7/rest_api/api/v1.Pod.html" rel="nofollow noreferrer">OpenShift RestAPI Reference</a>. Also, if you are planning to do some programmatic stuff, I advice you to checkout <a href="https://github.com/kubernetes-client" rel="nofollow noreferrer">official kubernetes-clients</a>.</p>
<p>Credits for jq improvement to <a href="https://stackoverflow.com/users/15537201/moonkotte">@moonkotte</a></p>
