I am trying to create a service and then communicate with it externally.
V1Service service = new V1Service();
V1ServiceSpec spec = new V1ServiceSpec();
spec.addPortsItem(new V1ServicePort().port(25452));
service.setSpec(spec);
...
V1Service kubernetesService = api.createNamespacedService("ns", service, null);
When I type kubectl get services --all-namespaces
command, I see that the port 25452 was forwarded to another automatically allocated port:
NAMESPACE TYPE IP EXTRENAL IP PORT(S)
ns NodePort 10.100.237.201 <none> 25452:32668/TCP
How using Java code can I retrieve the value of the new forwarded port (32668)?
kubernetesService.getSpec().getPorts().get(0).getNodePort()