A Kubernetes cluster is a powerful tool for managing containers in a highly available manner. Kubeadm greatly simplifies the process of setting up a simple cluster. In this hands-on lab, you will build your own working Kubernetes cluster using Kubeadm.
- Install Docker on all three ubuntu (Ubuntu 18.04.3 LTS) nodes:
- Add the Docker GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
- Add the Docker repository: sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
- Update packages: sudo apt-get update
- Install Docker: sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu
- Hold Docker at this specific version: sudo apt-mark hold docker-ce
- Verify that Docker is up and running with: sudo systemctl status docker
- Install kubeadmin, kubelet and kubectl on all three nodes
- Add the Kubernetes GPG key: curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add –
- Add the Kubernetes repository:
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
- Update packages: sudo apt-get update
- Install kubelet, kubeadm, and kubectl: sudo apt-get install -y kubelet=1.12.7-00 kubeadm=1.12.7-00 kubectl=1.12.7-00
- Hold the Kubernetes components at this specific version: sudo apt-mark hold kubelet kubeadm kubectl
- Bootstrap the cluster on the kube master node
- On the Kube master node: sudo kubeadm init –pod-network-cidr=10.244.0.0/16 (kubeadm config images pull). That command may take a few minutes to complete, When it is done, set up the local kubeconfig:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Take note that the kubeadm init command printed a long kubeadm join command to the screen. You will need that kubeadm join command in the next step.
- Run the following command on the Kube master node to verify it is up and running: kubectl version
user@ip-10-0-1-101:~$ kubectl version
Client Version: version.Info{Major:”1″, Minor:”12″, GitVersion:”v1.12.7″, GitCommit:”6f482974b76db3f1e0f5d24605a9d1d38fad9a2b”, GitTreeState:”clean”, BuildDate:”2019-03-25T02:52:13Z”, GoVersion:”go1.10.8″, Compiler:”gc”, Platform:”linux/amd64″}
Server Version: version.Info{Major:”1″, Minor:”12″, GitVersion:”v1.12.10″, GitCommit:”e3c134023df5dea457638b614ee17ef234dc34a6″, GitTreeState:”clean”, BuildDate:”2019-07-08T03:40:54Z”, GoVersion:”go1.10.8″, Compiler:”gc”, Platform:”linux/amd64″}
- Join the two kube worker nodes to the cluster
- Copy the kubeadm join command that was printed by the kubeadm init command earlier, with the token and hash. Run this command on both worker nodes, but make sure you add sudo in front of it:
sudo kubeadm join 10.0.1.101:6443 –token am4wv6.u1pf30bz2r70z4i2 –discovery-token-ca-cert-hash sha256:61172c44ea7f7470465b587c191bddb8f369872afebc3663b5ed97744c1cf5e3
- On the Kube master node, make sure your nodes joined the cluster successfully: kubectl get nodes
user@ip-10-0-1-101:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-10-0-1-101 NotReady master 13m v1.12.7
ip-10-0-1-102 NotReady <none> 17s v1.12.7
ip-10-0-1-103 NotReady <none> 12s v1.12.7
- Note that the nodes are expected to be in the NotReady state for now.
- Setup cluster networking with flannel
- Turn on iptables bridge calls on all three nodes:
echo “net.bridge.bridge-nf-call-iptables=1” | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
- Install Flannel only on the Kube master node:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
user@ip-10-0-1-101:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-10-0-1-101 Ready master 23m v1.12.7
ip-10-0-1-102 Ready <none> 9m31s v1.12.7
ip-10-0-1-103 Ready <none> 9m26s v1.12.7