<p>I am trying to create a service and then communicate with it externally.</p>

<pre><code>V1Service service = new V1Service();
V1ServiceSpec spec = new V1ServiceSpec();
spec.addPortsItem(new V1ServicePort().port(25452));
service.setSpec(spec);
...

V1Service kubernetesService = api.createNamespacedService("ns", service, null);
</code></pre>

<p>When I type <code>kubectl get services --all-namespaces</code> command, I see that the port 25452 was forwarded to another automatically allocated port:</p>

<pre><code>NAMESPACE TYPE        IP               EXTRENAL IP   PORT(S)
ns        NodePort    10.100.237.201   &lt;none&gt;        25452:32668/TCP
</code></pre>

<p>How using Java code can I retrieve the value of the new forwarded port (32668)?</p>

mercury0114
<p><code>kubernetesService.getSpec().getPorts().get(0).getNodePort()</code></p>
