Report this

What is the reason for this report?

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

Posted on April 25, 2020

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



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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 https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#whitelist-source-range
  • 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,

-Conrad

Hi there,

A quick update here in case that anyone comes across this in the future.

In addition to what has already been mentioned, DigitalOcean has just announced that Control plane firewalls are now available in Early Availability.

The feature improves security and traffic for your cluster. Once enabled, only configured IP addresses, cluster worker nodes and workloads, and internal systems that manage the cluster (such as cluster upgrades) can access the control plane.

Existing open connections continue to work until they terminate. However, for WATCH requests, the API server enforces a maximum of 30 minutes for terminating the open connection.

For more information, see How to Add a Control Plane Firewall.

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.