使用molecular和kubernetes搭建基础设施(疑惑)

Setting up infraestructure using moleculer and kubernetes (doubts)

我正在测试分子微服务框架以建立基础设施。我将使用打字稿 (https://github.com/moleculerjs/moleculer-template-project-typescript)。我的想法是根据文档是:

我将使用redis作为传输器。我也想在开发中使用redis。

我有这个疑问,因为你可以在同一个项目中创建所有的微服务,但这样,你正在开发一个单体应用程序(并且只在一个线程中)。我认为您需要在独立(打字稿)项目中分离每个微服务,以便在 docker 图像之后制作它,并在部署阶段在 k8s 中制作 pods。

您可以将每个微服务分离到一个单独的项目中,但使用 Moleculer 则不需要它。您可以将所有服务放在一个项目中。开发将变得简单快捷,在部署时您可以控制加载哪些服务。因此,您可以生成一个 docker 图像并使用环境变量控制加载的服务。

例如,您可以在 docker-compose.yml 中看到 SERVICES 环境变量: 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