Kubernetes: Part 2: Install and Configure Ubuntu LTS 20.04 on Rasberry Pi 4 (updated for use containerd)
Update January 21st, 2021
In my original post the kubernetes cluster was setup with docker a container engine. Since docker won't be supported as a container engine for kubernetes in future versions (> 1.22) I have rewritten this blog, so containerd will be installed instead of docker. If you already have setup a kubernetes with docker as an a container engine, I written this blog on replacing docker with containerd.
- Let's Start
To start the installtion of Kubernetes on the Raspberry Pi's. You first need to prepare the Rasberry Pi's with Ubuntu LTS 20.04 as OS and install Container. I have made links to all required tools, and added videos if you don't know how to use them.
- Download and Flash Ubuntu LTS 20.04 on your SD Card
Download the image from the Ubuntu website (do NOT use an Ubuntu image from the Raspberry Pi Imager), since the Ubuntu can accessed via SSH out of the box.
sudo nano /etc/hostname
The change the name "ubuntu" into "k8s-master" and save the file (Ctrl-O and Ctrl-X). All example values, which you need change with your own settings are marked in red.k8s-master
- Change the network configuration from DHCP to a fixed ip.
To give the Raspberry Pi a fixed ip, run the following command.
sudo nano /etc/netplan/50-cloud-init.yaml
Change the file like the example below to give it a fixed ip address and dns servers. In the example below the fixed ip address is 192.168.1.201/24, the gateway is 192.168.1.1 and the DNS servers are 8.8.8.8 and 8.8.4.4, so change these in your own values and save the file# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.201/24]
gateway4: "192.168.1.1"
optional: true
nameservers:
addresses: [8.8.8.8,8.8.4.4]
version: 2
sudo netplan apply
After the setings have been applied you might lose you ssh session if you have changed the ip address. You then need to start you SSH session again with the new ip address.
- Change the hosts file
After you have change your hostname and ip address. You need to change the hosts file via the following command
sudo nano /etc/hosts
Add a 2nd line with the ip-address of your Raspberry Pi, the FQDN and the hostname like the example below.127.0.0.1 localhost
192.168.1.201 k8s-master.mydomain.com k8s-master
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
- Configure boot options
The cmdline.txt contains the boot options of the Raspberry Pi. Similar to BIOS of a PC, so please doublecheck the adjustments you have made before rebooting the Pi.
sudo nano /boot/firmware/cmdline.txt
add the following text to the cmdline.txtnet.ifnames=0 dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 swapaccount=1
sudo reboot
In the example below I create a user named "erik". You can change this to the accountname of your choice. The second line will add the user to the "sudo" group, so it is allowed to use the "sudo" command.
sudo adduser erik
usermod -aG sudo erik
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
cat /etc/modules-load.d/containerd.conf
sudo modprobe overlay
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
cat /etc/sysctl.d/99-kubernetes-cri.conf
sudo sysctl --system
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/nulld.docker.com/linux/ubuntu
sudo apt-get update && sudo apt-get install -y containerd.io
sudo mkdir -p /etc/containerd sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo nano /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
...
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
sudo systemctl enable containerd
sudo systemctl start containerd
sudo systemctl status containerd
sudo ctr image ls
sudo nano /etc/sysctl.conf
# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
#net.ipv4.tcp_syncookies=1
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
# Uncomment the next line to enable packet forwarding for IPv6
# Enabling this option disables Stateless Address Autoconfiguration
# based on Router Advertisements for this host
#net.ipv6.conf.all.forwarding=1
sudo reboot
sudo apt install nfs-common
Comments
Post a Comment