Created
June 1, 2024 12:02
-
-
Save offlinehacker/fc3d83ef44a30d70d35ec88bbd7c4b2e to your computer and use it in GitHub Desktop.
Systemd service for k3s to take tailscale IP as node ip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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