How can expose a kubernete service to a specific IP (not all internet)

Posted April 25, 2020 1.4k views
KubernetesDigitalOcean Cloud FirewallsDigitalOcean Managed Load Balancers

Hi, english is not my first language and i’m still learning, sorry for grammar and spelling mistakes.

I need to a client to connect to specific service inside my kubernetes cluster. I try using a load balancer and work, the problem whit this approach is security. I cant restrict access to the service to a single IP in the load balancer, so is published to all internet. Also dont what to user ingress (i want to block at TCP level), so, what are my alternatives ?

thank you

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Currently, there is no way to restrict access to the load balancers or nodeports. You do have a few options:

  • As mentioned by @conradwt above you can use network policy objects to enact restrictions.
  • You can use an ingress controller as your exposed service and take advantage of their security annotations, nginx support whitelisting ips for example
  • You can set up your own droplet and install and configure a load balancer on it. This would allow you to apply a DO cloud firewall in front of that. The issue with this approach is you would need to automate the changing node IP’s as targets for your load balancer.

Hope that helps!

Hi, if you’re wanting to restrict who can connect or have access to your service endpoints, you’re going to need to setup the proper network policies here. For example, you can use a network policy provider like Project Calico. Also, here are some good resources that you may find helpful:

The above resources should be able to assist you in configuring your K8s cluster.

Think different and code well,