5 Easy Steps To Create a Kubernetes Cluster Using Kubeadm

If you want to manually create the cluster (i.e., without GKE) using kubeadm, then this document may help you to do it. Before moving into the procedure it is good to have knowledge on kubeadm.

Prerequisites:

OS: Ubuntu version 16.04 or higher

Minimum Memory required: For master node - 2 CPU's, 8GB memory

For each worker node - 1 CPU's, 4GB memory

Let us look into the steps for cluster creation using kubeadm

Step 1: Docker Installation

Create the Instances in the GCE , It should be at least one master node and two or more worker nodes. Follow these steps for all the nodes.

Docker installation is the primary steps in the cluster creation, so follow the below steps for all the nodes you created. Otherwise you can also look into the official docker documentation for docker installation.

  1. $ sudo apt-get update -y

  2. $ sudo apt-get install -qy docker.io

Check whether docker got properly installed or not using docker --version command

Step 2: Install Kubeadm

  • Get Kubernetes repo key

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

  • Add Kubernetes repository to manifests

$ sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

  • Install Kubeadm

$ sudo apt install kubeadm

Check kubeadm version and make sure it is properly installed or not.

$ kubeadm version

Step 3: Create the cluster

It is possible to configure kubeadm init with a configuration file instead of command line flags, and some more advanced features may only be available as configuration file options. This file is passed in the --config option.

On master node:

Initialize the kubeadm

$ sudo kubeadm init [option]

Options:

  • --pod-network-cidr=10.244.0.0/16

  • --config=/root/kubeadm-config.yaml

  • --cert-dir

Copy and execute kubectl config file

$ mkdir -p $HOME/.kube

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

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

Step 4: Join worker node

To join worker nodes to the master node, run the below command separately on each worker node

As a root user

$ kubeadm join 10.156.0.18:6443 --token ow15j0.kz12nltctqeowkiy \

> --discovery-token-ca-cert-hash sha256:a7024eacb754a01721f28cedc52e92427a83225db0f800d1bfb9117f2832602c

To check whether all the pods are active and running, run the following command on the master node.

$ kubectl get nodes

Step 5: Troubleshooting

  • When you are initializing kubeadm with cidr, then If you get pods status as not ready then run the following code in master node

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

  • If you are doing kubeadm init with config file then sample template of the file is shown below.

Kubeadm-config.yaml sample template

You can access the yaml file here.

Tear down:

To tear down the kubeadm, run these commands on the master node

$ kubectl drain <node name> — delete-local-data — force — ignore-daemonsets

$ kubectl delete node <node name>

Then, on the node being removed, reset all kubeadm installed state:

$ kubeadm reset

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square