How to setup Kubernetes with Docker on CentOS 8

Setuping kubernetes with docker on CentOS 8

Step 1 - Disable SELINUX

sudo su
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux

Setup your hostname

echo "${MACHINE IP HERE} k8s-master" >> /etc/hosts
hostname k8s-master

Enable linux bridge

echo "net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf

Disable swap

Open file

nano /etc/fstab

Then comment all swap lines (/swap)

Restart the VM

shutdown -r now

After VM restart remember to join as root

sudo su

Add Docker repo

dnf install yum-utils -y && yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Add kubenerters repo

echo "[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64

enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg" > /etc/yum.repos.d/kubernetes.repo

Install latest supported docker e kubeadm

dnf install -y kubeadm docker-ce-19.03.15-3.el8 docker-ce-cli-19.03.15-3.el8

Start and enable (startup) docker e kubelet

systemctl start docker kubelet
systemctl enable docker kubelet

Start kubernetes with the follow CIDR

kubeadm init --pod-network-cidr=10.244.0.0/16

The above command can be take up to 5 minutes (depends of the machine/network speed)

After finish, run the command bellow (remember that installation as need inside root user)

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bashrc
export KUBECONFIG=/etc/kubernetes/admin.conf

Join the node

Execute the join command showed as the result of init. Command example below

kubeadm join --token 938475.896hWdx4AYRpxDWM 192.168.3.81:6443 --discovery-token-ca-cert-hash sha256:SURSqEgFLcNuMzeVXpX5TuT3AAsCrJEdfJLPhU9EePF7NQv82UP3mnUCv9bJAZ2F

If when you run the command above and throw an error, just append on final

--ignore-preflight-errors=all

Eg final command

kubeadm join --token 938475.896hWdx4AYRpxDWM 192.168.3.81:6443 --discovery-token-ca-cert-hash sha256:SURSqEgFLcNuMzeVXpX5TuT3AAsCrJEdfJLPhU9EePF7NQv82UP3mnUCv9bJAZ2F --ignore-preflight-errors=all

Install flannel

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Fix Kubernetes Taint

kubectl taint nodes --all node-role.kubernetes.io/master-

After run the above command, wait a little time and run

kubectl get nodes

and check if the STATUS is Ready