Search code examples
kubernetesmicroservicesmoleculer

Setting up infraestructure using moleculer and kubernetes (doubts)


I am testing moleculer microservices framework to setting up an infraestructure. I will to use typescript (https://github.com/moleculerjs/moleculer-template-project-typescript). My idea is according the documentation is:

  • create one project for with API Gateway => make doker => make k8s deployment with N replicas
  • create 1 project per microservice => dockerize => make k8s deployment with N replicas
  • create 2 project per microservice => dockerize => make k8s deployment with N replicas ...
  • create N project per microservice => dockerize => make k8s deployment with N replicas

I will use redis as transporter. I want to use redis also in development.

I have got this doubt, because you can create in the same project all the microservices, but in this way, you are developing a monolitic application (and only in one thread). I think that you need to sepparate each microservice in independent (typescripts) projects to make it after docker images and the make pods in k8s in the deployment phase.


Solution

  • You can separate every microservices into a separated projects, but with Moleculer you don't need it. You can put all services into one project. The development will be easy and fast, and at deploying you can control which services will be loaded. So you can generate one docker image and control the loaded services with environment variables.

    E.g here you can see the SERVICES env var in docker-compose.yml: https://moleculer.services/docs/0.14/deploying.html#Docker-Compose

    version: "3.2"
    
    services:
    
      api:
        build:
          context: .
        image: moleculer-demo
        container_name: moleculer-demo-api
        env_file: docker-compose.env
        environment:
          SERVICES: api # Runner will start only the 'api' service in this container
          PORT: 3000    # Port of API gateway
    
      greeter:
        build:
          context: .
        image: moleculer-demo
        container_name: moleculer-demo-greeter
        env_file: docker-compose.env
        environment:
          SERVICES: greeter # Runner will start only the 'greeter' service in this container