Skip to content

Instantly share code, notes, and snippets.

@offlinehacker
Created June 1, 2024 12:02
Show Gist options
  • Save offlinehacker/fc3d83ef44a30d70d35ec88bbd7c4b2e to your computer and use it in GitHub Desktop.
Save offlinehacker/fc3d83ef44a30d70d35ec88bbd7c4b2e to your computer and use it in GitHub Desktop.
Systemd service for k3s to take tailscale IP as node ip
[Unit]
Description=Generates K3S NodeIP Entry With Tailscale IP
Requires=network.target
Requires=tailscaled.service
Before=k3s.service
[Service]
Type=oneshot
RemainAfterExit=yes
# k3s config file
Environment=CONFIG_FILE=/etc/rancher/k3s/config.yaml.d/tailscale.yaml
# wait until tailscale is ready
ExecStartPre=/bin/bash -c 'until tailscale status; do echo waiting for tailscale to be up && sleep 1; done'
# make sure config directory exists
ExecStartPre=/bin/bash -c 'mkdir -p `dirname $CONFIG_FILE`'
# compose configuration file
ExecStart=/bin/bash -c '\
echo "node-ip: `tailscale ip -4`" > "$CONFIG_FILE"; \
echo "advertise-address: `tailscale ip -4`" >> "$CONFIG_FILE"; \
cat "$CONFIG_FILE"'
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment