Automated deployment and management of a K3s Kubernetes cluster using Ansible. This project enables easy setup and teardown of a multi-node K3s cluster, connecting to an external MariaDB database, and dedicated control plane and agent nodes.
- Automated K3s cluster deployment and uninstallation
- Multi-node support with control plane and agent nodes
- External MariaDB database integration
- Detailed status reporting and health checks
- Idempotent operations - safe to re-run
-
Configure your inventory and variables (see Configuration section)
-
Install K3s cluster:
ansible-playbook -i hosts k3s-install.yaml -K
-
Uninstall K3s cluster (if needed):
ansible-playbook -i hosts k3s-uninstall.yaml -K
-
Configure your inventory in
hosts:[control_plane] cp1 ansible_host=192.168.1.2 cp2 ansible_host=192.168.1.3 [agents] agent1 ansible_host=192.168.1.4 agent2 ansible_host=192.168.1.5
-
Update configuration in
group_vars/all.yaml:k3s_version: "v1.31.5+k3s1" # Specify K3s version to install k3s_token: "your_secure_token" # Security token for cluster formation db_endpoint: "mysql://user:pass@host:3306/k3s" # MySQL database connection string api_endpoint: "your_api_ip" # IP address where the Kubernetes API will be exposed
-
Enable / Disable default components :
- Remove `--disable=traefik` to keep the built-in Traefik ingress controller - Remove `--disable=servicelb` to use the built-in ServiceLB load balancer - Remove `--datastore-endpoint` to use the default embedded etcd instead of external database
ansible-k3s/
├── group_vars/
│ └── all.yaml
├── hosts
├── k3s-install.yaml
├── k3s-uninstall.yaml
├── LICENSE
└── README.md
-
Check node status:
kubectl get nodes
-
Check cluster health:
kubectl get --raw /healthz
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or need support, please file an issue on the GitHub repository.
This project is licensed under the GNU GENERAL PUBLIC LICENSE v3.0 - see the LICENSE file for details.