I am trying to create a Kubernetes application in which, I have created one pod and service for backend(spring boot microservice) & frontend pod and a loadbalancer service.
I wanted to know how would I call the backend API from frontend pod in Kubernetes?
Here are the running services:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
angular LoadBalancer 10.100.15.215 a17f17fd2e25011e886100a0e002191e-1613530232.us-east-1.elb.amazonaws.com 4200:30126/TCP 12s app=angular
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 35m <none>
login ClusterIP 10.100.99.52 <none> 5555/TCP 13m app=login,tier=backend
I am calling the following API from frontend and it is showing name not resolved error:
http://login/login
I have also tried to call the API with cluster IP but that failed.
Looks like your backend service is running on port
5555
, so you would have to call your backend service like this:This assuming the pods for your frontend are on the same Kubernetes namespace. If they are on a different namespace you would call something like this:
Also as described here.
Note that this will work only within the cluster, if you are hitting your Angular frontend from a web browser outside of the cluster, this will not work, because the web browser would have no idea of where your backend is in the cluster. So either you will have to expose your backend using another LoadBalancer type of service or you may consider using a Kubernetes Ingress with an ingress controller.