博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Træfɪk 服务发现解决方案
阅读量:6312 次
发布时间:2019-06-22

本文共 3887 字,大约阅读时间需要 12 分钟。

Træfɪk is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. It supports several backends (, , , , , , , , Rest API, file...) to manage its configuration automatically and dynamically.

Overview

Imagine that you have deployed a bunch of microservices on your infrastructure. You probably used a service registry (like etcd or consul) and/or an orchestrator (swarm, Mesos/Marathon) to manage all these services. If you want your users to access some of your microservices from the Internet, you will have to use a reverse proxy and configure it using virtual hosts or prefix paths:

  • domain api.domain.com will point the microservice api in your private network
  • path domain.com/web will point the microservice web in your private network
  • domain backoffice.domain.com will point the microservices backoffice in your private network, load-balancing between your multiple instances

But a microservices architecture is dynamic... Services are added, removed, killed or upgraded often, eventually several times a day.

Traditional reverse-proxies are not natively dynamic. You can't change their configuration and hot-reload easily.

Here enters Træfɪk.

Architecture

Træfɪk can listen to your service registry/orchestrator API, and knows each time a microservice is added, removed, killed or upgraded, and can generate its configuration automatically. Routes to your services will be created instantly.

Run it and forget it!

Quickstart

You can have a quick look at Træfɪk in this  that shows how to load balance requests between multiple Docker containers.

Here is a talk given by  at the  conference. You will learn fundamental Træfɪk features and see some demos with Kubernetes.

Here is a talk (in French) given by  at the  conference. You will learn fundamental Træfɪk features and see some demos with Docker, Mesos/Marathon and Let's Encrypt.

Get it

Binary

You can grab the latest binary from the  page and just run it with the :

./traefik -c traefik.toml

Docker

Using the tiny Docker image:

docker run -d -p 8080:8080 -p 80:80 -v $PWD/traefik.toml:/etc/traefik/traefik.toml traefik

Test it

You can test Træfɪk easily using , with this docker-compose.yml file in a folder named traefik:

version: '2'services:  proxy:    image: traefik    command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG    networks:      - webgateway    ports:      - "80:80"      - "8080:8080"    volumes:      - /var/run/docker.sock:/var/run/docker.sock      - /dev/null:/traefik.tomlnetworks:  webgateway:    driver: bridge

Start it from within the traefik folder:

docker-compose up -d

In a browser you may open http://localhost:8080 to access Træfɪk's dashboard and observe the following magic.

Now, create a folder named test and create a docker-compose.yml in it with this content:

version: '2'services:  whoami:    image: emilevauge/whoami    networks:      - web    labels:      - "traefik.backend=whoami"      - "traefik.frontend.rule=Host:whoami.docker.localhost"networks:  web:    external:      name: traefik_webgateway

Then, start and scale it in the test folder:

docker-compose up -ddocker-compose scale whoami=2

Finally, test load-balancing between the two services test_whoami_1 and test_whoami_2:

$ curl -H Host:whoami.docker.localhost http://127.0.0.1Hostname: ef194d07634aIP: 127.0.0.1IP: ::1IP: 172.17.0.4IP: fe80::42:acff:fe11:4GET / HTTP/1.1Host: 172.17.0.4:80User-Agent: curl/7.35.0Accept: */*Accept-Encoding: gzipX-Forwarded-For: 172.17.0.1X-Forwarded-Host: 172.17.0.4:80X-Forwarded-Proto: httpX-Forwarded-Server: dbb60406010d$ curl -H Host:whoami.docker.localhost http://127.0.0.1Hostname: 6c3c5df0c79aIP: 127.0.0.1IP: ::1IP: 172.17.0.3IP: fe80::42:acff:fe11:3GET / HTTP/1.1Host: 172.17.0.3:80User-Agent: curl/7.35.0Accept: */*Accept-Encoding: gzipX-Forwarded-For: 172.17.0.1X-Forwarded-Host: 172.17.0.3:80X-Forwarded-Proto: httpX-Forwarded-Server: dbb60406010d

转载地址:http://yphxa.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
sshd系统自带启动脚本详解
查看>>
yum升级php到5.2
查看>>
我的友情链接
查看>>
JAVA学习日志(7-4-接口)
查看>>
我的友情链接
查看>>
ansible-playbook 剧本
查看>>
明天入职!
查看>>
MongoDB操作
查看>>
linux文件查找之find的用法
查看>>
MyCat - 使用篇(2)
查看>>
shell脚本常见面试题
查看>>
Oracle 12C OEM 安装
查看>>
IPV6动态路由协议的配置
查看>>
【安全牛学习笔记】TOR
查看>>
Java 数组 之 一维数组 冒泡排序算法
查看>>
struts第六结
查看>>
公文管理解决方案
查看>>
使用sed插入tab
查看>>
ansible hosts文件详解
查看>>