Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot stop loadbalancer from binding to my public IP #11504

Closed
fboerman opened this issue Dec 26, 2024 · 11 comments
Closed

cannot stop loadbalancer from binding to my public IP #11504

fboerman opened this issue Dec 26, 2024 · 11 comments

Comments

@fboerman
Copy link

Environmental Info:
K3s Version:
k3s version v1.31.3+k3s1 (6e6af98)
go version go1.22.8

Node(s) CPU architecture, OS, and Version:
Linux trajan 6.12.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 19 Dec 2024 21:29:01 +0000 x86_64 GNU/Linux

Cluster Configuration:
single server single node on a hetzner VPS

Describe the bug:
I want k3s and the load balancer to only bind on an internal interface but it always binds to the public one as well. I cannot get it to stop binding to 0.0.0.0

Steps To Reproduce:

  • Installed K3s:
  • edited the systemd unit with the following flags: --node-external-ip 10.3.23.1 --node-ip 10.3.23.1 --bind-address 10.3.23.1
  • I then try with the public ip of the server to do a curl, this always gives a response from traefik

Expected behavior:
curl localhost or curl should give an error that it cannot connect

Actual behavior:
a http response is given from traefik

Additional context / logs:
load balancing rules:
get svc --all-namespaces
kube-system traefik LoadBalancer 10.43.69.59 10.3.23.1 80:30497/TCP 2d10h

@brandond
Copy link
Member

brandond commented Dec 26, 2024

Please read the docs: https://docs.k3s.io/networking/networking-services#how-servicelb-works

When the ServiceLB Pod runs on a node that has an external IP configured, the node's external IP is populated into the Service's status.loadBalancer.ingress address list with ipMode: VIP. Otherwise, the node's internal IP is used.

@github-project-automation github-project-automation bot moved this from New to Done Issue in K3s Development Dec 26, 2024
@brandond
Copy link
Member

brandond commented Dec 26, 2024

Note that the --bind-address only affects the apiserver. It does not affect the loadbalancer, as the loadbalancer uses iptables to forward traffic and does not actually 'bind' to anything.

Again, this is all covered in the docs.

@fboerman
Copy link
Author

fboerman commented Dec 26, 2024 via email

@brandond
Copy link
Member

Set the node IP to the private IP, and don't set an external IP.

@fboerman
Copy link
Author

fboerman commented Dec 27, 2024 via email

@brandond
Copy link
Member

After changing the CLI args, you'd probably need to kubectl delete node the existing node, then restart k3s.

@fboerman
Copy link
Author

@brandond I created a brand new vps, only added --node-ip and did not supply --node--external-ip and still I can reach default traefik and any other service I create on the public ip. is there any way to stop this behaviour? the docs are really unclear on this

@brandond
Copy link
Member

brandond commented Feb 24, 2025

You can set the loadBalancerSourceRanges field on your Service spec to restrict it. Ref: https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/#:~:text=loadBalancerSourceRanges

Note that servicelb does not "bind" to anything. It just works with the kubelet to forward traffic from the hostport, to the service.

@fboerman
Copy link
Author

@brandond ah thats interesting thanks, how do I that for everything including traefik? because traefik is by default enabled I dont create that service myself?

@brandond
Copy link
Member

brandond commented Feb 24, 2025

It is configured at the Service level, so you'd need to set it through traefik chart values.

This is all just core Kubernetes Loadbalancer Service stuff, not specific to Traefik or K3s.

@fboerman
Copy link
Author

@brandond thanks! sorry for that I am just a bit bewildered by all the options so not sure what is k3s specific or not. My simple test works now by adding it to the traefik chart as described in the docs here: https://docs.k3s.io/helm#customizing-packaged-components-with-helmchartconfig and now the little test vps seems to work like I want. thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done Issue
Development

No branches or pull requests

2 participants