Kubernetes from scratch on Azure.

Introduction

Installing Kubernetes

Create your virtual machines

For this we’re going to be using 3x CentOS 7.7 virtual machines

Install the following on all 3 servers

1. Elevate privileges to install all the necessary components

sudo su

2. Disable SELinux

We’re going to disable SELinux because we don’t really have the time to go in and set run context for SELinux, so we will will just disable it for the purpose of this. But you should never do this in production.

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

3. Enable br_netfilter module for cluster communication

Next we will enable the br_netfilter module, and then allow kubernetes to manipulate IP tables by adding 1 into the bridge-nf-call-iptables file.

modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

4. Disable swap to prevent memory allocation issues

The reason we need to turn off swap is in a production environment, when we’re looking at memory stress on the machines, we want to be correctly reporting the amount of memory that were using and if we have swap it can incorrectly report swap as actual memory. So best practice is to turn swap off.

swapoff -a

Now open up the file /etc/fstab in your favourite editor (I’m using vim), and comment out the last line which is **/root/swap swap swap sw 0 0 **

vim /etc/fstab

5. Install the prerequisites for Docker

yum install -y yum-utils device-mapper-persistent-data lvm2

6. Add the Docker repo and install Docker.

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

7. Configure the Docker Cgroup Driver to systemd, enable and start Docker

sed -i '/^ExecStart/ s/$/ --exec-opt native.cgroupdriver=systemd/' /usr/lib/systemd/system/docker.service 
systemctl daemon-reload
systemctl enable docker --now 
systemctl status docker
docker info | grep -i cgroup

8. Add the Kubernetes repo.

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
      https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

9. Install Kubernetes

yum install -y kubelet kubeadm kubectl

10. Enable Kubernetes. The kubelet service will not start until you run kubeadm init.

systemctl enable kubelet

Install the following on the master node only

1. Initialize the cluster using the IP range for Flannel.

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

2. Copy the kubeadmin join command.

It will look something like the following:

kubeadm join 172.31.25.161:6443 --token j8to4r.p2zl5f1c2wk5ercw --discovery-token-ca-cert-hash sha256:71e885fd4191c75dcda527f67da9bd820bbfe9b4e6cdd44851266b38d54eddd6

3. Exit sudo and run the following:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

4. Deploy Flannel.

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

5. Check the cluster state.

kubectl get pods --all-namespaces

6. *Note: Complete the following steps on the NODES ONLY!

Run the join command that you copied earlier (this command needs to be run as sudo), then check your nodes from the master.
kubectl get nodes