How to expose tcp service in Kubernetes only for certain ip addresses?

1k Views Asked by At

Nignx ingress provides a way to expose tcp or udp service: all you need is public NLB.

However this way tcp service will be exposed publicly: NLB does not support security groups or acl, also nginx-ingress does not have any way to filter traffic while proxying tcp or udp.

The only solution that comes to my mind is internal load balancer and separate non-k8s instance with haproxy or iptables, where I'll actually have restrictions based on source ip - and then forward/proxy requests to internal NLB.

Maybe there are another ways to solve this?

2

There are 2 best solutions below

0
On

Yo can use the whitelist-source-range annotation for that. We've been using it successfully for a few use cases and it does the job well.

EDIT: I spoke too soon. Rereading your question and understanding your exact use case brought me to this issue, which clearly states these services cannot be whitelisted, and suggests solving this in the firewall level.

0
On