Skip to content

nelsonyaccuzzi/hypriot-k8s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hypriot Kubernetes Cluster

Create a Kubernetes Cluster using Raspberry Pi's, HypriotOS, and KubeAdm.

Prerequisites

  • Raspberry Pi 3/4

With KubeAdm you only need one node (1 master) to start playing with K8s, so feel free to add up any number of nodes you want.

  • Linux

Ansible only works under Linux. So if you are using a Windows workstation you can create a Linux Virtual Machine or use WSL

Ansible is a powerful configuration manager that is used here to bootstrap the K8s cluster.

HypriotOS is a Debian based distribution for Raspberry Pi. It preloads docker and optimize it to make it easy to use. It also bring support for cloud-init configs.

  • Openshift Python Module

Ansible use it to operate with the Kubernetes Cluster. You can install it easily with pip. And due to this issue you have to set the kubernetes package version to 11.0.0

pip install openshift
pip install kubernetes==11.0.0

Steps

Clone the repository

git clone https://github.com/nelsonyaccuzzi/hypriot-k8s.git
cd hypriot-k8s

Complete the inventory

Edit the inventory and vars file with your variables and hosts

[master]
rpi-mst-01 ansible_host=192.168.0.211
rpi-mst-02 ansible_host=192.168.0.212
rpi-mst-03 ansible_host=192.168.0.213

[worker]
rpi-wrk-01 ansible_host=192.168.0.214
rpi-wrk-02 ansible_host=192.168.0.215
rpi-wrk-03 ansible_host=192.168.0.216


master_ip_address: 192.168.0.210
network_mask: 255.255.0.0
gateway_ip_address: 192.168.0.1
dns_ip_address: 192.168.0.35

cluster_address: k8s
kubernetes_version: 1.18.4

Create ssh keys

You need to create the ssh keys to connect to the nodes.


mkdir keys
ssh-keygen -f keys/id_k8s -N ""

Create cloud-init configs


ansible-playbook -i inventory -e "@vars" playbooks/configs.yml

After this, a folder name user-data will appear in this repo with the cloud-init files for each raspberry

Download Image

Download the HypriotOS image from the Official Repo Realease Page.


wget https://github.com/hypriot/image-builder-rpi/releases/download/v1.12.2/hypriotos-rpi-v1.12.2.img.zip
unzip hypriotos-pi-v1.12.2.img.zip

Flash MicroSD Cards

You can use any tool you like to do this, but in the end you have to copy the content of each cloud-init file in the user-data file inside the /boot partition of each microSD card

If you are using Linux you can use the Hypriot Flash Tool to flash and copy the cloud-init in the same command, like this


flash -u <cloud-init_file> <hypriotos_image>

Select the correct device where the microSD are mounted.

Repeat the command for every microSD card, changing the cloud-init file.

Check Connectivity

The cloud-init configs configures the eth0 interface with the inventory specified ip address and network configuration, wlan0 support will be added later.


ansible all -m ping -i inventory --private-key keys/id_k8s -u pi

Passwordless connections are also configured for the pi user and the keys are located in the keys folder

Create the K8s Cluster

Execute the playbook


ansible-playbook -i inventory -e "@vars" main.yml

Checking

Checking on nodes

kubectl get nodes

NAME         STATUS   ROLES                  AGE     VERSION
rpi-mst-01   Ready    control-plane,master   7m4s    v1.21.0
rpi-wrk-01   Ready    worker                 6m33s   v1.21.0
rpi-wrk-02   Ready    worker                 6m35s   v1.21.0

Cleanup Cluster

If you want to keep playing you can start over with the following command


ansible-playbook -i inventory playbooks/cleanup.yml

References

This playbook was created following this helpful repos

About

Create a Kubernetes Cluster using Raspberry Pi'si, HypriotOS, and KubeAdm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages