Kubernetes setup Ubuntu 20.04.3 LTS - Part 1
There are many tutorials out there for the first steps with Kubernetes but most of them did not work out of the box so I place here a solution which worked for me very well on the actual Ubuntu 20.04 LTS
Base image is an Ubuntu 20.04 minimal installation with SSH access, you need to have access to the root account
Update Repo and System:
apt update && apt upgrade
I set the hostname according to the use of the server in this case it is the first node and master of my kubernets project
hostnamectl set-hostname master-node
Kubernets requires that swap is disabled:
swapoff -a && sed -i '/ swap / s/^/#/' /etc/fstab
Download the docker repo key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Adding the docker repo to your server:
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Install docker on ubuntu without snap
apt install docker-ce docker-ce-cli containerd.io -y
Start the docker service and set it to autostart
systemctl start docker && systemctl enable docker
Adding Docker Service Fix:
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
Restart the docker service to accept the fix
systemctl restart docker
Install required packages for Kubernets
apt -y install curl apt-transport-https
Add the Kubernets repo key
curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
Add the Kubernets repo to your server
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
Update your repolist
apt update
Install Kubernets and Kubeadm
apt-get -y install kubeadm kubelet kubectl
Check the installation and the version of the installed packages
kubeadm version && kubelet --version && kubectl version
Start an intial preflight test with kubernetes (this will take up to 10min)
kubeadm init --pod-network-cidr=10.244.0.0/16
This steps are also avaiable via ansible playbook on my GitHub Accout:
https://github.com/dawdad/ansible-playbooks