How Can I Whitelist Client IPs with F5 Load Balancer and NodePort in Kubernetes?
Asked by
88 tiles remaining
I'm facing a networking issue in my Kubernetes cluster that hosts over 100 microservices, and I need some advice on how to handle client IP visibility and whitelisting. My current setup involves an external F5 Load Balancer (L4) directing traffic to Kubernetes NodePort services, which then connect to the individual pods. All services are running with `externalTrafficPolicy: Cluster`. The main challenge is that I need to restrict access to specific microservices based on the real client IP, but setting it up this way causes source NAT (SNAT) to occur. This means the microservices see the internal IP of the node instead of the client's real IP. I'm unable to switch to `externalTrafficPolicy: Local` because I don't have access to the F5 configuration, and migrating to Ingress isn't feasible right now due to the number of legacy services. Additionally, the F5 team cannot manage dynamic IP whitelisting rules. Given these constraints, are there any known methods or tricks to filter traffic based on the original client IP? Any advice or solutions would be greatly appreciated!
Answers
You might want to consider setting up a firewall on each Kubernetes host. This would allow you to restrict access to the specific ports for each microservice, filtering by allowed IPs before the SNAT occurs. It could be a viable solution for your situation!
Reply to this answer
Another option could be using a specific CNI plugin with port-mapping capabilities to add iptables rules that block unwanted client IPs. This could allow you to filter traffic effectively. You might take a look at CNI's portmap plugin for more details.
Reply to this answer
The client IP is usually preserved in headers, particularly `X-Forwarded-For`, which can help with filtering. If you're using Cilium CNI or Cilium Ingress, it might work for you, but I'm not sure if itโs always effective unless used with the Gateway API. Itโs worth checking out, especially versions >1.18.
Reply to this answer
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions