4
votes

I have an app deployment called 'backend-app' running in pods that are on several different nodes. I also have a service that exposes the 'backend-app' to be accessed by other cluster internal pods as my 'frontend-app' pods.

If I use DNS to connect to the 'backend-app' from my different app deployment called 'frontend-app' will the requests be load balanced to each 'backend-app' pod on each node?

It sounds like a NodePort service will only connect to one node and not load balance my requests to others.

2
NodePort is a service type, but if you want load balancing behavior choose the type as LoadBalancer. There is also a question on SO on NodePort and LoadBalancer. After all, for official reference, see: kubernetes.io/docs/concepts/services-networking/service/… - vahdet
So if I want my 'frontend-app' pod to communicate with a 'backend-app' pod in a load balanced way I can't just create a 'ClusterIP' service that selects the 'backend-app' and then use DNS lookups to a random 'backend-app'? - Dan
ClusterIP should not be available outside the cluster. Basically, for a load balanced behavior, choosing LoadBalancer can delegate the balancing to your cloud provider's LB. If you are to configure your LB more explicitly, however, nothing stops you from exposing your deployments by a NodePort service: An external LB can access the NodePorts in a round-robin fashion (or whatever way you configure it) - vahdet
@vahdet thanks for the information. My question really centres around internal load balancing. Note that my 'backend-app' and 'frontend-app' are both in the same cluster. I would like to know how can my 'frontend-app' load balance its requests to my 'backend-app'. Both frontend and backend deployments are running on multiple nodes. I want to make sure that my frontend requests are not just hitting the same pod in the same node all the time. - Dan

2 Answers

2
votes

For each Service with type: NodePort a port is opened on all nodes (the same port on each). The port is open whether a pod of that service is running on a node or not. The load balancing is done among all pods of all nodes with no preference to a pod that happens to run on the same node to which you connected on the node port (if there is one there at all).

1
votes

Services automatically load balance to the pods that are assigned to them. See https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#creating-a-service.

The cluster IP address that is created with a service is the IP address that will automatically select an available pod on any node that is running the pod. You can find the service's cluster IP address by using a DNS lookup.

My confusion came because I didn't realise the cluster IP address was associated with a service, not with a specific Pod.

I'm currently not sure about how NodePort's work with this though.