Docker installation
First, let's install updates, dependencies and docker:
sudo apt update
sudo apt upgrade
sudo apt install apt-transport-https # already installed
sudo apt install docker.io
Now, we can start docker and enable it to start during the system boot:
sudo systemctl start docker
sudo systemctl enable docker
Kubernetes installation
Before the installation, we need to add the key:
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
To create the apt repository for Kubernetes, we open a file:
sudo nano /etc/apt/sources.list.d/kubernetes.list
and add the following line into it and close the file:
deb http://apt.kubernetes.io/ kubernetes-xenial main
Time to update and install kebernetes:
sudo apt update
sudo apt install kubelet kubeadm kubectl kubernetes-cni
Kubernetes master
To initialise Kubernetes cluster to run as master, execute the below command:
sudo kubeadm init --pod-network-cidr 10.244.0.0/16
If you receive this error:
[preflight] Some fatal errors occurred:
[ERROR Swap]: running with swap on is not supported. Please disable swap
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
You will need to disable the swap:
sudo nano /etc/fstab # comment swap to disable permanently
sudo swapoff -a
After the initialisation, you will see something like this:
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 10.143.6.161:6443 --token de5fen.6y2w4x7shlyhnfyf8 --discovery-token-ca-cert-hash sha256:2a9dfacf654eba7d374b8dfac0028d6a094c550c67bc084f1efcc1f4301ca656
To complete the setup:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Execute below commands on master node to apply network settings:
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
Now, check all pods:
sudo kubectl get pods --all-namespaces
Kubernetes node
First of all, follow: Docker installation and Kubernetes installation. Then:
kubeadm join 10.143.6.161:6443 --token de5fen.6y2w4x7shlyhnfyf8 --discovery-token-ca-cert-hash sha256:2a9dfacf654eba7d374b8dfac0028d6a094c550c67bc084f1efcc1f4301ca656
Go back to Master and check:
kubectl get nodes NAME STATUS ROLES AGE VERSION k8-master Ready master 17h v1.11.0 k8-node1 Ready37s v1.11.0 k8-node2 Ready 29s v1.11.0