Preserve Source IP when using NLB and Nginx Ingress Controller
Preserve Source IP when using vLB Layer 4 and Nginx Ingress Controller in Kubernetes is the process of maintaining the client's original IP address when traffic is forwarded through the load balancer and into the Kubernetes cluster. This is important in some cases when you need detailed information about the client's connection, such as the client's original IP address and root port, to be able to make traffic handling or logging decisions. Exactly. Below are our specific instructions to help you implement this usecase.
Prerequisites
You have initialized the Cluster on the VKS system according to the instructions here and VNGCloud Controller Manager has been installed on your cluster with appversion from v0.2.1 or higher. If your appversion is lower than this standard version, you can perform the upgrade according to the following instructions:
First, you need to get the release name of vngcloud-controller-manager installed on your cluster:
Then, please upgrade to the latest version via the command:
Next, you need to install nginx-ingress-controller with the command:
ConfigMap for Nginx Ingress Controller
Add to Nginx Ingress Controller's ConfigMap the settings to enable proxy protocol via command:
The code you need to add is as follows:
Configure vLB Layer 4
Next, you need to configure vLB Layer4 to allow the use of proxy protocol for the Load Balancer Nginx service. The input value is a list of service names in Load Balancer using Proxy Protocol.
Finally, please perform NLB testing on vLB Portal until these Load Balancers are ACTIVE with full listener and pool.
Using
Suppose, you have a service prometheus-node-exporter with port 9100 in the default namespace, you can apply the following yaml to make it accessible via NLB
Then I use IP 103.245.252.75 to curl to host kkk.example.com as follows:
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2F1985221522-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F7rE7M1L7GYcwQzNGd0aB%252Fuploads%252Fken9OEXz8qhYvjc8y3pn%252Fimage.png%3Falt%3Dmedia%26token%3D7dc8fc0b-9a62-4d32-93bb-89f98042db86&width=768&dpr=4&quality=100&sign=2bb93a1a&sv=1)
The recorded log result has this Client IP information as shown:
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2F1985221522-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F7rE7M1L7GYcwQzNGd0aB%252Fuploads%252FHqtVY1piUy3nBTAKTkET%252Fimage.png%3Falt%3Dmedia%26token%3D83e9157d-7074-4f25-ba4a-e1fd40a743a5&width=768&dpr=4&quality=100&sign=639999cf&sv=1)
Last updated