Dimitar Lazarov
Dimitar Lazarov

Reputation: 1

NGINX TCP LB ProxyProtocol > LB IP

Greetings guys I am running a home lab with a kubernetes cluster behind nginx loadbalancer deployed in a separate vm within the cluster private subnet.

Basically it is a WSL2 with VirtualBox running inside for nested virtualization and I have a kubernetes cluster(k3s and microk8s) and a VM that acts as a LoadBalancer(NGINX).

The load balancer VM is running NGINX TCP with the following config

stream {
    server {
        listen     80;
        proxy_pass http_backend;
        proxy_protocol on;
    }

    server {
        listen     443;
        proxy_pass https_backend;
        proxy_protocol on;
    }

    upstream http_backend {
        server 192.168.56.10:30080;
        server 192.168.56.21:30080;
        server 192.168.56.22:30080;
    }

    upstream https_backend {
        server 192.168.56.10:30443;
        server 192.168.56.21:30443;
        server 192.168.56.22:30443;
    }
}

on Kubernetes side I have Istio IngressGateway that is configured to accept proxy protocol.

When I have the setup configured to use proxy protocol I get

x-forwarded-for=10.0.2.2 which is the LoadBalancer VM NAT cidr

When I disabled the proxyprotocol i get

x-forwarded-for=10.1.219.64 which is the cluster cidr

I have also tested it by moving the LB on the host directly and I get x-forwarded-for=192.168.1.1 So basically LB to Cluster configuration is set right because I use similar configuration on cloud enviroments and it works

The problem is that NGINX is sending the wrong IP instead of the client IP

I beleive it is something small that has to be configured in NGINX but not sure what.

I have tried to place set_real_ip_from 192.168.1.0/24; as per https://docs.nginx.com/nginx/admin-guide/load-balancer/using-proxy-protocol/

but it says "set_real_ip_from" directive is not allowed here

Any idea waht else I can try ?

Upvotes: 0

Views: 47

Answers (0)

Related Questions