Cannot connect frontend app{Angular} to Backend{SpringBoot} in kubernetes

5/23/2019

I am trying to containerize my angular+java app in Kubernetes cluster. I have a frontend deployment and a backend deployment in my k8 cluster. My database is in AWS{RDS}. But i am confused that what API-URL should i give in my Frontend code so that it can get connected to my backend app in k8 cluster. For e.g :- In local system i use something like {localhost:8080/api/customers} in my Frontend code but what should i change it to at the time of deploying in Kubernetes cluster.

I have a Kubernetes cluster setup with 1 master and 2 slave nodes, I created a deployment of my backend app and exposed it through Cluster Ip, and than i gave this cluster ip and port in my frontend application. After that i pushed the image to docker hub and than created a k8 deployment for it, but still its not working.

My main ask is what URL and Port should i mention in my Frontend application target URL so that it can find hit my java APIs.

-- Faisal Jaffri
amazon-web-services
angular6
kubernetes
spring-boot

3 Answers

5/27/2019

if your two applications run in the same kubernetes cluster so you would have to call your backend service like this: svcname:port for example

http://login:8080/login

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:

http://login.<namespace>.svc.cluster.local:5555/login
-- Semah Mhamdi
Source: StackOverflow

5/28/2019

Exposing my back-end service to a Load Balancer, and than using that Load Balancer endpoint in my Front-end application worked for me.

-- Faisal Jaffri
Source: StackOverflow

5/23/2019

The front end angular application is running inside the browser of a user. This is outside of the kubernetes Cluster and you therefore can not use the kubernetes Service Name as api endpoint. You need to make the spring boot api accessible from outside of kubernetes, usually using an ingress or load balancer. You use this external ip or host name as api url in the angular application.

-- Thomas
Source: StackOverflow