REDDIT 原始帖子

Cloudflared + Docker Swarm + NPM(Or Trafek?) with root domain pointing at github pages

Hey All, I got two mini PCs that are in a docker swarm, I am wondering if there is a good way to set up a system so I can just deploy a new container and have whatever system im using, just make the DNS record. The main issue here is that, my root domain…

原帖正文r/selfhosted

Hey All, I got two mini PCs that are in a docker swarm, I am wondering if there is a good way to set up a system so I can just deploy a new container and have whatever system im using, just make the DNS record. The main issue here is that, my root domain points to Github pages. From what I can find, this, isn't something that has been documented before, so if its really needed. I can just make the records on my own, but if there is a way to avoid that, it would be nice. Thanks.

已收录讨论

5 条评论

u/asimovs-auditor

Expand the replies to this comment to learn how AI was used in this post/project.

u/LakesideMinersOP

Oh, nice! Thank you! I was gonna just have Cloudflared be on the master node, I don't really care much about availability or replicas. So if the master node goes down it's whatever. Il mess around with this when I get home but, other then that, thank you!

u/Aggravating_War_6704

Nice, yeah for a homelab that's totally fine, wouldn't overthink the HA part. One small thing when you set it up: have cloudflared point at Traefik by its service name rather than a fixed node IP, so it still finds it even if that container moves nodes. Otherwise you're set, ping me if it gets weird.

u/Aggravating_War_6704

The github pages on your root isn't really the blocker it feels like here. Your apex record and your subdomain records are totally separate, so you can leave yourdomain.com on GH Pages and just point subdomains like app.yourdomain.com at your swarm stuff. The only thing that actually rules out is serving the root itself from the swarm, which it doesn't sound like you need anyway. For not touching DNS every time you deploy, honestly the easiest trick is to just wildcard it once. Point *.yourdomain.com at your tunnel (a CNAME to the whatever.cfargotunnel.com target), send that wildcard through the tunnel to Traefik, and let Traefik match on the Host header from your service labels. After that you never make another DNS record again. A new service just needs its Traefik label with the hostname on it and it resolves through the wildcard automatically. That's what I'd do. If you specifically want real per-service records in Cloudflare instead of a wildcard (cleaner dashboard, more control per host), there's a companion container for that, traefik-cloudflare-companion (the tiredofit one). It watches your Traefik/swarm labels and creates or updates the CNAMEs for you on deploy, which is basically the "just make the record for me" thing you're describing. On NPM vs Traefik, I'd go Traefik for this. It reads labels and it's built for swarm, so routing just registers itself when a service comes up. NPM is more of a click-in-the-GUI-per-host thing and it won't touch DNS at all, so it kind of fights what you're trying to automate. One thing that changes how you'd wildcard it: is it one cloudflared per node, or a single tunnel in front of the whole swarm? Depends how you've got that part wired.

u/Overall_Weakness_433

You don't need the root domain to point at your homelab for this to work. Leave the apex on GitHub Pages and use subdomains for your self-hosted services. For automatic routing, Traefik is probably the better fit than NPM since it can watch Docker Swarm and create routes as services come and go. I keep the registrar separate at somewhere like dynadot, but the DNS automation is usually handled by Cloudflare's API rather than the registrar anyway. With cloudflared, you can either use a wildcard tunnel (*.example.com) or have Traefik plus a companion that talks to the Cloudflare API create DNS records automatically. That way, deploying a new service is just adding the right labels, without touching your root domain or manually creating records each time.