Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have a single service created to expose as both cluster IP and NodePort?

Tags:

kubernetes

I have 2 pods running on minikube. Pod A has to expose 2 ports 8081 and 9092 to both Pod B inside the k8 cluster and also outside k8 cluster so that pod B can reach them and also outside the cluster my consumer can reach them.So my question is should I have 2 services created for each port? One to expose as cluster ip and one for node port? Or is there a way to have a single service created to expose this as both cluster IP and NodePort?

Also if I have to expose my node port as a particular port, would specifying nodePort mess up with the cluster ip?

like image 548
Achilleus Avatar asked Oct 15 '25 18:10

Achilleus


1 Answers

When you choose the NodePort service type, besides having a Cluster IP, kubernetes will expose the service on a port on each node of the cluster (the same port on each node). So choosing NodePort gets you both: the ClusterIP and the port on each node. As said in the docs

Note that this Service will be visible as both :spec.ports[].nodePort and spec.clusterIP:spec.ports[].port.

like image 83
Jose Armesto Avatar answered Oct 18 '25 15:10

Jose Armesto