Logo

dev-resources.site

for different kinds of informations.

Connect to Kubernetes Pods with Tailscale

Published at
4/3/2022
Categories
kubernetes
selfhost
tailscale
devops
Author
kasuboski
Author
9 person written this
kasuboski
open
Connect to Kubernetes Pods with Tailscale

I wasn't ready to add auth to my new feedreader. So I built a moat with Tailscale.

What does that mean?

I added a kubernetes pod to my tailnet so it's accessible from anywhere that can route to Tailscale nodes. It also gets a nice domain name so http://feedreader works.

Tailscale actually has a blog post and example for how to set this up. I wanted it to be mildly different so modified their run script. They also don't publish their example image so I needed to build one.

You can see my version at kasuboski/tailscale-proxy. The main differences are it takes a HOSTNAME and DEST_PORT parameters.

The HOSTNAME is so you can set the name the node will show up as. This was important for kubernetes because I don't want the generated name of the pod to be how I access it. DEST_PORT is so you can have it forward to a different port. This allows you to run your app on 8080, but the tailscale-proxy will route any port to 8080 meaning you can hit it on 80 in your browser. This is required to not have :8080 ugliness after your URL.

But Why?

I've been making a feedreader to replace my running miniflux. It's my first real rust project and I wanted an even more minimal feedreader.

I haven't gotten around to figuring out users or authentication in the feedreader though. Despite this, it finally reached the point where I can use it as my main feedreader. However, I didn't exactly want an unauthenticated app hanging out on the internet for someone to ruin my day.

If you don't want to make authentication, just make it inaccessible. This is where Tailscale comes in. I already run Tailscale on all the nodes, which is how I'm able to have a multi-region k3s cluster. That doesn't make my pods routable though.

Tailscale has an option for a subnet router that is actually highlighted as how to access all things k8s in the examples. This probably would have been nice (and I might still add it), but I wouldn't automatically get dns routing I believe.

You can see how it's all put together in my k8s-gitops repo. The gist is that you add a sidecar container that starts tailscale and in my case adds an iptables rule which forwards all traffic to the app port. You can see my poor Doppler secret naming in there too where everything is using miniflux-secret.

So, no more auth?

I still want to add users to the feedreader so that you can have multiple users on one instance. It remains to be seen whether I'll just add basic auth or something more complicated. Tailscale let me focus on getting something usable quickly though.

After seeing how convenient it was to expose a pod with a dns name, I also want to make a debugging tool injecting tailscale to pods. I could then finely be rid of the finicky kubectl port-forward.

selfhost Article's
28 articles in total
Favicon
Portainer + gitops ❀️: A simple way to deploy and manage your self-hosted applications
Favicon
Information flow - how I capture the notes
Favicon
I Am Done With Self-Hosting
Favicon
Hoppscotch Cloud vs. Self-Hosted Community vs. Self-Hosted Enterprise – Which One Should You Choose?
Favicon
Hoppscotch v2024.3.0: Access Control, Variable Scopes and more..
Favicon
Exploring Open Source # 1: Calibre E-book Library
Favicon
A Year of Self-Hosting: 6 Open-Source Projects That Surprised Me in 2023
Favicon
Dockerize an OCI Instance
Favicon
OCI Instance with External Block Volume
Favicon
Open-source Fine-Tuning on Codebase with Refact
Favicon
Deploying Medusa to Oracle Cloud
Favicon
CapRover - Easy and Free Self-Hosted PaaS!
Favicon
2023 On Prem Kubernetes Container Attached Storage Options
Favicon
BEST Postman Alternative: Hoppscotch πŸ›Έ - open source, self hosted API Development Ecosystem
Favicon
Self-hosted Matomo - an implementation guide for production
Favicon
PresenceJS: The Simplest Way to Power Realtime Experience in My Collaborative Apps , From Current to The Future
Favicon
A minimal ChatGPT client by vanilla javascript, run from local or any web host
Favicon
Need help with the following error…!
Favicon
What's on my Raspberry-Pi
Favicon
Connect to Kubernetes Pods with Tailscale
Favicon
self-host forem on cloud other than gcp,aws,digitalocean
Favicon
Self-hosted newsletter tech stack for $0-7/mo
Favicon
Self-hosting Quirrel
Favicon
Please help how to host two forem domain in a single server
Favicon
O que Γ© selfhosting e por que adotΓ‘-lo
Favicon
Leaving Feedly for Miniflux
Favicon
Connect Your Home to the Cloud with Tailscale
Favicon
Pixelfed (beta) with Docker and Traefik

Featured ones: