Cloudgaze.
← Alle artikelen

Implementing tailscale in a Cloud-Native home lab

In this blog post, we will explore how I integrated the tailscale operator in my home-lab, while keeping the setup as "Cloud Native" as possible.

The Cloud-Native home lab

As a cloud engineer, a home lab for me, should be a place to practice and explore Cloud-Native tools while keeping my setup as close as possible to production at work. This makes it easy for me to explore tools in my homelab, and implement them at work if they are promising enough. At the same time, exposing everything to the internet is a bad security practice, especially when you consider a home lab is more of a hobby than a job. Enterprise environments are usually way more secure.

Secure access

I was looking for a way to move my applications behind a VPN so I could enjoy my home lab away from home, expose apps like usual, and keeping everything as native as possible. Then I found the tailscale operator. It advertises it can expose Kubernetes Services to your tailscale VPN, making them accessible from anywhere. This however, is really not what I wanted to do, it made me throw up a little bit when I read it. Thankfully the Tailscale Operator has many different approaches to expose your applications.

My setup

I would like to expose my applications through my Kubernetes Gateway, kgateway. The Tailscale Operator can hand out Loadbalancer IP's to your services. Besides my public gateway, I chose to set up a VPN-gateway. I configured tailscale to give my Kubernetes Gateway a Loadbalancer IP, which can be routed on the tailnet. I achieved this with the following yaml snippet:

apiVersion: gateway.kgateway.dev/v1alpha1
kind: GatewayParameters
metadata:
  name: tailscale
spec:
  kube:
    serviceOverlay:
      metadata:
        annotations:
          tailscale.com/hostname: kgateway-vpn
      spec:
        type: LoadBalancer
        loadBalancerClass: tailscale
        externalTrafficPolicy: Cluster
        allocateLoadBalancerNodePorts: false

Then refer to these GatewayParameters in your gateway with:

...
spec:
  infrastructure:
    parametersRef:
      group: gateway.kgateway.dev
      kind: GatewayParameters
      name: tailscale

The result

Now, it is possible to create HTTPRoutes for your VPN-gateway to expose them to the tailnet. Only the HTTPRoutes are exposed, nothing else. With this setup, you can keep using HTTPRoutes normally to expose your applications, but now securely.

Usage patterns

Now you have two gateways, your existing public gateway and your VPN Gateway. If you only want to use the VPN gateway, feel free to remove the old gateway. I chose to keep it. With this setup, I am very flexible in what I want to expose publicly and what I would like to expose via Tailscale. One example: I need my Keycloak realm to be available publicly, so users can access their applications from anywhere, without requiring access to my Tailscale. I chose to not expose the admin interface at all. Now, I can expose the admin interface to my Tailscale VPN, while keeping realm access public. This is why I love the Kubernetes Gateway API.

Round-up

Hopefully this blog gave you additional insights in how to use Tailscale to put your applications behind a VPN in a Cloud-Native and secure way.