<p>Let's suppose I have pods deployed in a Kubernetes cluster and I have exposed them via a NodePort service. Is there a way to get the pod external endpoint in one command ?</p>
<p>For example:</p>
<pre><code>kubectl &lt;cmd&gt;
Response : &lt;IP_OF_NODE_HOSTING_THE_POD&gt;:30120 ( 30120 being the nodeport external port )
</code></pre>

joe1531
<p>The requirement is a complex one and requires query to list object. I am going to explain with assumptions. Additionally if you need internal address then you can use endpoint object(ep), because the target resolution is done at the endpoint level.</p>
<p>Assumption: 1 Pod, 1 NodePort service(32320-&gt;80); both with name nginx</p>
<p>The following command will work with the stated assumption and I hope this will give you an idea for the best approach to follow for your requirement.</p>
<p>Note: This answer is valid based on the assumption stated above. However for more generalized solution I recommend to use <code>-o jsonpath='{range..</code> for this type of complex queries. For now the following command will work.</p>
<p>command:</p>
<pre><code>kubectl get pods,ep,svc nginx -o jsonpath=' External:http://{..status.hostIP}{&quot;:&quot;}{..nodePort}{&quot;\n Internal:http://&quot;}{..subsets..ip}{&quot;:&quot;}{..spec.ports..port}{&quot;\n&quot;}'
</code></pre>
<p>Output:</p>
<pre><code> External:http://192.168.5.21:32320
 Internal:http://10.44.0.21:80
</code></pre>
