Prepare VM for Kubernetes
This section describes how to prepare a virtual machine for kubernetes. This procedure is common for both master and worker nodes.
Install docker runtime
sudo apt update
sudo apt upgrade
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
Add your user to the docker
group
Adding your user to the docker
group allows you to run docker commands without the need to sudo
sudo usermod -aG docker ${USER}
Log out of your shell and log back in.
Check your docker install
docker run hello-world
docker container list --all
You should see the commands completed successfully:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c14e7b3a7c36 hello-world "/hello" 20 seconds ago Exited (0) 19 seconds ago competent_hopper
Install kubernetes tools
Note
In the following commands, we use xenial repository to pull kubernetes binaries and tools. This is not a typo. Focal uses xenial k8s repos.
sudo apt install apt-transport-https curl gnupg2 software-properties-common
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt install kubeadm kubelet kubectl kubernetes-cni
Configure netfilter settings
sudo modprobe overlay
sudo modprobe br_netfilter
sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
Configure docker drivers
sudo tee /etc/docker/daemon.json<<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Enable kubelet service
sudo systemctl enable kubelet
Cache kubernetes docker images
sudo kubeadm config images pull