0

I have a backend API & Frontend application that i want to deploy on Kubernetes, all using docker images. I know how to deploy the Frontend using a Loadbalancer service & Ingress to expose the Frontend to the public internet. The question i have is about how the backend API service will communicate with the frontend.

I want to deploy the backend API using ClusterIP service, so it's only accessible to the Frontend from within the cluster, instead of exposing the backend API using ingress, hence, and no public access to the backend API

Is this a good approach if i do decide to use Cluster IP? & how will the Frontend be able to access the backend? will it be using http://localhost:4000? or if an IP is generated it'll be fixed and it won't change? What's the best way to have an URL for the backend which the frontend can call

james
  • 51
  • 1
  • 3
  • The cluster IP service of the backend does have a DNS entry in the cluster DNS. This can be used by the frontend to connect to it. Something like `service-name.namespace.svc`. See https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ for details. – Henry Nov 17 '20 at 15:27
  • Thanks. this is useful. So if i decide to use the cluster DNS, that means i'll be specifying something like `service-name.namespace.svc` to the Frontend to be used as the backend API? – james Nov 17 '20 at 15:53
  • yes, this is correct. This name will resolve to the cluster IP address of the service. – Henry Nov 17 '20 at 15:54
  • Just making sure. Your front-end runs on the server side right? Some front-ends like React etc run in the browser. If that is the case you will need to expose this on the ingress as well or proxy is from another application like your front-end server - Nginx for example – Justin Tamblyn Nov 17 '20 at 16:53
  • This is something i didn't take into account. Is there a way for me to secure the backend if the frontend is running on client side? and i need a backend API url to access the backend. I don't think cluster IP would work for this, would it? – james Nov 17 '20 at 17:59
  • If you need to access the backend from outside the cluster a cluster IP service does not work. – Henry Nov 17 '20 at 18:26

1 Answers1

1

There are various options on connecting your frontend to backend and it all depends on your application architecture.

You can expose your frontend using Ingress- it allows you to expose different parts of your app using different paths. And backend pods can be accessible only within cluster. You can check "Connecting Applications with Services " in Kubernetes documentation.

There are few examples available online that might help you decide how to approach it.

  1. You can take a look in official documentation: Connect a Front End to a Back End Using a Service.

  2. There is a tutorial on how to connect frontend to backend using nginx

  3. Similar question was also asked in SO, where good answer was given.

kool
  • 3,214
  • 1
  • 10
  • 26