CKA Learning Series: Build K8s Cluster using Kubeadm in minutes !
CKA 2020 Exam Updates(Sep onwards)
Proctored exam, 15-20 hands on questions, 2 hours, 6 k8s clusters, K8s 1.19 and no multiple choice drama !
CKA exam, tests your skills in specific domains of k8s platform. Creating/managing k8s cluster using kubeadm is one of primary requirement. I have recently passed this exam and In my opinion practising on kubeadm based cluster can help you to cover a big part of exam syllabus. I suggest create your own cluster using kubeadm and practise as much as possible to get through in first attempt. This blogpost is part of series which I will be publishing in coming days to help you pass the exam.
In this post we will cover the part in which we are building a k8s cluster using kubeadm.
What you need to start -
Free cloud account or Virtual Box
I am using 3 VMs named —
- node-1 [Ubuntu 18.x machine / master or controlplane]
- node-2 [Ubuntu 18.x machine / worker]
- node-3 [Ubuntu 18.x machine / worker]
What are the steps -
Perform these steps on all 3 VMs. These steps deploy required component for building k8s cluster using kubeadm.
Step 1: Configure iptables to receive bridged network traffic
# add following lines in /etc/ufw/sysctl.conf filenet/bridge/bridge-nf-call-ip6tables = 1
net/bridge/bridge-nf-call-iptables = 1
net/bridge/bridge-nf-call-arptables = 1
Step 2: Make sure you have installed ebtables and ethtool. If not please install
apt-get install ebtables ethtool
Step 3: Install HTTPS-TRANSPORT component
apt-get updateapt-get install -y apt-transport-https
Step 4: Install docker
apt-get install -y docker.io
Step 5: Add K8s repo in system
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
Step 6: Install Kubeadm,Kubelet and Kubectl
apt-get install -y kubelet kubeadm kubectl
Step 7: If you want kubeadm cluster process fast then pull required Images in advance which will be used for controlplane. [required on master node ], otherwise you can ignore !
kubeadm config images pull
Time to create cluster -
VMs are ready, select 1 VM which we need to prepare as a master node [k8s controlplane] and others we will prepare as a worked node. In this case I will use node-1 as a master and node-2/3 as a worker node.
kubeadm init --pod-network-cidr=192.168.0.0/16
Thats it ! Isn’t it the simplest way to deploy a k8s cluster. Your master node is getting ready now. To start using it, you can see the 3 steps mentioned in the output. Run it !
List the status of control-plane pods. If you would have pulled image in advance, you could have avoided this delay :)
Now Node-1 as a master is ready, please run the join command mentioned above as an output of create cluster command on other worker nodes. Join command adds worker node as part of cluster.
Did you see NotReady status on nodes ? It is because you missed to install pod network. [I miss this intentionally to help you understand troubleshooting of cluster which is an essential topic of CKA ]
Lets Install Pod Network, we will use Weave as a pod network solution. Please note there are multiple solutions so you can use anyone as per your requirement.
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
Once done check the status again on cluster.
Voila ! Cluster is ready for use :)
If by any chance you miss to copy that join command ! Don’t worry, we have solution.
# list tokens [run on node-1]kubeadm token list# if there is no token generate one kubeadm token create# generate discovery token hashopenssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'# now build up your command kubeadm join <master-node-ip>:6443 --token <token> \
--discovery-token-ca-cert-hash sha256:<token hash>
to avoid above hustle, we have one more simple solution, run following command —
kubeadm token create --print-join-command
But knowing things in details will not bite anyone.
Once your cluster is ready, you can start using it immediately. I have consolidated few commands which can help you as well.