【问题标题】:Openshift 3.11 header based routing基于 Openshift 3.11 标头的路由
【发布时间】:2019-06-28 15:40:13
【问题描述】:

我正在尝试在 Openshift 3.11 上实现基于标头的路由。

我的意思是,我希望 HAProxy 根据标头的存在和值而不是主机名将请求路由到某个服务。标头值将在路由配置中设置。

我知道使用 HAProxy 可以做到这一点,但我不知道该怎么做。 我遵循了我找到的一条建议 here 但似乎配置已更改并且不再起作用。

欢迎提出任何建议。我有一个替代方案,那就是放置一个可以完成工作的第二个代理,但这一点也不优雅......

【问题讨论】:

    标签: haproxy openshift-origin okd


    【解决方案1】:

    好的,我设法让它正常工作。但帮助的不是文档。 我在问题中发布的链接中显示的一段代码是放在以下配置部分下:

    • frontend public(http 代理)
    • frontend fe_sni(带有自定义证书的 https 代理)
    • frontend fe_no_sni(带有默认证书的 https 代理)

    此外,这段代码很旧,并且不包含实际的变量名称。 对于每条路线,这是一个:

    • 查找名为haproxy.router.openshift.io/tenant-id 的路由注释
    • 创建 2 个 acls 检查名为 tenant-id 的 cookie 的值以及主机是否为预期主机(主机值可通过路由注释 haproxy.router.openshift.io/tenant-hostname 进行配置
    • 检查 2 个 acls 是否返回 true,如果是,则向路由后面的服务发出 http 请求
      # Custom snippet for balancing through HTTP headers
      {{- range $cfgIdx, $cfg := .State }}
      {{- if (ne (index $cfg.Annotations "haproxy.router.openshift.io/tenant-id") "") }}
      acl custom_header_{{index $cfg.Annotations "haproxy.router.openshift.io/tenant-id"}} cook(tenant-id) {{index $cfg.Annotations "haproxy.router.openshift.io/tenant-id"}}
      acl configured_host_{{index $cfg.Annotations "haproxy.router.openshift.io/tenant-id"}} hdr(host) {{index $cfg.Annotations "haproxy.router.openshift.io/tenant-hostname"}}
      use_backend be_edge_http:{{$cfgIdx}} if configured_host_{{index $cfg.Annotations "haproxy.router.openshift.io/tenant-id"}} custom_header_{{index $cfg.Annotations "haproxy.router.openshift.io/tenant-id"}}
    
      {{- end }}
      {{- end }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-10
      • 2016-06-24
      • 2020-12-16
      • 2021-08-02
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 2017-01-14
      相关资源
      最近更新 更多