本篇内容介绍了“Traefik怎么使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
traefik是一个使你把微服务暴露出来变的更容易的http反向代理和负载均衡软件。traefik支持K8S、docker swarm、mesos、consul、etcd、zookeeper等基础设施组件,个人认为更适合容器化的微服务,traefik的配置会自动的、动态的配置更新自己。
本篇主要模拟的是traefik+docker swarm mode的场景,由traefik自动发现swarm mode下的service
ubuntu16.04-1 | swarm manager | traefik |
ubuntu16.04-2 | swarm works | |
ubuntu16.04-3 | swarm works |
ps:还是之前文章做实验的swarm集群
wget 'https://github-production-release-asset-2e65be.s3.amazonaws.com/42408804/b7288f00-a48e-11e8-817e-298aa1a8bae9?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180903%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180903T065922Z&X-Amz-Expires=300&X-Amz-Signature=4d4a6a61122a5e0ac8aaae5da30883d555db307c2a9dbe1e300fb1dc2decb0a2&X-Amz-SignedHeaders=host&actor_id=12913767&response-content-disposition=attachment%3B%20filename%3Dtraefik_linux-amd64&response-content-type=application%2Foctet-stream'
ps:把下载完的traefik_linux-amd64二进制文件重命名成traefik,上传到镜像制作服务器。
Dockfile
FROM scratch COPY ./traefik / EXPOSE 80 ENTRYPOINT ["/traefik"]
docker build -t traefik .
docker tag traefik 172.31.68.241/library/traefik docker push 172.31.68.241/library/traefik
docker network create --driver=overlay traefik-net
ps:traefik和app要在同一个网络内,否则traefik识别不到app
docker service create \ --name traefik \ --constraint=node.role==manager \ --publish 8090:80 --publish 8080:8080 \ --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ --network traefik-net \ 172.31.68.241/library/traefik \ --docker \ --docker.swarmMode \ --docker.domain=example.org \ --docker.watch \ --logLevel=DEBUG \ --web
http://172.31.68.241:8080/dashboard/
docker service create --replicas 2 --network traefik-net --label traefik.port=80 --label traefik.frontend.rule=Host:test.example.org --name hello 172.31.68.241/library/friendlyhello
curl -H Host:test.example.org http://172.31.68.241:8090
docker service create --replicas 2 --network traefik-net --label traefik.port=80 --label traefik.frontend.rule=Host:test.example.org --label traefik.backend.loadbalancer.sticky=true --name hello 172.31.68.241/library/friendlyhello
curl -c cookies.txt -H Host:test.example.org http://172.31.68.241:8090 curl -b cookies.txt -H Host:test.example.org http://172.31.68.241:8090
“Traefik怎么使用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。