<p>Is it possible to determine the neighbour container or pod IP address, e.g. given its name? More specifically, if I have two running containers/pods C1 (ip=1.2.3.4) and C2 (ip=5.6.7.8) and I execute:</p>

<pre><code>  ME$ kubectl exec -it C1 bash
  C1$ magic_command_to_get_ip C2
  5.6.7.8
</code></pre>

<p>Is there a magic_command_to_get_ip?</p>

<p>I am new to Kubernetes and I used to resolve names to addresses in Docker using <code>getent hosts tasks.$SERVICE</code>, but apparently it does not work with KB. </p>

João Matos
<p>Each pod has a service account mounted to it.</p>

<p>You can check that with </p>

<pre><code>kubectl decsribe pod pod_name
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from xxxxx-token-xxx (ro)
</code></pre>

<p>The command suggested by Raunak should work if your service account has permission to execute that command.</p>

<p>Please make sure the service account you are using has permission to run that command.</p>

<p>The error stated in comments <strong>(Forbidden): pods "cassandra-0" is forbidden: User "system:serviceaccount:default:default"</strong>  is beacuse of that.</p>

<p>More about service accounts <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/" rel="nofollow noreferrer">docs</a></p>
