Skip to content

peterweissdk/ansible-k3s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💾 Ansible K3s Cluster Deployment

Static Badge Static Badge

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.

✨ Features

  • 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

🚀 Quick Start

  1. Configure your inventory and variables (see Configuration section)

  2. Install K3s cluster:

    ansible-playbook -i hosts k3s-install.yaml -K
  3. Uninstall K3s cluster (if needed):

    ansible-playbook -i hosts k3s-uninstall.yaml -K

🔧 Configuration

  1. 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
  2. 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
    
  3. 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

📝 Directory Structure

ansible-k3s/
├── group_vars/
│   └── all.yaml
├── hosts
├── k3s-install.yaml
├── k3s-uninstall.yaml
├── LICENSE
└── README.md

🔍 Health Check

  1. Check node status:

    kubectl get nodes
  2. Check cluster health:

    kubectl get --raw /healthz

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🆘 Support

If you encounter any issues or need support, please file an issue on the GitHub repository.

📄 License

This project is licensed under the GNU GENERAL PUBLIC LICENSE v3.0 - see the LICENSE file for details.

About

Ansible playbook for automated deployment and configuration of a K3s Kubernetes cluster

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published