Create a Kubernetes cluster using kubeadm

Mohan Pawar
4 min readMar 6, 2020

The Minimal Viable kubernetes(MVK) cluster…

The kubeadm tool is used to bootstrap smaller kubernetes cluster where you can experience all kubernetes features. The cluster spin-up using kubeadm is eligible to pass the Kubernetes Conformance Program. The cluster life-cycles functions and cluster upgrade also supports by kubeadm.

If you are getting started with Kubernetes, then this is perfect start to bootstrapping a cluster using kubeadm. As well as if you want to test two node or three node cluster, you can do it on your local machine or workstation by creating guest operating system. You can automate these commands using any of configuration management tool.

You can install kubeadm on your local machine or laptop, any of the cloud server or on Arduino, Raspberry Pi, etc.

Prerequisites:

  1. One or more machines running linux operating system like deb/rmp.
  2. 2 GiB+ of RAM / machine (works with less RAM but, you cannot run later on heavy resource applications).
  3. Min 2 vCPU for master node(control-plane node).
  4. Full network connectivity between machines(machines can be in either public network or private network, respectively).

Now that you have qualified the above prerequisites, you can quickly go to the installation process as below, divided into steps, Step 1–9 you have to run on all the nodes on cluster.

  1. Get the Docker GPG Key,
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  2. Add the docker repository,
sudo add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

3. Get the Kubernetes gpg key,

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

4. Add the Kubernetes repository,

cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

5. Update your packages,

sudo apt update -y

6. Install Docker, kubelet, kubeadm, and kubectl,

sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu kubelet=1.15.7-00 kubeadm=1.15.7-00 kubectl=1.15.7-00

7. The versions of the components installed are compatible with each other hence would recommend to follow the same,
sudo apt-mark hold docker-ce kubelet kubeadm kubectl

apt-mark hold package command

8. Add the iptables rule to sysctl.conf, so that pods can communicate across nodes,

echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf

9. Enable iptables immediately i.e. to get it effected:

sudo sysctl -p

10. Initialize the cluster (run only on the master),

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

What happens when you run kubeadm init to create a kubernetes native cluster ?

It will first run a set of per-flight checks which will validates the system state. You might get specific error or warnings at the command line. Then it will generate self-signed certificates or use one if existing certificate has been provided to set up identities of different components of Master node. Same certificate will be used by the API-server as other components communicates with it. Next, it will setup the KubeConfig file into the `/etc/kubernetes/` directory for kubelet, controller-manager and the scheduler, etc. Note that these components like API-server, controller-manager, scheduler are themselves running inside pod and static pod-manifest file for these pods in the control-plane have already been set-up on the master. So, the respective images will be pulled at this time. The init process will also apply labels and taints to the master node so that no additional workload will ever run there. Next kubeadm will generate a token. This token can be specified by any nodes to join this cluster. Next couple of add-ons set-up on the master node as kube-dns and kube-proxy. Finally, you’ll see the steps to start using your cluster, you need to run the following steps as a regular user along with a join token which we’ll need to run from the worker node to join the cluster.

11. Set up local kubeconfig, make sure as mentioned in the above command’s output run below commands as regular user, not with root user(as seen in the above screenshot),

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

12. Apply Flannel CNI network overlay,

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

13. Join the worker nodes to the cluster(run this on the worker nodes to join the cluster),

sudo kubeadm join [kubeadm_init_token]

14. Verify the worker nodes have joined the cluster successfully,

kubectl get nodes
get nodes command

Compare this result of the kubectl get nodes command. Now you have a ready cluster with you to test and deploy any application into Kubernetes cluster. This is not recommend way to run the Kubernetes applications into production environment using kubeadm. But, it’s very helpful to understand, learn and experiment with Kubernetes cluster.

--

--