You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/docs/k8s
David Wolever 0c427f23bd docs/k8s: don't call kubectl directly from Makefile
Instead of calling kubectl directly in k8s Makefile, write the yaml to
stdout so it can be reviewed/edited/etc before manually applying with
kubectl.

Fixes: #8511

Signed-off-by: David Wolever <david@wolever.net>
1 year ago
..
Makefile
README.md
proxy.yaml
role.yaml
rolebinding.yaml
sa.yaml
sidecar.yaml
subnet.yaml
userspace-sidecar.yaml

README.md

Overview

There are quite a few ways of running Tailscale inside a Kubernetes Cluster, some of the common ones are covered in this doc.

Instructions

Setup

  1. (Optional) Create the following secret which will automate login.
    You will need to get an auth key from Tailscale Admin Console.
    If you don't provide the key, you can still authenticate using the url in the logs.

    apiVersion: v1
    kind: Secret
    metadata:
      name: tailscale-auth
    stringData:
      TS_AUTHKEY: tskey-...
    
  2. Tailscale (v1.16+) supports storing state inside a Kubernetes Secret.

    Configure RBAC to allow the Tailscale pod to read/write the tailscale secret.

    export SA_NAME=tailscale
    export TS_KUBE_SECRET=tailscale-auth
    make rbac | kubectl apply -f-
    

Sample Sidecar

Running as a sidecar allows you to directly expose a Kubernetes pod over Tailscale. This is particularly useful if you do not wish to expose a service on the public internet. This method allows bi-directional connectivity between the pod and other devices on the Tailnet. You can use ACLs to control traffic flow.

  1. Create and login to the sample nginx pod with a Tailscale sidecar

    make sidecar | kubectl apply -f-
    # If not using an auth key, authenticate by grabbing the Login URL here:
    kubectl logs nginx ts-sidecar
    
  2. Check if you can to connect to nginx over Tailscale:

    curl http://nginx
    

    Or, if you have MagicDNS disabled:

    curl "http://$(tailscale ip -4 nginx)"
    

Userspace Sidecar

You can also run the sidecar in userspace mode. The obvious benefit is reducing the amount of permissions Tailscale needs to run, the downside is that for outbound connectivity from the pod to the Tailnet you would need to use either the SOCKS proxy or HTTP proxy.

  1. Create and login to the sample nginx pod with a Tailscale sidecar

    make userspace-sidecar | kubectl apply -f-
    # If not using an auth key, authenticate by grabbing the Login URL here:
    kubectl logs nginx ts-sidecar
    
  2. Check if you can to connect to nginx over Tailscale:

    curl http://nginx
    

    Or, if you have MagicDNS disabled:

    curl "http://$(tailscale ip -4 nginx)"
    

Sample Proxy

Running a Tailscale proxy allows you to provide inbound connectivity to a Kubernetes Service.

  1. Provide the ClusterIP of the service you want to reach by either:

    Creating a new deployment

    kubectl create deployment nginx --image nginx
    kubectl expose deployment nginx --port 80
    export TS_DEST_IP="$(kubectl get svc nginx -o=jsonpath='{.spec.clusterIP}')"
    

    Using an existing service

    export TS_DEST_IP="$(kubectl get svc <SVC_NAME> -o=jsonpath='{.spec.clusterIP}')"
    
  2. Deploy the proxy pod

    make proxy | kubectl apply -f-
    # If not using an auth key, authenticate by grabbing the Login URL here:
    kubectl logs proxy
    
  3. Check if you can to connect to nginx over Tailscale:

    curl http://proxy
    

    Or, if you have MagicDNS disabled:

    curl "http://$(tailscale ip -4 proxy)"
    

Subnet Router

Running a Tailscale subnet router allows you to access the entire Kubernetes cluster network (assuming NetworkPolicies allow) over Tailscale.

  1. Identify the Pod/Service CIDRs that cover your Kubernetes cluster. These will vary depending on which CNI you are using and on the Cloud Provider you are using. Add these to the TS_ROUTES variable as comma-separated values.

    SERVICE_CIDR=10.20.0.0/16
    POD_CIDR=10.42.0.0/15
    export TS_ROUTES=$SERVICE_CIDR,$POD_CIDR
    
  2. Deploy the subnet-router pod.

    make subnet-router | kubectl apply -f-
    # If not using an auth key, authenticate by grabbing the Login URL here:
    kubectl logs subnet-router
    
  3. In the Tailscale admin console, ensure that the routes for the subnet-router are enabled.

  4. Make sure that any client you want to connect from has --accept-routes enabled.

  5. Check if you can connect to a ClusterIP or a PodIP over Tailscale:

    # Get the Service IP
    INTERNAL_IP="$(kubectl get svc <SVC_NAME> -o=jsonpath='{.spec.clusterIP}')"
    # or, the Pod IP
    # INTERNAL_IP="$(kubectl get po <POD_NAME> -o=jsonpath='{.status.podIP}')"
    INTERNAL_PORT=8080
    curl http://$INTERNAL_IP:$INTERNAL_PORT