Stay Hungry,Stay Foolish!

microservice-demo

microservice-demo

https://github.com/fanqingsong/microservice-demo

docker-compose.yml

version: '2'

services:
  gateway:
    build: traefik
    command: --logLevel=DEBUG
    networks:
      - microservices
    ports:
      - "80:80"
      # - "443:443"
      - "9090:8080"

  # user:
  #   build: user
  #   networks:
  #     - microservices
  #   ports:
  #     - "8081:80"

  cart:
    build: cart
    networks:
      - microservices
    ports:
      - "8082:80"

  product:
    build: product
    networks:
      - microservices
    ports:
      - "8083:80"

  event:
    build: event
    networks:
      - microservices
    ports:
      - "8084:80"

  web:
    build: web
    networks:
      - microservices
    ports:
      - "8085:80"

networks:
  microservices:
    driver: bridge

 

traefic yaml

http:
  routers:
    # user:
    #   rule: "Host(`api.example.com`) && PathPrefix(`/user`)"
    #   service: user
      # tls:
      #   certResolver: myresolver
      #   domains:
      #     - main: api.example.com
    product:
      rule: "Host(`api.example.com`) && PathPrefix(`/product`)"
      service: product
      # tls:
      #   certResolver: myresolver
      #   domains:
      #     - main: api.example.com
    cart:
      rule: "Host(`api.example.com`) && PathPrefix(`/cart`)"
      service: cart
      # tls:
      #   certResolver: myresolver
      #   domains:
      #     - main: api.example.com
    event:
      rule: "Host(`api.example.com`) && PathPrefix(`/event`)"
      service: event
      # tls:
      #   certResolver: myresolver
      #   domains:
      #     - main: api.example.com
    web:
      rule: "Host(`web.example.com`) && PathPrefix(`/`)"
      service: web
      # tls:
      #   certResolver: myresolver
      #   domains:
      #     - main: web.example.com

  services:
    # user:
    #   loadBalancer:
    #     servers:
    #     - url: http://user

    product:
      loadBalancer:
        servers:
        - url: http://product

    cart:
      loadBalancer:
        servers:
        - url: http://cart

    event:
      loadBalancer:
        servers:
        - url: http://event
        
    web:
      loadBalancer:
        servers:
        - url: http://web

traefik

https://doc.traefik.io/traefik/getting-started/concepts/

Edge Router

Traefik is an Edge Router; this means that it's the door to your platform, and that it intercepts and routes every incoming request: it knows all the logic and every rule that determine which services handle which requests (based on the path, the host, headers, etc.).

The Door to Your Infrastructure

Auto Service Discovery

Where traditionally edge routers (or reverse proxies) need a configuration file that contains every possible route to your services, Traefik gets them from the services themselves.

Deploying your services, you attach information that tells Traefik the characteristics of the requests the services can handle.

Decentralized Configuration

This means that when a service is deployed, Traefik detects it immediately and updates the routing rules in real time. Similarly, when a service is removed from the infrastructure, the corresponding route is deleted accordingly.

You no longer need to create and synchronize configuration files cluttered with IP addresses or other rules.

https://github.com/traefik/traefik?tab=readme-ov-file#quickstart

Traefik (pronounced traffic) is a modern HTTP reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your existing infrastructure components (Docker, Swarm mode, Kubernetes, Consul, Etcd, Rancher v2, Amazon ECS, ...) and configures itself automatically and dynamically. Pointing Traefik at your orchestrator should be the only configuration step you need.

 

Overview

Imagine that you have deployed a bunch of microservices with the help of an orchestrator (like Swarm or Kubernetes) or a service registry (like etcd or consul). Now you want users to access these microservices, and you need a reverse proxy.

Traditional reverse-proxies require that you configure each route that will connect paths and subdomains to each microservice. In an environment where you add, remove, kill, upgrade, or scale your services many times a day, the task of keeping the routes up to date becomes tedious.

This is when Traefik can help you!

Traefik listens to your service registry/orchestrator API and instantly generates the routes so your microservices are connected to the outside world -- without further intervention from your part.

Run Traefik and let it do the work for you! (But if you'd rather configure some of your routes manually, Traefik supports that too!)

Architecture

Features

  • Continuously updates its configuration (No restarts!)
  • Supports multiple load balancing algorithms
  • Provides HTTPS to your microservices by leveraging Let's Encrypt (wildcard certificates support)
  • Circuit breakers, retry
  • See the magic through its clean web UI
  • Websocket, HTTP/2, gRPC ready
  • Provides metrics (Rest, Prometheus, Datadog, Statsd, InfluxDB 2.X)
  • Keeps access logs (JSON, CLF)
  • Fast
  • Exposes a Rest API
  • Packaged as a single binary file (made with ❤️ with go) and available as an official docker image

 

Ubuntu 安装 Docker

https://docker-practice.github.io/zh-cn/install/ubuntu.html#%E5%8D%B8%E8%BD%BD%E6%97%A7%E7%89%88%E6%9C%AC

 

posted @ 2024-06-28 15:34  lightsong  阅读(2)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel