You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A couple of weeks back I spent the evening in an workshop organized by resin.io where we had the chance to play around with some raspberry pis. Once that was done we got to keep the boards for ourselves. With this nice little gift the number of raspberry pis in my house grew to three. Now, as we all know, one's company, two's a crowd, and three's a cluster, so I figured it would be fun to try and get Kubernetes running on these machines. I spent a few hours over a weekend doing just that.
To get a raspberry k8s cluster up and running you'll need the following:
three or more Raspberry Pis 3 model B/B+ (two it's technically enough, but you'll end up with one k8s master and one node, and running everything on one node isn't as fun or as "clustery")
a router that you control (if you'd like to carry this cluster around get a small router just for this cluster)
ethernet cables for each raspberry (running this over WiFi works just as well but I prefer cables for speed and consistency)
After you've got all hardware in place, there are six main targets to achieve in order to go from a bunch of circuit boards lying around to a k8s cluster:
ssh enabled raspbian lite stretch installed
network setup with static ips assigned to each pi
swap disabled
docker installed
kubeadm, kubelet, and kubectl installed
pod networking added to cluster
We'll go through each of these bullet points in greater detail and get everything set up.
SSH into each machine in a different terminal, add all terminals to a group by clicking the three squares button in the top left corner, and select Broadcast Group in the same menu. Every command you type in one terminal will then be broadcast to all other terminals. You'll be able to write these commands once and run them across all three Pis.
There are of course various ways of automating this process across machines but using the terminal is a very simple way of doing it. Plus, there is educational value in running these commands by hand at least once.
Burn it to your sd cards using Etcher - a great gui tool for burning images to sd cards
Enable ssh before putting your cards in by creating an empty "ssh" file in the boot partition of each card
cd /path/to/sdcard/boot/partition # e.g. /media/cristian/boot
touch ssh
Configure networking
Your setup should look more or same like in the above diagram. The network router could be the one you probably have in your home already and if you don't have an extra router everything in that diagram would simply connect to the so called network router. I bought a small separate router just for this cluster because I'd like to be able to take this cluster with me and plug it into any network I might find. In any case, to get this to work, you need to control the router that your pis connect to.
Log in to your router's interface, usually at 192.168.0.1/192.168.1.1, but do read your router's manual for instructions, and figure out a way to reserve/assign static ip addresses for each raspberry pi. These settings should normally reside in or around a "DHCP Server Settings" page. The router I bought has them under "IP & MAC Binding". After you've assigned a static IP of your choice to the MAC address of each Raspberry unplug the machines and plug them back in. Refresh your router's interface page and you should see them coming up online at the specified addresses.
At this point, you should be able to ssh into your Pis using your computer and login with password raspberry.
ssh pi@192.168.1.42 # or whatever ip you picked
After you're in, change the hostname of each Raspberry using the raspi-config tool.
sudo raspi-config
# then network options > hostname
I do recommend changing the password as well using the same utility.
Disable Swap
For Kubernetes 1.7 and later you will get an error if swap space is enabled. To turn off swap run:
If swap is off this command should show no entries:
Install Docker
This installs the latest version of Docker:
curl -sSL get.docker.com | sh &&\
sudo usermod pi -aG docker
You'll get a warning later on from Kubernetes about this very recent docker version being untested but I haven't had any docker related issues so it should be fine.
Enable cgroup
sudo nano /boot/cmdline.txt
Add this to the end of the file:
cgroup_enable=cpuset cgroup_enable=memory
Then restart your Pis
Install Kubernetes
The installation guide is available on the official page here and I will simply paste the same commands here.
VERY IMPORTANT: You should install version 1.9.6 and not the latest. I've had issues which other people online seem to have also run into using 1.10 and the most obvious fix is to simply use 1.9.6 for now.
You will install kubeadm, kubelet, and kubectl on all machines.
sudo apt update && sudo apt install -y apt-transport-https curl # enable installing from repo over https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - # add GPG key
sudo nano /etc/apt/sources.list.d/kubernetes.list
# add this line to the file: deb http://apt.kubernetes.io/ kubernetes-xenial main
sudo apt update
sudo apt install kubelet=1.9.6-00 kubeadm=1.9.6-00 kubectl=1.9.6-00
Edit the kubelet systemd file and add the --cgroup-driver flag to the ExecStart command. The cgroup-driver flag should match the cgroup driver used by Docker. You can see the one Docker uses with
docker info | grep -i cgroup
You'll have to add --cgroup-driver=cgroupfs as a flag to the kubelet command. Afterwards:
This will allow you to control the cluster using kubectl.
Make sure to also save the kubeadm join command given in the output. You'll use this on the worker nodes to connect to the cluster.
Install Weave network driver
My master node is a Raspberry Pi 3 Model B+ and I've run into issues installing Weave using the default command described here. I found a workaround in a github issue here and am pasting the modified command down below:
kubectl --kubeconfig k8s-piconfig get pods --all-namespaces
Create a simple deployment and service for a markdown-to-html converter web service (using this docker image) by creating a file markdown.yaml and pasting the contents below,
Have fun with your little cluster! For more content on the subject have a look at this github gist and go through the comments if you happen to run into issues. I also recommend this great post by Hanselman regarding his Pi cluster.
Jun 16, 2018
via www.cristiandima.com https://ift.tt/33rCdOV
November 8, 2019 at 11:58AM
The text was updated successfully, but these errors were encountered:
Cristian Dima - Running Kubernetes on a Raspberry Pi cluster
https://ift.tt/34EBU3v
About 0 Minutes
A couple of weeks back I spent the evening in an workshop organized by resin.io where we had the chance to play around with some raspberry pis. Once that was done we got to keep the boards for ourselves. With this nice little gift the number of raspberry pis in my house grew to three. Now, as we all know, one's company, two's a crowd, and three's a cluster, so I figured it would be fun to try and get Kubernetes running on these machines. I spent a few hours over a weekend doing just that.
To get a raspberry k8s cluster up and running you'll need the following:
After you've got all hardware in place, there are six main targets to achieve in order to go from a bunch of circuit boards lying around to a k8s cluster:
We'll go through each of these bullet points in greater detail and get everything set up.
For each Raspberry Pi
Install Raspbian
Configure networking
Your setup should look more or same like in the above diagram. The network router could be the one you probably have in your home already and if you don't have an extra router everything in that diagram would simply connect to the so called network router. I bought a small separate router just for this cluster because I'd like to be able to take this cluster with me and plug it into any network I might find. In any case, to get this to work, you need to control the router that your pis connect to.
Log in to your router's interface, usually at 192.168.0.1/192.168.1.1, but do read your router's manual for instructions, and figure out a way to reserve/assign static ip addresses for each raspberry pi. These settings should normally reside in or around a "DHCP Server Settings" page. The router I bought has them under "IP & MAC Binding". After you've assigned a static IP of your choice to the MAC address of each Raspberry unplug the machines and plug them back in. Refresh your router's interface page and you should see them coming up online at the specified addresses.
At this point, you should be able to ssh into your Pis using your computer and login with password
raspberry
.ssh pi@192.168.1.42 # or whatever ip you picked
After you're in, change the hostname of each Raspberry using the
raspi-config
tool.sudo raspi-config # then network options > hostname
I do recommend changing the password as well using the same utility.
Disable Swap
For Kubernetes 1.7 and later you will get an error if swap space is enabled. To turn off swap run:
If swap is off this command should show no entries:
Install Docker
This installs the latest version of Docker:
You'll get a warning later on from Kubernetes about this very recent docker version being untested but I haven't had any docker related issues so it should be fine.
Enable cgroup
Add this to the end of the file:
Then restart your Pis
Install Kubernetes
The installation guide is available on the official page here and I will simply paste the same commands here.
VERY IMPORTANT: You should install version 1.9.6 and not the latest. I've had issues which other people online seem to have also run into using 1.10 and the most obvious fix is to simply use 1.9.6 for now.
You will install kubeadm, kubelet, and kubectl on all machines.
Edit the kubelet systemd file and add the
--cgroup-driver
flag to the ExecStart command. The cgroup-driver flag should match the cgroup driver used by Docker. You can see the one Docker uses withYou'll have to add
--cgroup-driver=cgroupfs
as a flag to the kubelet command. Afterwards:At this point the kubelet service should be restarting continously with the following err:
You can check the kubelet logs with
On the master Pi node
Initialize your Kubernetes cluster:
Run the commands given to you:
This will allow you to control the cluster using
kubectl
.Make sure to also save the
kubeadm join
command given in the output. You'll use this on the worker nodes to connect to the cluster.Install Weave network driver
My master node is a Raspberry Pi 3 Model B+ and I've run into issues installing Weave using the default command described here. I found a workaround in a github issue here and am pasting the modified command down below:
To see your pods starting up run:
After all containers have finished creating, you should see something like this:
On the worker nodes
Run the join command given to you earlier by
kubeadm init
, i.e.Go back to the master and run
Wait a few minutes and you should see the status of the nodes change to ready.
Deploy a sample application from your computer
Copy the kube config file to your computer (replace the ip with your master ip):
Check kubectl works on your computer:
Create a simple deployment and service for a markdown-to-html converter web service (using this docker image) by creating a file
markdown.yaml
and pasting the contents below,and then running:
Watch the pod status column until the containers are created and the pods running:
and then test the service (replacing the ip with the ip of your master node):
Kubernetes dashboard
To install the kubernetes dashboard run:
and to get a token that you can login with either read this guide or simply copy and paste the following into a
dashboard.yaml
file,and then run
Open up a localhost proxy to the dashboard via
and then login with the token obtained by running
Have fun with your little cluster! For more content on the subject have a look at this github gist and go through the comments if you happen to run into issues. I also recommend this great post by Hanselman regarding his Pi cluster.
Jun 16, 2018
via www.cristiandima.com https://ift.tt/33rCdOV
November 8, 2019 at 11:58AM
The text was updated successfully, but these errors were encountered: