π§± Whatβs included in this phase?
- β Automated Kubernetes cluster installation with kubeadm
- β Master and worker nodes configuration with containerd runtime
- β Network modules preparation for Istio
- β SSH key management and passwordless authentication
- β Cluster verification and kubeconfig setup
- β Task automation with go-task for streamlined operations
π¦ Technologies:
- π€ Ansible 2.9+
- βΈοΈ Kubernetes (kubeadm)
- π³ Containerd Runtime
- β‘ Task (go-task) for automation π§ Ubuntu Server 24.04 LTS
- π§ Python 3.13
π Setting Up StackOpsys Overview
π Project Structure Overview
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 setup
β βββ reset-vm/ # Cluster reset (optional)
βββ collections/
β βββ requirements.yaml # Required Ansible collections
βββ output/ # Logs and output files
π Detailed Workflow:
βοΈ Configuration Examples
Inventory Configuration
[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.224
Global Variables
os: "linux"
arch: "amd64"
ansible_user: <user>
ansible_ssh_private_key_file: ~/.ssh/ansible
ansible_become: true
Cluster Architecture
- Master Node: 1 node (192.168.100.220)
- Worker Nodes: 2 nodes (192.168.100.223, 192.168.100.224)
- Runtime: Containerd
- Network: Pre-configured for Istio
π Usage Steps
1. Prerequisites Setup
# Install Task (MacOS)
brew install go-task/tap/go-task
# Install Ansible collections
ansible-galaxy collection install -r collections/requirements.yaml
# Setup SSH keys
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
2. Testing (Dry Run)
# Test complete configuration
task test:all
# Test master only
task test:site:master
# Test workers only
task test:site:worker
3. Full Deployment
# Execute complete configuration
task apply:all
# Or step by step
task apply:site
task apply:kubeconfig
4. Alternative: Direct Ansible
# Connectivity verification
ansible all -i inventory/hosts.ini -m ping
# Full deployment
ansible-playbook site.yaml -i inventory/hosts.ini
π§ Ansible Roles Breakdown:
prepare-nodes - Disables swap permanently - Configures kernel
modules (overlay, br_netfilter) - Installs and configures containerd -
Prepares modules for Istio/Kubeflow - Installs kubeadm, kubelet, and
kubectl
configure-master-node - Initializes Kubernetes cluster with
kubeadm - Configures cluster networking - Generates join tokens for
worker nodes
configure-worker-node - Joins worker nodes to the cluster -
Configures kubelet on worker nodes
kubeconfig - Copies kubeconfig from master node - Sets up cluster
access configuration
π Outputs & Verification
Generated Files
output/
βββ ansible-2025-01-XX_XX-XX-XX.log # Execution logs
βββ kubeconfig # Kubernetes config
Cluster Verification Commands
# Copy kubeconfig locally
scp rtaparay@192.168.100.220:~/.kube/config ~/.kube/config
# Verify cluster status
kubectl get nodes
kubectl get pods -A
kubectl cluster-info
Expected Output
NAME STATUS ROLES AGE VERSION
cluster-kubeadm-k8s-master-01 Ready control-plane 5m v1.28.x
cluster-kubeadm-k8s-worker-01 Ready <none> 3m v1.28.x
cluster-kubeadm-k8s-worker-02 Ready <none> 3m v1.28.x
π Task Automation Features
Available Tasks
-
task init
- Initialize log directories -
task test:all
- Run all tests (dry-run) -
task apply:all
- Full cluster deployment -
task apply:site
- Main playbook execution -
task apply:kubeconfig
- Kubeconfig setup only
Automated Logging
- Timestamped log files
- Structured output directory
- Verbose execution tracking
π οΈ Troubleshooting & Reset
Common Issues
# SSH connectivity test
ansible all -i inventory/hosts.ini -m ping
# Manual swap disable
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab
# Verbose execution
ansible-playbook site.yaml -i inventory/hosts.ini -vvv
Cluster Reset (Optional)
# Uncomment reset-vm role in site.yaml
ansible-playbook site.yaml -i inventory/hosts.ini --tags reset
β Whatβs next?
With your Kubernetes cluster now fully automated:
- πΉ Deploy CNI plugins(Calico)
- πΉ Configure service mesh (Istio)
π€ Complete StackOpsys Journey
Part 1: ποΈ Custom VM templates with Packer
Part 2: βοΈ Infrastructure provisioning with Terraform
Part 3: π€ Cluster automation with Ansible
π Full project available at: π github.com/rtaparay/stackopsys
Top comments (0)