0

Recently, I’ve made a simple application with spring boot backends and an angular frontend. Here is the ‘architecture’:

application setup

The goal was to mimic microservices, that’s why I have three backends with different databases. The microservices only check with each other in order to keep data consistent. So if you make a concert and assign it a performerId, it checks if that is a valid one. I have all this in Docker and can run it successfully locally.

Now, I want to deploy this through Kubernetes. I have a Linode set up to achieve this, but there are some difficulties I run into.

In short, I created deployments for all the apps. For the angular I used a loadbalancer to expose it to the outside world, but the microservices and databases only have a clusterIp. Now, the thing is, how do I connect from Angular to the backend apps? I don’t know what URL to use. My services are as follows:

image of my services

I thought, I could connect to the ClusterIP’s using the service name. So I changed the URL’s in the frontend to look like: http://concert-cluster-ip... But that doesn’t work. So a few questions:

  • Is it common practice to shield your microservices or would you make the api’s accessible from the outside? Because, obviously, it worked when I made the services loadbalancers and updated the URL’s in the back- and frontend but I think that’s not what you would do?

  • Is it possible to access the backends with the front end with my current setup? I assume so, because the databases do work like this.

  • Should I put an Ingress service before the traffic? And should Ingress govern all traffic? So a request to the frontend and requests from the frontend to the backend? Or should I make two ingresses, one for the backends and one for the frontend?

  • How should my URL’s look inside my backend and frontend applications when calling a service?

I did a lot of Kubernetes tutorials but I struggle to apply that knowledge in this case and can’t get it to work. Any help and tips would be appreciated.

JelD
  • 11

1 Answers1

0

Is it common practice to shield your microservices or would you make the api’s accessible from the outside? Because, obviously, it worked when I made the services loadbalancers and updated the URL’s in the back- and frontend but I think that’s not what you would do?

You have to use the service name instead of using the cluster IP of that specific service. try using http://mysql or http://backend if your database connecting string is like mysq://<service-name>:<port> so it will be like mysql://mysql:3360

Normally we don't expose all services mostly like backed and databases run over clusterIP only which is internally resolved in the K8s cluster not from outside.

Is it possible to access the backends with the front end with my current setup? I assume so, because the databases do work like this.

Yes you should be able to access it that's how it works.

Should I put an Ingress service before the traffic? And should Ingress govern all traffic? So a request to the frontend and requests from the frontend to the backend? Or should I make two ingresses, one for the backends and one for the frontend?

Ingress is for handling the incoming traffic to cluster, if you have requirement to expose the backend service and API you can create multiple ingess or use single ingress to expose API (backend) and frontend both. it's up to you.

How should my URL’s look inside my backend and frontend applications when calling a service?

http://service-name:port 

if service is in another you should have to use full path http://<servicename>.<namespace>.svc.cluster.local

Read more : https://stackoverflow.com/a/55650127/5525824

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Thanks for your clear reply. I'm at work at the moment and having trouble connecting to Linodue due to pesky VPN settings, but will try this at home. I thought I already did try it (connecting through the servicename) and I do this with my databases, so I must have made an error somewhere! – JelD May 09 '22 at 06:13
  • Okay, I managed to implement it. For instance, my 'performers' microservice is managed by a clusterIP service with the name 'performer-cluster-ip', so I updated my angular frontend to send requests to: http://performer-cluster-ip:6060/. However, when I load the page, I get an "GET http://performer-cluster-ip:6060/performer/all net::ERR_NAME_NOT_RESOLVED" in the console log. Any remaining tips? – JelD May 09 '22 at 08:32