Kubernetes Raspberry Pi Lab Environment Setup Using Ansible
After manually setting up a Lightweight Kubernetes cluster on a few of my Raspberry Pi’s I decided to tear it all down, and rebuild it from scratch using Ansible, and an infrastructure as code strategy.
This gives me a chance to catchup a bit on ansible, and keep my documentation and notes for this project in a replay-able Github repository. The project at the moment is rough, and contains sensitive details; however, this is a local lab environment that will most likely be trashed later on, so I’m not worried.
https://github.com/jness/ansible-k3s
Like before, I needed to freshly install Raspberry Pi OS on to my microsd cards; however, this time I had my dhcp server configured to assign predictable ip addresses, ip addresses that are referenced in the repositories hosts configuration file.
Once my two Raspberry Pi model 3 were booted and on the network, I’m able to use this repository to run playbooks for my Kubernetes server (k3s-server), and Kubernetes agents (k3s-agent).
$ docker-compose run app ansible-playbook k3s-server.yml
PLAY RECAP ***********************************************************************
192.168.1.250 : ok=7 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Assuming each of these plays were successful, we should have a working control-plane.
Connect to this server and fire off a kubectl
to confirm:
user@k3server1:~ $ sudo kubectl get node
NAME STATUS ROLES AGE VERSION
k3server1 Ready control-plane,master 1h v1.26.3+k3s1
With our k3s server running we can now run our k3s-agent
playbook:
$ docker-compose run app ansible-playbook k3s-agent.yml
PLAY RECAP ***********************************************************************
192.168.1.251 : ok=6 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
If this execution was successful we should now have our 2 node Kubernetes cluster:
user@k3server1:~ $ sudo kubectl get node
NAME STATUS ROLES AGE VERSION
k3server1 Ready control-plane,master 1h v1.26.3+k3s1
k3node1 Ready <none> 20m v1.26.3+k3s1
At this point it appears everything is up and working, we can confirm our control-plane pods which k3s deploys
in the kube-system
namespace:
user@k3server1:~ $ sudo kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system local-path-provisioner-5d56847996-6wdwp 1/1 Running 0 29h
kube-system helm-install-traefik-crd-lfh8k 0/1 Completed 0 29h
kube-system helm-install-traefik-wjrrl 0/1 Completed 2 29h
kube-system svclb-traefik-ff88ccc4-2n75p 2/2 Running 0 29h
kube-system svclb-traefik-ff88ccc4-dvdzj 2/2 Running 0 101m
kube-system coredns-7c444649cb-k7w9t 1/1 Running 0 29h
kube-system metrics-server-7b67f64457-4rmt4 1/1 Running 0 29h
kube-system traefik-56b8c5fb5c-bp5nz 1/1 Running 0 29h
Hope my notes and exploration have been helpful.
Cheers