I tried to obtain the source global IP address from HTTP requests through Kubernetes Ingress, but I ended up getting the IP address of Kubernetes' local network, which wasn't successful.
By switching Kubernetes to microk8s and using the built-in ingress controller, I was able to obtain the global remote IP address. Here are the notes.
The OS of the node is Ubuntu 20.04
In 2021.
The LAN is 192.168.0.0/24, and both the Kubernetes nodes and the requesting PC have IP addresses of 192.168.0.X.
I started Rancher with Docker, and in the built-in k3s cluster, I deployed the following:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/baremetal/deploy.yaml
This set up the ingress controller.
When I started an nginx pod and made a request through Ingress, checking the access logs showed:
X-Real-IP: 10.42.0.1
X-Forwarded-For: 10.42.0.1
This was the IP address of the gateway within Kubernetes.
I wanted this to be the original IP address of the requesting PC, but I couldn't find any useful information to achieve that.
In 2022.
I discarded the above Kubernetes cluster and created a new MicroK8s cluster.
sudo snap install microk8s --classic
Enabled the Ingress controller
microk8s enable dns ingress
With the Ingress manifest and other configurations the same as in step 1, when I made a request, the logs showed:
X-Real-IP: 192.168.0.159
X-Forwarded-For: 192.168.0.159
This correctly obtained the client's IP address.
Comments