Frontend communication with API in Kubernetes cluster Frontend communication with API in Kubernetes cluster kubernetes kubernetes

Frontend communication with API in Kubernetes cluster


Pods running on the cluster can talk to each other using a ClusterIP service, which is the default service type. You don't need a LoadBalancer service to make two pods talk to each other. According to the docs on this topic

ClusterIP exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default ServiceType.

As explained in the Discovery documentation, if both Pods (frontend and API) are running on the same namespace, the frontend just needs to send requests to the name of the backend service.

If they are running on different namespaces, the frontend API needs to use a fully qualified domain name to be able to talk with the backend.

For example, if you have a Service called "my-service" in Kubernetes Namespace "my-ns" a DNS record for "my-service.my-ns" is created. Pods which exist in the "my-ns" Namespace should be able to find it by simply doing a name lookup for "my-service". Pods which exist in other Namespaces must qualify the name as "my-service.my-ns". The result of these name lookups is the cluster IP.

You can find more info about how DNS works on kubernetes in the docs.


The problem with this configuration is the idea that the Frontend app will be trying to reach out to the API via the internal cluster. But it will not. My app, on the client's browser can not reach services and pods in my Kluster.

My cluster will need something like nginx or another external Load Balancer to allow my client side api calls to reach my API.

You can alternatively used your front end app, as your proxy, but that is highly not advised!


I'm trying to get the front end and api to communicate

By api, if you mean the Kubernetes API server, first setup a service account and token for the front-end pod to communicate with the Kubernetes API server by following the steps here, here and here.

is there a way to do that using the clusterIPs and not have an external IP for the back end

Yes, this is possible and more secure if external access is not needed for the service. Service type ClusterIP will not have an ExternalIP and the pods can talk to each other using ClusterIP:Port within the cluster.