Search code examples
web-applicationskubernetesmicroserviceskubernetes-ingress

How to deploy microservices web application on Kubernetes?


I want to create a web application using Angular and microservices backend serving some REST api. Then I would like to deploy everything on Kubernetes.

Lets say application will serve some drinks (Coffea and Tea). For the simplification lets assume that app is fully stateless and I want to 2 have microservices.

Without Kubernetes I would do this in such a way:

  1. Coffea service - rest API for /api/coffea endpoint

  2. Tea service - rest API for /api/tea endpoint

  3. Nginx - static contents with Angular app (HTML/CSS/JS/images etc.) and the gateway (proxy for /api/coffea and /api/tea endpoints)

Now the question is how to reflect this in Kubernetes? Would it be enough just to deploy everything in a several replicas, then expose Coffea and Tea services as a NodePort and finally expose Nginx as a LoadBalancer? Is this a right approach? Should I use Ingress instead of making my own nginx proxy? If yes, then how to serve static contents using Ingress Controller?

Thanks in advance!


Solution

  • Would it be enough just to deploy everything in a several replicas, then expose Coffea and Tea services as a NodePort and finally expose Nginx as a LoadBalancer?

    Probably yes, it would be sufficient to make your application work, but the best way is to use your services with cluster IP and expose it by Ingress. Because Ingress is good for routing but it is not good for serving static content, so you can use the Nginx as a web server only for static content. Your app will look like 3 services hidden behind the Ingress:

    1. Coffea service with cluster IP
    2. Tea service with cluster IP
    3. Nginx service with cluster IP as a web server for static content

    Here is a good answer why it is better to use Nginx as a service for static content.