Search code examples
kuberneteskubernetes-ingress

Is there a way to enable proxy-protocol on Ingress for only one service?


I have this service that limits IPs to 2 requests per day running in Kubernetes. Since it is behind an ingress proxy the request IP is always the same, so it is limiting he total amount of requests to 2.

Its possible to turn on proxy protocol with a config like this:

apiVersion: v1
metadata:
  name: nginx-ingress-controller
data:
  use-proxy-protocol: "true"
kind: ConfigMap

But this would turn it on for all services, and since they don't expect proxy-protocol they would break.

Is there a way to enable it for only one service?


Solution

  • It is possible to configure Ingress so that it includes the original IPs into the http header.

    For this I had to change the service config. Its called ingress-nginx-ingress-controller(or similar) and can be found with kubectl get services -A

    spec: 
       externalTrafficPolicy: Local
    

    And then configure the ConfigMap with the same name:

    data:
      compute-full-forwarded-for: "true"
      use-forwarded-headers: "true"
    

    Restart the pods and then the http request will contain the fields X-Forwarded-For and X-Real-Ip.

    This method won't break deployments not expecting proxy-protocol.