Repository navigation
Ansible
RaΓΊl Tapara Y. edited this page Sep 3, 2025
·
1 revision
This project automates the installation and configuration of a Kubernetes cluster using Ansible. The project is designed to deploy a Kubernetes cluster with kubeadm in a Proxmox environment, automatically configuring both master and worker nodes.
- Master Node: 1 node (192.168.100.220)
- Worker Nodes: 2 nodes (192.168.100.223, 192.168.100.224)
- Runtime: Containerd
- Network: Configuration with network modules for Istio/Kubeflow
ansible/
βββ ansible.cfg # Ansible configuration
βββ site.yaml # Main playbook
βββ Taskfile.yml # Automated tasks with Task
βββ inventory/
β βββ hosts.ini # Host inventory
β βββ group_vars/
β βββ all.yaml # Global variables
βββ roles/
β βββ prepare-nodes/ # Node preparation
β βββ configure-master-node/ # Master configuration
β βββ configure-worker-node/ # Worker configuration
β βββ kubeconfig/ # Kubeconfig configuration
β βββ reset-vm/ # Cluster reset (optional)
βββ collections/
β βββ requirements.yaml # Required Ansible collections
βββ output/ # Logs and output files
- Ansible 2.9+
- Python 3.x
- Task (go-task) for automation
- SSH access to target nodes
# MacOS
brew install go-task/tap/go-task
# Ubuntu/Debian
sudo apt install taskansible-galaxy collection install -r collections/requirements.yamlEdit inventory/hosts.ini with your node IPs:
[k8s_master]
cluster-kubeadm-k8s-master-01 ansible_host=192.168.100.220
[k8s_worker]
cluster-kubeadm-k8s-worker-01 ansible_host=192.168.100.223
cluster-kubeadm-k8s-worker-02 ansible_host=192.168.100.224Adjust variables in inventory/group_vars/all.yaml:
os: "linux"
arch: "amd64"
ansible_user: rtaparay
ansible_ssh_private_key_file: ~/.ssh/ansibleEnsure passwordless SSH access is configured:
ssh-copy-id -i ~/.ssh/ansible.pub rtaparay@192.168.100.220
ssh-copy-id -i ~/.ssh/ansible.pub rtaparay@192.168.100.223
ssh-copy-id -i ~/.ssh/ansible.pub rtaparay@192.168.100.224# Test complete configuration
task test:all
# Test master only
task test:site:master
# Test workers only
task test:site:worker# Execute complete configuration
task apply:all
# Main playbook only
task apply:site
# Kubeconfig configuration only
task apply:kubeconfigansible all -i inventory/hosts.ini -m ping# Full deployment
ansible-playbook site.yaml -i inventory/hosts.ini
# Master nodes only
ansible-playbook site.yaml -i inventory/hosts.ini --limit k8s_master
# Worker nodes only
ansible-playbook site.yaml -i inventory/hosts.ini --limit k8s_worker
# Check mode (dry run)
ansible-playbook site.yaml -i inventory/hosts.ini --check- Disables swap
- Configures kernel modules (overlay, br_netfilter)
- Installs and configures containerd
- Configures modules for Istio/Kubeflow
- Installs kubeadm, kubelet and kubectl
- Initializes cluster with kubeadm
- Configures cluster network
- Generates join token for workers
- Joins worker nodes to cluster
- Configures kubelet on workers
- Copies kubeconfig from master
- Configures cluster access
- Completely resets the cluster
- Cleans Kubernetes configurations
Logs are stored in the output/ directory:
-
ansible-YYYY-MM-DD_HH-MM-SS.log: Execution logs -
kubeconfig: Kubernetes configuration file
After deployment, verify cluster status:
# Copy kubeconfig
scp rtaparay@192.168.100.220:~/.kube/config ~/.kube/config
# Verify nodes
kubectl get nodes
# Verify system pods
kubectl get pods -A
# Verify cluster status
kubectl cluster-info-
SSH connectivity error
ansible all -i inventory/hosts.ini -m ping
-
Swap issues
sudo swapoff -a sudo sed -i '/ swap / s/^/#/' /etc/fstab -
Cluster reset
# Uncomment reset-vm role in site.yaml ansible-playbook site.yaml -i inventory/hosts.ini --tags reset
# Execute with maximum verbosity
ansible-playbook site.yaml -i inventory/hosts.ini -vvvTo contribute to the project:
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
This project is licensed under the MIT License. See the LICENSE file for more details.