【问题标题】:Ingress Nginx NLB get Client Real IP (Broken header: "" while reading PROXY protocol)Ingress Nginx NLB 获取客户端真实 IP(损坏的标头:\"\" 在读取 PROXY 协议时)
【发布时间】:2022-12-30 21:00:28
【问题描述】:

我已经通过私有 NLB(网络负载平衡器)公开了入口 nginx 控制器。我想在入口 Nginx 上启用主机白名单。
我的用例是允许从 VPC1 到 VPC2 的请求,并且只允许来自 VPC1 的请求通过这个私有 nginx。为此,我使用了下面的注释
nginx.ingress.kubernetes.io/whitelist-source-range
我从中得到的问题是 ingress-nginx 没有收到客户端的真实 IP。在做了一些研究后,我发现我必须在 NLB 上启用代理协议。为此,我添加了以下注释和配置。

         annotations:
              service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
              service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: '60'
              service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: 'true'
              service.beta.kubernetes.io/aws-load-balancer-type: nlb
              service.beta.kubernetes.io/aws-load-balancer-internal: "true"
              service.beta.kubernetes.io/aws-load-balancer-target-group-attributes: proxy_protocol_v2.enabled=true
          metrics:
            enabled: true
          config:
            use-proxy-protocol: "true"
            real-ip-header: "proxy_protocol"

准确地说,我只添加了这部分

       config:
            use-proxy-protocol: "true"
            real-ip-header: "proxy_protocol"

       service.beta.kubernetes.io/aws-load-balancer-target-group-attributes: proxy_protocol_v2.enabled=true
    
I've also tried this annotation with same config
       service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"

我收到的错误是

broken header: "" while reading PROXY protocol, client: xx.xx.xx.xx

我无法弄清楚我做错了什么。任何帮助是极大的赞赏。

更新 1:
我检查了此注释未启用 aws 控制台代理协议。当我手动启用它时,一切正常。但我不明白为什么这不起作用,是否与我使用的入口 nginx 版本有关?

【问题讨论】:

    标签: kubernetes-helm kubernetes-ingress nlb ingress-nginx proxy-protocol


    【解决方案1】:

    为了启用代理协议并使此注释起作用
    service.beta.kubernetes.io/aws-load-balancer-target-group-attributes: proxy_protocol_v2.enabled=true
    我们必须使用 aws 负载均衡器控制器。有了这个注释 service.beta.kubernetes.io/aws-load-balancer-type: nlb kubernetes 使用它自己的负载均衡器控制器,它不支持这个注释。
    要使用 aws 负载均衡器控制器,我们需要添加这些注释。

    service.beta.kubernetes.io/aws-load-balancer-type: external
    service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance/ip (on the basis of your use case).
    

    有关详细信息,请参阅this文档。
    如果您想深入了解并检查 kubernetes 代码库,请关注link

    【讨论】:

      猜你喜欢
      • 2013-08-01
      • 1970-01-01
      • 2020-05-22
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 2020-10-21
      • 2020-08-23
      • 2022-01-18
      相关资源
      最近更新 更多