1.7 KiB
1.7 KiB
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:
- Install dependencies: Installs
qemu-guest-agent. - Primary Server Installation:
- Downloads the K3s installation script.
- Installs the K3s server on the primary node with a TLS SAN.
- Pull Token:
- Retrieves the K3s token from the primary server.
- Stores the token in an Ansible Vault encrypted file.
- Secondary Server Installation:
- Installs K3s on the secondary servers, joining them to the cluster using the token from the vault.
- Create Kubeconfig:
- Slurps the
k3s.yamlfrom the primary server. - Creates a kubeconfig file on the local machine for accessing the cluster.
- Slurps the
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"