How I built my Kubernetes Homelab – Part 2

Welcome back to the second part of my Kubernetes Homelab Series. After I deployed three virtual machines to my Homelab I want to install all necessary packages …

First of all I updated all of my the nodes to the latest packages.

marco@allthreenodes:~# sudo apt-get update && apt-get upgrade -y

I need to install several packages for downloading or adding additional software packages in later steps.

marco@allthreenodes:~# sudo apt install ca-certificates software-properties-common apt-transport-https curl gnupg lsb-release -y

In this step we turn off swapping to disk, uncomment the swap file from /etc/fstab and delete the /swap.img file. I was wondering why this needs to be done. The real reason why this is not supported by Kubernetes is not 100% clear for me after reading only a little bit about it.

marco@allthreenodes:~# sudo swapoff -a
marco@allthreenodes:~# sudo sed -i '/swap/s/^/#/' /etc/fstab
marco@allthreenodes:~# sudo rm -f /swap.img

In a later step I will use flannel for pod networking and I need to run this commands on all nodes to pass bridged IPv4 traffic to iptables chains:

marco@allthreenodes:~# echo "# Kubenetes" | sudo tee -a /etc/sysctl.conf
marco@allthreenodes:~# echo "net.bridge.bridge-nf-call-iptables = 1" | sudo tee -a /etc/sysctl.conf
marco@allthreenodes:~# sudo sysctl net.bridge.bridge-nf-call-iptables=1

Now I added the offical Docker GPG keys to all of my nodes

marco@allthreenodes:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

To download and later update the docker packages, I added the docker repository to my apt package manager on all three nodes

marco@allthreenodes:~# echo \
 "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
 $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

After adding the docker repository to my package manager, I have to refresh the package lists, install the correct docker packages, and also mark this packages to be not automatically updated.

marco@allthreenodes:~# sudo apt-get update
marco@allthreenodes:~# sudo apt install -qy docker-ce=5:19.03.15~3-0~ubuntu-focal docker-ce-cli=5:19.03.15~3-0~ubuntu-focal containerd.io
marco@allthreenodes:~# sudo apt-mark hold docker-ce docker-ce-cli containerd.io

Docker needs also some configuration and with this command I create a new file call /etc/docker/daemon.json to setup some stuff like e.g. log rotation.

marco@allthreenodes:~# sudo tee /etc/docker/daemon.json >/dev/null <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

I create a systemd drop-in directory for the docker service and restarted the services afterwards.

marco@allthreenodes:~# sudo mkdir -p /etc/systemd/system/docker.service.d
marco@allthreenodes:~# sudo systemctl daemon-reload
marco@allthreenodes:~# sudo systemctl restart docker

At this step I added the official google GPG keys for kubernetes to all of my nodes and also added an additional repository, where I want to get the kubernetes packages from.

marco@allthreenodes:~# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
marco@allthreenodes:~# echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list >/dev/null

Once again we need to refresh our package lists and install kubelet, kubectl and kubeadm for cluster creation. Also I added a hold for the kubernetes packages at their currently installed version so as not to upgrade unexpectedly on an apt upgrade.

# Install kubelet, kubectl and kubeadm for cluster spinup
marco@allthreenodes:~# sudo apt update
marco@allthreenodes:~# sudo apt install -qy kubeadm=1.18.16-00 kubelet=1.18.16-00 kubectl=1.18.16-00 
marco@allthreenodes:~# sudo apt-mark hold kubelet kubeadm kubectl



This was part 2 of my Homelab Kubernetes journey. Hopefully it was useful for you. In the next part of this series I will create my Kubernetes cluster.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

ten + 5 =