traefik v2 https router service etcd 边缘 Edge Gateway 博客园
(相关资料图)
---【前言】---
写本文目的: 网上应该没有 traefik v2 配 etcd 的例子。
traefik被我喜爱的原因:跨平台,支持win,linux版同时使用。同时支持监控目录和etcd。
- 支持win,linux版同时使用。
- 支持etcd的同时,支持watch文件目录。而另一台traefik,可以配置为只用etcd。很方便在win上,编辑toml文件调试。然后通过dashboard查看是否成功。测试正常后,再向etcd中写入,以达到数据面高可用的目的。
- traefik的etcd键值设计的特别好!!!它用复杂的key,简单的值。而不是像其他任何基于eted键值的网关那样,用简单的key,复杂的值。
---【正文】---
测试版本:traefik v2.9.10 for win。原则上,linux版本一样。
问:手册在哪?
答:https://doc.traefik.io/traefik/reference/dynamic-configuration/kv/
https://doc.traefik.io/traefik/routing/providers/kv
问:要打开etcd存储,静态配置文件traefik.toml应该如何配置?
答:[providers.etcd]endpoints = "192.168.1.2:2379"
问:如何添加上游?
答:
./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/services/baidushangyou/loadBalancer/servers/0/url" -v "http://test1.baidu.com:443"./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/services/baidushangyou/loadBalancer/servers/1/url" -v "http://test2.baidu.com:443"
下面的例子,添加一个从 https://test223.com ,到https://www.baidu.com 的反向代理。
问:如何添加路由?
答:
./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/routers/my-router-https/entryPoints/0" -v "websecure"./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/routers/my-router-https/service" -v "noop@internal"./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/routers/my-router-https/rule" -v "Host(`test223.com`) && PathPrefix(`/baidu`)"./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/routers/my-router-https/middlewares/0" -v "https-upstream"./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/routers/my-router-https/tls" -v "true"
问:如何添加默认key?
答:
./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/tls/stores/default/defaultCertificate/certFile" -v "a:/traefik_v2.9.10/test223.cert"./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/tls/stores/default/defaultCertificate/keyFile" -v "a:/traefik_v2.9.10/test223.key"
问:如何添加中间件?
答:
./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/middlewares/https-upstream/redirectRegex/regex" -v "^https://test223.com/baidu$"./put-etcdKey.ps1 -endpoint "http://192.168.1.2:2379" -k "traefik/http/middlewares/https-upstream/redirectRegex/replacement" -v "https://www.baidu.com"
问:本文涉及的,ps1脚本库在哪?
答:
https://gitee.com/chuanjiao10/powershell/tree/master/gateway_client/traefik
谢谢观看,完。