Change default port numbers in docker deployment

Hi. I am new to Syncthing, deploying it for the first time. It appears to be a helpful product, wish I had discovered it sooner. I have a docker deployment related issue though.

I wish to run Syncthing in a k3s (kubernetes) cluster. Thankfully Syncthing provides official docker image. The problem that I have is not specific to k3s, if it can be done in docker it can be done in k3s too.

I noticed that Syncthing uses 3 ports:

  1. gui, port 8384
  2. transfer, port 22000
  3. local discovery (broadcast?), port 21027

I wish to change the default port numbers while deploying to k3s or docker. gui port (#1) can be changed by setting STGUIADDRESS environment variable. But I couldn’t find anything like that for the remaining two ports. I have seen tutorials to change these ports in configuration file. But is there a way to set it in docker or kubernetes deployment file?

No, it’s set in the config file, only. Why though? What happens in the container doesn’t need to be what you expose to the outside world. And local discovery is pretty much guaranteed not to work in a Kubernetes setup. I expect you’d need to wire up the appropriate services and configure connection from other devices to go via those services.

I only intend to expose it to my LAN (192.168.2.x)

Even if I wire port 22000 & 21027 from pod, through kubernetes-service to LoadBalancer?

That way port 22000 & 21027 of the host (k3s cluster host) should be accessible to other devices in the LAN. Other devices will identify host as a Syncthing device. The host will redirect that traffic to kubernetes which in turn will route it to the pod. I am using traefik as my LoadBalancer.

Local discovery is UDP multicast/broadcast. I don’t think you can do what you want with it.

Ok, NO local discovery then. But offline sync should still work as long as port 22000 traffic from host gets forwarded by kubernetes to Syncthing pod – right?

If I map port 22000 from pod to some other port in host, will local transfer still work?

Since you won’t have local discovery, all you have to go by is global discovery. Presumably the clients are “normal” and their addresses will be announced correctly, so your k8s-hosted Syncthing could connect out to the clients.

In the other direction, the k8s-hosted Syncthing would announce it’s local port and IP (which will be some meaningless pod-local IP), and it’s local port and outside-visible-IP as seen by the discovery server. This may or may not be what you want your clients to connect to. If it is, then having the same port number in the pod as on the outside will make things work out of the box. It doesn’t matter if that’s 22000 or 45678 though, as long as what Syncthing announces is what can be connected to in the end.

If the addresses announced and discovered in this manner won’t work, then you’ll need to configure the address manually on your clients. This should be fine, presumably your cluster will have a permanent address. At that point, since you’re configuring the address manually, the port can be whatever you want it to be and it doesn’t matter if it’s the same on the outside and inside as long as the forwarding ends up in the right place in the end.

Ok, got it working. Thanks for all the help.

I had to configure devices manually. And I had to keep port numbers same all the way from host to k3s pod. I also tried changing port numbers, where I mapped syncthing pod with default port number to a custom port number on host - that didn’t work.

changing port numbers where I mapped syncthing pod with default port number to a custom port number on host - also works but connection need to be started from k3s hosted instance.