6

How to Route Traffic Between Microservices During Development

 3 years ago
source link: https://hackernoon.com/how-to-route-traffic-between-microservices-during-development-36183341
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
How to Route Traffic Between Microservices During Development

We could also use nginx or HAProxy, however, we decided on traefik because of its simplicity. Also, it is worth mentioning that we’re going to use version 2.2.

0 reactions

There’re two types of configuration in traefik: static and dynamic. The difference is that dynamic configuration can be changed in the runtime, whilst static can’t.

0 reactions

Let’s create a static configuration file and call it static.config.yml:

0 reactions
entryPoints:
  web:
    address: :80

providers:
  file:
    filename: /config/dynamic.config.yml

api:
  dashboard: true
  insecure: true

log:
  level: INFO

As you can see, we specify an entrypoint, HTTP port 80, and a path to the dynamic config file. Nothing too complicated.

0 reactions

Let’s now create a dynamic configuration file (dynamic.config.yml):

0 reactions
http:
  routers:
    recommendation:
      rule: Host(`recommendation.some-domain.localhost`)
      service: recommendation
    auth:
      rule: Host(`auth.some-domain.localhost`)
      service: auth
    email:
      rule: Host(`email.some-domain.localhost`)
      service: email
    notifications:
      rule: Host(`notifications.some-domain.localhost`)
      service: notifications
    dashboard:
      rule: >-
        Host(`traefik.some-domain.localhost`) && (PathPrefix(`/api`) 
||
        PathPrefix(`/dashboard`))
      service: api@internal
  services:
    auth:
      loadBalancer:
        passHostHeader: false
        servers:
          - url: "https://stg-auth.some-domain.io/"
    email:
      loadBalancer:
        passHostHeader: false
        servers:
          - url: "https://stg-email.some-domain.io/"
    notifications:
      loadBalancer:
        passHostHeader: false
        servers:
          - url: "http://localhost:8089/"
    recommendation:
      loadBalancer:
        passHostHeader: false
        servers:
          - url: "http://localhost:8088/"

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK