Last active
March 2, 2022 10:35
-
-
Save jacksonps4/9c887b0ed0dd6f8854bc1a6d2d6564a8 to your computer and use it in GitHub Desktop.
Setting up Kubernetes on Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------ | |
# INSTALLING KUBERNETES on a physical node (regular or raspberry pi) | |
# ------------------------------------------------------------------ | |
# | |
# Chris Wraith @jacksonps4 | |
# | |
# Raspbian: From 2019-09-26-raspbian-buster-lite | |
# Kubernetes: v1.16.1 - v1.23.4 | |
# | |
# Run this script as root | |
# | |
# | |
# prepare apt | |
# | |
apt-get update | |
# | |
# install Docker | |
# | |
apt-get install docker.io | |
# | |
# add Kubernetes apt repositories | |
# | |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - | |
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list | |
apt-get update | |
# | |
# install Kubernetes | |
# | |
apt-get install -y kubeadm | |
# | |
# (Raspberry Pi only) Add the following to the end of /boot/cmdline.txt | |
# | |
# cgroup_enable=cpuset cgroup_memory=1 | |
# | |
# configure networking | |
# NB: add this to /etc/sysctl.conf to apply it permanently | |
# | |
sysctl net.bridge.bridge-nf-call-iptables=1 | |
# | |
# turn off the swapfile permanently | |
# | |
# this turns off swap until reboot | |
swapoff -a | |
# (Raspberry Pi only) this turns it off permanently | |
dphys-swapfile swapoff | |
dphys-swapfile uninstall | |
update-rc.d dphys-swapfile remove | |
apt purge dphys-swapfile | |
# (Other node types) | |
# delete the swap entry from /etc/fstab | |
# | |
# create a cluster | |
# | |
# Notes | |
# - you can change the network CIDR address but you need to do the same in your network plugin (Flannel, Calico, etc) | |
# - you can optionally set the DNS suffix and kubernetes API SANs | |
# | |
kubeadm init --pod-network-cidr 10.244.0.0/16 [--service-dns-domain <dns suffix>] [--apiserver-cert-extra-sans <san1>,<san2>,...] | |
# | |
# download and apply the network plugin (Flannel in this case) | |
# | |
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml | |
# If you're using Calico and this isn't your first node in the cluster, check and see if all is working. If you see errors like this: | |
# | |
# | |
# This is the solution: | |
# mkdir -p /etc/cni/net.d | |
# | |
# Find the calico config from elsewhere in your cluster | |
# ON ANOTHER NODE: get the file contents | |
# $ cat /etc/cni/net.d/10-calico.conflist | |
# COPY THE CONTENTS to /etc/cni/net.d/10-calico.conflist on the new node | |
# Tweak the arch if needed | |
# $ curl -LO https://github.com/projectcalico/cni-plugin/releases/download/v3.17.1/calico-arm64 | |
# $ mv calico-arm64 /opt/cni/bin/calico | |
# $ ln -s /run/dnsmasq /run/systemd/resolve | |
# | |
# To add worker nodes | |
# | |
# (on a control plane node) | |
kubeadm token create --print-join-command # step 1 | |
# (on the new worker target node) | |
<command-from-above-step-1> | |
# | |
# To add another control plane node (assumes you already have an HAProxy setup to load balance across the nodes) | |
# | |
# (on a control plane node) | |
kubeadm init phase upload-certs --upload-certs # step 1 | |
kubeadm token create --print-join-command # step 2 | |
# (on the new control plane target node) | |
kubeadm join <control-plane-address>:<control-plane-port> --token <token-from-above-step-2> --control-plane --certificate-key <token-from-above-step-1> --discovery-token-ca-cert-hash <token-from-above-step-1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment