Skip to content

Instantly share code, notes, and snippets.

@shiponcs
Created November 9, 2024 09:26
Show Gist options
  • Save shiponcs/30e5bb81b8f98b43fca48c1697f119d5 to your computer and use it in GitHub Desktop.
Save shiponcs/30e5bb81b8f98b43fca48c1697f119d5 to your computer and use it in GitHub Desktop.
Add an IP to an existing k3s cluster

Problem: Let's say you have created a k3s cluster and now you want to access it from outside the network. To do that you need to assign a public IP to your machine the cluster is running on. Recently I installed tailscale on the VM (on which a k3s cluster was running) so that I can access the cluster from my home. Here's how I did that.

  1. First we need to add the Tailscale IP to tls-san of the cluster.

By default, configuration files are read from /etc/rancher/k3s/config.yaml and /etc/rancher/k3s/config.yaml.d/*.yaml in alphabetical order. 1

So, we create a config file if it doesn't exist:

cd /etc/rancher/k3s
touch config.yaml

And, add this content to the file:

tls-san:
  - <tailscale-ip>
  - <other ips>
  1. Restart k3s cluster service
systemctl restart k3s
  1. Collect the update kubeconfig file and update the following field:
    server: <tailscale-ip>:6443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment