Files
ansible/roles/k3s_server
Tuan-Dat Tran 5bc3024eaf feat(k3s): replace nginx loadbalancer with kube-vip for control-plane HA
Deploys kube-vip as a DaemonSet on all k3s server nodes, advertising a
VIP (192.168.20.2) via ARP. Eliminates the single-point-of-failure
k3s-loadbalancer VM.

- New kube_vip role: RBAC + DaemonSet templates, TLS SAN cert rotation
- playbooks/kube-vip.yaml: migration playbook (serial=1, idempotent)
- Updated k3s install tasks (server primary/secondary, agent) to use k3s_vip
  instead of the loadbalancer VM IP
- Added k3s_vip: 192.168.20.2 to group_vars (below DHCP range .11-.250)

Migration steps in playbook header comment.
2026-04-26 12:08:42 +02:00
..
2025-11-07 20:44:14 +01:00
2025-11-07 20:44:14 +01:00
2025-07-27 16:40:46 +02:00

K3s Server Ansible Role

This Ansible role installs and configures a K3s server cluster.

Role Variables

  • k3s_primary_server_ip: The IP address of the primary K3s server.
  • k3s_server_name: The server name for the K3s cluster.
  • k3s_cluster_name: The name for the K3s cluster in the kubeconfig.
  • k3s_user_name: The user name for the K3s cluster in the kubeconfig.
  • k3s_context_name: The context name for the K3s cluster in the kubeconfig.
  • k3s_server_token_vault_file: The path to the Ansible Vault file containing the K3s token. Default is ../vars/group_vars/k3s/secrets_token.yml.

Tasks

The main tasks are:

  1. Install dependencies: Installs qemu-guest-agent.
  2. Primary Server Installation:
    • Downloads the K3s installation script.
    • Installs the K3s server on the primary node with a TLS SAN.
  3. Pull Token:
    • Retrieves the K3s token from the primary server.
    • Stores the token in an Ansible Vault encrypted file.
  4. Secondary Server Installation:
    • Installs K3s on the secondary servers, joining them to the cluster using the token from the vault.
  5. Create Kubeconfig:
    • Slurps the k3s.yaml from the primary server.
    • Creates a kubeconfig file on the local machine for accessing the cluster.

Handlers

  • Restart k3s: Restarts the K3s service.

Usage

Here is an example of how to use this role in a playbook:

- hosts: k3s_servers
  roles:
    - role: k3s_server
      vars:
        k3s_primary_server_ip: "192.168.1.100"
        k3s_server_name: "k3s.example.com"
        k3s_cluster_name: "my-k3s-cluster"
        k3s_user_name: "my-k3s-user"
        k3s_context_name: "my-k3s-context"