Kubernetes on Raspberry Pi with Ansible - Usage Guide
This guide details how to use the generated Ansible playbook to install Kubernetes on your Raspberry Pi cluster.
Prerequisites
- Ansible Installed: You need Ansible installed on your control machine (your laptop/desktop).
- Debian/Ubuntu:
sudo apt update && sudo apt install ansible sshpass -y - Arch Linux:
sudo pacman -S ansible sshpass - Fedora:
sudo dnf install ansible sshpass
- Debian/Ubuntu:
- SSH Access: Ensure you have SSH access to all Raspberry Pi nodes.
- Hardware: 4 Raspberry Pi nodes (1 Master, 3 Workers) with Raspberry Pi OS installed.
Configuration Steps
1. Configure Inventory
Edit inventory/hosts.ini and replace the placeholder IP addresses with the actual IPs of your Raspberry Pis.
[masters]
pi1 ansible_host=192.168.1.10 <-- Change to Master IP
[workers]
pi2 ansible_host=192.168.1.11 <-- Change to Worker 1 IP
pi3 ansible_host=192.168.1.12 <-- Change to Worker 2 IP
pi4 ansible_host=192.168.1.13 <-- Change to Worker 3 IP
2. Configure Credentials
You need to set the SSH password for the pi user. We use Ansible Vault for security.
-
Generate an encrypted password string:
ansible-vault encrypt_string 'YOUR_ACTUAL_PASSWORD' --name 'vault_ssh_password'Replace
YOUR_ACTUAL_PASSWORDwith the real password. -
Copy the output block and paste it into
group_vars/all.yml, replacing the commented out section or just adding it.Example in
group_vars/all.yml:ansible_password: !vault | $ANSIBLE_VAULT;1.1;AES256 ... (encrypted string) ...Do the same for
vault_become_passwordif your sudo password is different. If sudo password is same as ssh password, you can just set:ansible_become_password: "{{ vault_ssh_password }}"
3. Run the Playbook
To start the installation, run:
ansible-playbook site.yml --ask-vault-pass
Note: Since you used encrypt_string without a password file, it might ask for a vault password if you set one. If you just used encrypt_string, you might need to provide the vault password you used to encrypt it.
Alternative (Simpler for testing): If you don't want to use Vault yet, you can pass the password as an extra var (INSECURE - be careful with history):
ansible-playbook site.yml -e "ansible_password=yourpassword ansible_become_password=yourpassword"
Verification
After the playbook completes:
-
SSH into the Master Node:
ssh pi@<master-ip> -
Check Nodes:
kubectl get nodesYou should see 4 nodes with status
Ready. -
Check Pods:
kubectl get pods -AEnsure
corednsandkube-flannelare running.
Kubernetes Dashboard
A dashboard has been installed and is accessible via NodePort on the master node.
-
Get the Token: Run this command on the master node to get your login token:
kubectl get secret admin-user-token -n kubernetes-dashboard -o jsonpath={".data.token"} | base64 -d -
Access the Dashboard: Open your browser and navigate to:
https://<master-ip>:30443Note: Since it uses a self-signed certificate, you will need to bypass the browser security warning (usually click "Advanced" -> "Proceed").