Sources: https://microk8s.io/docs
- 2 or more Raspberry Pi (the Raspberry Pi 3B is recommended)
- 2 or more SD Cards
- 5V and 2.5A Power Supply for each Pi
- Insert the SD card then run
$ diskutil list
- Unmount the target disk
$ diskutil unmountDisk /dev/diskN (where N is the target disk)
- Copy the image
$ sudo dd bs=1m if=path/to/your/image.img of=/dev/rdiskN; sync (where N is the target disk)
- Eject the SD card
$ sudo diskutil eject /dev/rdiskN (where N is the target disk)
Goal:
k8s-master
k8s-worker-01
k8s-worker-02
k8s-worker-03
- Enable SSH
$ sudo apt update
$ sudo apt install openssh-server
$ sudo systemctl status ssh
- Change the hostname
$ nano /etc/hostname
- Edit the hosts file:
$ nano /etc/hosts
Replace the "127.0.0.1 localhost" line with the new hostname so: "172.0.0.1 k8s-master localhost" for example. 4. Update
$ apt update && apt upgrade
- Reboot
- SSH into your Pi
$ ssh [email protected]
- Enable c-groups (to make kubelet work out of the box)
$ sudo nano /boot/firmware/cmdline.txt
- Add the following options
cgroup_enable=memory cgroup_memory=1
Expected:
cgroup_enable=memory cgroup_memory=1 net.ifnames=0 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
- Reboot
- Install MicroK8s snap
sudo snap install microk8s --classic
- Repeat step 0-4 for the remaining Pis
See: https://microk8s.io/docs/addons
$ microk8s enable dns
$ microk8s enable storage
$ microk8s enable metallb (You’ll be prompted for a range of IP addresses here, pick one on the same subnet as the Kubenetes nodes)
$ microk8s enable ingress
$ microk8s enable dashboard
$ microk8s enable registry
!You may need to enable your firewall to allow communication between nodes
sudo ufw allow in on cni0 && sudo ufw allow out on cni0
sudo ufw default allow routed
- Generate a connection string for master node
$ sudo microk8s.add-node
- Join master from other nodes
$ microk8s.join <master_ip>:<port>/<token>
Ex: $ microk8s.join 10.55.60.14:25000/JHpbBYMIevZSAMnmjMHmFwanrOYCWZLu
- Verify if new node has been joined/added ! To this on master node !
$ microk8s.kubectl get node
- Repeat step 2 for the remaining nodes you want to add to the cluster
- Remove a node from master
$ sudo microk8s remove-node <node name>
- Alternatively, to leave the cluster from any node
sudo microk8s.leave
! Master node ONLY!
- Install Docker
$ apt-get install docker.io
$ sudo systemctl enable docker
$ sudo systemctl start docker
- Create the Docker File for your application ! The Raspberry Pi is an ARM based processor architecture, therefore you can only run images that are compiled for ARM, you can't run x86/x64 architecture images.
$ touch DockerFile (with your application)
- Create an Docker image from DockerFile
$ docker build -f Dockerfile -t my-application:local .
- Export Docker image
$ docker save my-application > my-application.tar
- Import the Docker image into Kuerbetes Repository
$ microk8s ctr image import my-application.tar
- Verify that the Docker image has successfully imported
$ microk8s ctr images ls
- Create a deployment.yaml and service.yaml files
$ touch deployment.yaml
$ touch service.yaml
- Deploy your application
$ kubectl apply -f deployment.yaml
$ kubectl apply -f service.yaml
- Check pods status
$ microk8s kubectl get pods
- Show services
$ microk8s kubectl get services
- Remove the Application (Deployment and Service)
$ microk8s kubectl delete -f deployment.yaml
$ microk8s kubectl delete -f service.yaml
- Updating an Application or Service on the Fly While the application is running you can modify the content inside the service.yaml file then run the following command to update the changes
$ microk8s kubectl apply -f service.yaml
!You may need to allow Insecure Registry for private secure registry See: https://microk8s.io/docs/registry-private
- Enable Kubernetes Image Repository !Once enabled, the registry should be lived on localhost:32000
$ microk8s enable registry
- Build the Docker image with tag
$ docker build . -t localhost:32000/my-application:registry
- Push image to Kubernetes Image Repository
$ docker push localhost:32000/my-application
- Deploy your container using Registry Image Update deployment.yaml file
image: 192.168.1.164:32000/my-application:registry
- Save and deploy
$ kubectl apply -f deployment.yaml