Search code examples
nginxkubernetesibm-cloudkubernetes-ingressnginx-ingress

Preserve client source IP for Kubernetes ingress?


I am using this Ingress it is similar to Nginx: https://cloud.ibm.com/docs/containers?topic=containers-ingress_annotation#general

When I do:

request -> LoadBalancer Service -> client source public IP returned
request -> Ingress -> LoadBalancer Service -> some private IP returned

I would like to preserve the client source public IP. In my Service I am setting ExternalTrafficPolicy: Local, and it works when hitting the LoadBalancer directly, but I do not know what setting I require when going through the Ingress.


Solution

  • For preserving Ingress source IP, see these steps: https://cloud.ibm.com/docs/containers?topic=containers-comm-ingress-annotations#preserve_source_ip_classic

    Essentially you do the same thing that you've described, except that you edit the existing alb service.


    steps:

    • kubectl edit svc <ALB_ID> -n kube-system
    • Under spec, change the value of externalTrafficPolicy from Cluster to Local.