Træfɪk is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. It supports several backends (DockerSwarmMesos/MarathonConsulEtcdZookeeperBoltDBAmazon ECS, 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.

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 Katacoda tutorial that shows how to load balance requests between multiple Docker containers.

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

Here is a talk (in French) given by Emile Vauge at the Devoxx France 2016 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 releases page and just run it with the sample configuration file:

./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 Docker compose, 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.toml networks:
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 -d
docker-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.1
Hostname: ef194d07634a
IP: 127.0.0.1
IP: ::1
IP: 172.17.0.4
IP: fe80::42:acff:fe11:4
GET / HTTP/1.1
Host: 172.17.0.4:80
User-Agent: curl/7.35.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.17.0.1
X-Forwarded-Host: 172.17.0.4:80
X-Forwarded-Proto: http
X-Forwarded-Server: dbb60406010d $ curl -H Host:whoami.docker.localhost http://127.0.0.1
Hostname: 6c3c5df0c79a
IP: 127.0.0.1
IP: ::1
IP: 172.17.0.3
IP: fe80::42:acff:fe11:3
GET / HTTP/1.1
Host: 172.17.0.3:80
User-Agent: curl/7.35.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.17.0.1
X-Forwarded-Host: 172.17.0.3:80
X-Forwarded-Proto: http
X-Forwarded-Server: dbb60406010d

Træfɪk 服务发现解决方案的更多相关文章

  1. 服务发现:Zookeeper vs etcd vs Consul

    [编者的话]本文对比了Zookeeper.etcd和Consul三种服务发现工具,探讨了最佳的服务发现解决方案,仅供参考. 如果使用预定义的端口,服务越多,发生冲突的可能性越大,毕竟,不可能有两个服务 ...

  2. 为什么不应该使用Zookeeper做服务发现?(转载)

    转载自: http://dockone.io/article/78 [编者的话]本文作者通过ZooKeeper与Eureka作为Service发现服务(注:WebServices体系中的UDDI就是个 ...

  3. 为什么不应该使用ZooKeeper做服务发现

    [编者的话]本文作者通过ZooKeeper与Eureka作为Service发现服务(注:WebServices体系中的UDDI就是个发现服务)的优劣对比,分享了Knewton在云计算平台部署服务的经验 ...

  4. 服务发现:Zookeeper vs etcd vs Consul 参考自http://dockone.io/article/667

    服务发现:Zookeeper vs etcd vs Consul [编者的话]本文对比了Zookeeper.etcd和Consul三种服务发现工具,探讨了最佳的服务发现解决方案,仅供参考. 如果使用预 ...

  5. 【转帖】为什么不要把ZooKeeper用于服务发现

    http://www.infoq.com/cn/news/2014/12/zookeeper-service-finding ZooKeeper是Apache基金会下的一个开源的.高可用的分布式应用协 ...

  6. 寻找丢失的微服务-HAProxy热加载问题的发现与分析 原创: 单既喜 一点大数据技术团队 4月8日 在一点资讯的容器计算平台中,我们通过HAProxy进行Marathon服务发现。本文记录HAProxy服务热加载后某微服务50%概率失效的问题。设计3组对比实验,验证了陈旧配置的HAProxy在Reload时没有退出进而导致微服务丢失,并给出了解决方案. Keywords:HAProxy热加

    寻找丢失的微服务-HAProxy热加载问题的发现与分析 原创: 单既喜 一点大数据技术团队 4月8日 在一点资讯的容器计算平台中,我们通过HAProxy进行Marathon服务发现.本文记录HAPro ...

  7. 服务发现之 Etcd VS Consul

    抄自这里 *********************************************************************************************** ...

  8. .net core grpc consul 实现服务注册 服务发现 负载均衡(二)

    在上一篇 .net core grpc 实现通信(一) 中,我们实现的grpc通信在.net core中的可行性,但要在微服务中真正使用,还缺少 服务注册,服务发现及负载均衡等,本篇我们将在 .net ...

  9. .net core Ocelot Consul 实现API网关 服务注册 服务发现 负载均衡

    大神张善友 分享过一篇 <.NET Core 在腾讯财付通的企业级应用开发实践>里面就是用.net core 和 Ocelot搭建的可扩展的高性能Api网关. Ocelot(http:// ...

随机推荐

  1. Python 基础教程(有经典的例子)

    http://www.runoob.com/python/os-listdir.html

  2. poj1113凸包

    就是求凸包的周长加以l为半径的圆周长,证明略 由于之前写过叉积,所以graham扫描算法不是很难理解 #include<map> #include<set> #include& ...

  3. nyoj520——素数序列

    最大素因子 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 GreyAnts最近正在学习数论中的素数,但是现在他遇到了一个难题:给定一个整数n,要求我们求出n的最大素 ...

  4. HUST 1328 String (字符串前缀子串个数 --- KMP)

    题意 给定一个字符串S,定义子串subS[i] = S[0..i],定义C[i]为S中subS[i]的数量,求sigma(C[i])(0<=i<N). 思路 我们以子串结尾的位置来划分阶段 ...

  5. A网页高度随B内容而自然变化兼容各种浏览器

    今天是星期一,昨天又没有睡好,眼睛干干的,还有点痛疼,于是不想干啥.但是心里又不觉得过意不去,浪费时间呀,考虑再三把自己前面实现的一个东西发了上来.算是今天的功劳,没有过多的文字描述,纯粹是贴图片和代 ...

  6. web版源码管理软件SCM-Manager安装配置

    背景 一直使用 “VisualSvn Server” 作为源码管理工具,使用一段时间之后,使用场景遇到以下问题 添加用户必需登录到服务器. 一台服务器,只能安装一个 “VisualSvn Server ...

  7. Redis数据结构:跳跃表

    1. 跳跃表是有序集合(zset)的底层实现之一: 2. 由zskiplist和zskiplistNode组成: 3. 每个跳跃表节点的层数都是1-32之间的随机数(每创建一个节点的时候,程序会随机生 ...

  8. C++面向对象高级编程(七)point-like classes和function-like classes

    技术在于交流.沟通,转载请注明出处并保持作品的完整性. 1.pointer-like class 类设计成指针那样,可以当做指针来用,指针有两个常用操作符(*和->),所以我们必须重载这两个操作 ...

  9. (转)MapReduce Design Patterns(chapter 3 (part 2))(六)

    Top Ten Pattern Description Top ten模式跟前面的有很大的不同,跟输入数据大小无关,最终得到的记录数量是确定的.而在通用filtering中,输出的规模取决于输入数据. ...

  10. 在ROS Kinetic和Gazebo 8中使用智能汽车仿真演示

    在ROS Kinetic和Gazebo 8中使用智能汽车仿真演示 智能车无人驾驶技术是目前人工智能和机器人技术的研究热点,有许多开源平台可以使我们零基础零成本入门无人驾驶技术.本文分享一下目前ROS官 ...