K8S POD如何获取客户端IP

  • 问题:
    在K8S上部署应用时候,会发现从POD里边获取的IP一直都是F5的IP,思虑良久,怀疑是Ingres端那边被丢弃了类似X-FORWARD-FOR的信息,于是就有了下面的解决方案。
  • 解决方案:
    Rancher上配置界面如下,在项目:System,命名空间ingress-nginx,配置映射: nginx-configuration中增加键值对即可。
    • 参数说明:
      (1)compute-full-forwarded-for
      Append the remote address to the X-Forwarded-For header instead of replacing it. When this option is enabled, the upstream application is responsible for extracting the client IP based on its own list of trusted proxies.
      (2)forwarded-for-header
      Sets the header field for identifying the originating IP address of a client. default: X-Forwarded-For
      (3)use-forwarded-headers
  • If true, NGINX passes the incoming X-Forwarded-* headers to upstreams. Use this option when NGINX is behind another L7 proxy / load balancer that is setting these headers.
  • If false, NGINX ignores incoming X-Forwarded-* headers, filling them with the request information it sees. Use this option if NGINX is exposed directly to the internet, or it’s behind a L3/packet-based load balancer that doesn’t alter the source IP in the packets.
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: ingress-nginx
  name: nginx-configuration
  namespace: ingress-nginx
data:
  compute-full-forwarded-for: "true"  #
  forwarded-for-header: X-Forwarded-For
  use-forwarded-headers: "true"

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值