AKS K8S - access spring-boot app from angular frontend using service name

2/20/2021

I have two application frontend developed using angular and backend developed using spring-boot. Both the app are running in same namespace.

Already created two service of type: Loadbalancer. 1. frontend say frontend-app-lb (exposed 9001) 2. backend say backend-app-lb (exposed 9000).

I am able to get the response with the External Ip. using curl http://<External-ip>:900[0/1]/

In angular app, i configured environment-prod.ts, with baseurl as http://<External-ip-of-backend-app-lb>:9000/. With the CORS allowed, able to access the backend app.

I also know that, if the app is running in different namespace, we can access the application/pod from different namespace, using this http://<service-name>.<namespace>.svc.cluster.local:port.

How to access the backend app running in the same namespace just using the service name in baseurl like http://backend-app-lb:9000. - Is this possible?

-- Tim
angular
azure
azure-aks
kubernetes

1 Answer

2/26/2021

i found out, accessing http://backend-app-lb:9000 might not be a approach to do it.

Other approaches:

Approach #1: Using Azure application gateway:

  • Expose the backend service a LoadBalancer type service, (in my case the applications deployed in AKS). So a Application Gateway (Layer 7) was configured.

    • say any url /backend-api connect to the backend application.
  • In frontend application environment.prod.ts, use the /backend-api as baseurl to connect to the backend api.

    Approach #2: Using Nginx proxy

  • If the frontend application is developed on Ngnix server, using the configuration the we create a proxy and access the backend service.

  • Reference available at Kubernetes documentation
  • In this case the backend application can be exposed as service (it can be of type NodePort or LoadBalancer).

Both approach, in a way makes the Frontend application access to the backend service simple and no need for manipulation during build.

-- Tim
Source: StackOverflow