Provisioning Kubernetes cluster by kubeadm

Kubeadm is a new tool that is part of the Kubernetes distribution of 1.4.0. It allows you to install and set up a Kubernetes cluster. One of the most frequent criticisms of Kubernetes is that it’s difficult to install. kubeadm makes this much easier, so I strongly suggest you give it a try.

Pre-requisites for creating a cluster:

  • One or more machines running the compatible OS (ex: Ubuntu)
  • 2-GB or more of RAM per machine
  • 2-CPU or more for Master

Network connectivity among all machines in the cluster

Objectives:

  • Install a single master Kubernetes cluster.
  • Install a Pod network on the cluster so that your Pods can communicate.

Beginners can set up the pre-requisites in their own machine by creating virtual machines (VMs) in a virtual box, or they can also use multiple machines for creating clusters.

Installation:

Install these requirements in each node:

  • Docker
    $ sudo apt-get update
    $ sudo apt-get install -y docker.io
  • Kubeadm, Kubelet, Kubectl
    $ sudo apt-get update && sudo apt-get install -y apt-transport-https curl
    $ sudo -i
    $ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    $ cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
    $ deb http://apt.kubernetes.io/ kubernetes-xenial main
    $ EOF
    $ exit
    $ sudo apt-get update
    $ sudo apt-get install -y kubelet kubeadm kubectl

Master Node:

The master is the machine where the control plane components run, including etcd (the cluster database) and the API server (which the kubectl CLI communicates with).

Master NodeMaster Node

Before running kubeadm init in master node, first choose a pod network add-on and verify whether it requires any arguments to be passed for kubeadm initialization. Depending on which third-party provider you choose, you might need to set the --pod-network-cidr argument with kubeadm init <args>.

Configure the cgroup Driver used by kubelet

$ sudo sed -i "s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf


Restart kubelet

$ sudo systemctl daemon-reload
$ sudo systemctl restart kubelet


Example:

$ sudo kubeadm init --apiserver-advertise-address=<master-private-ip> --apiserver-cert-extra-sans=10.0.2.15 --pod-network-cidr 10.1.0.0/16
$ sudo mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ sudo sysctl net.bridge.bridge-nf-call-iptables=1
$ sudo KUBECONFIG=/etc/kubernetes/admin.conf
$ kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml

After you finish running kubeadm init in master node, it provides the token, master-ip, sha and hash as follows:

$ kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>

If you do not have the token, you can obtain it by running the following command on the master node:

$ kubeadm token list

By default, tokens expire after 24 hours. If you are joining a node to the cluster after the current token has expired, you can create a new token using the following command:

$ kubeadm token create

For reference, you can view this document: https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

Worker nodes:

A worker node in Kubernetes was previously known as a minion. A node may be a VM or a physical machine, depending on the cluster. Each node has the services necessary to run pods and is managed by the master components.

Joining worker nodes:

To add nodes to your cluster, do the following for each machine:

  • SSH to the machine
  • Become root (e.g. sudo su -)
  • Run the command that was returned by kubeadm init. For example:
$ kubeadm join — token <token> <master-ip>:<master-port> — discovery-token-ca-cert-hash sha256:<hash>

Now you are all set and can list the nodes from the master by running

$ kubectl get nodes


This article was first published on Aug 23, 2018 on OpenEBS's Medium Account

Don Williams
Don is the CEO of MayaData and leading the company for last one year. He has an exceptional record of accomplishments leading technology teams for organizations ranging from private equity-backed start-ups to large, global corporations. He has deep experience in engineering, operations, and product development in highly technical and competitive marketplaces. His extensive professional network in several industries, large corporations and government agencies is a significant asset to early stage businesses, often essential to achieve product placement, growth and position for potential exit strategies.
Kiran Mova
Kiran evangelizes open culture and open-source execution models and is a lead maintainer and contributor to the OpenEBS project. Passionate about Kubernetes and Storage Orchestration. Contributor and Maintainer OpenEBS projects. Co-founder and Chief Architect at MayaData Inc.
Murat Karslioglu
VP @OpenEBS & @MayaData_Inc. Murat Karslioglu is a serial entrepreneur, technologist, and startup advisor with over 15 years of experience in storage, distributed systems, and enterprise hardware development. Prior to joining MayaData, Murat worked at Hewlett Packard Enterprise / 3PAR Storage in various advanced development projects including storage file stack performance optimization and the storage management stack for HPE’s Hyper-converged solution. Before joining HPE, Murat led virtualization and OpenStack integration projects within the Nexenta CTO Office. Murat holds a Bachelor’s Degree in Industrial Engineering from the Sakarya University, Turkey, as well as a number of IT certifications. When he is not in his lab, he loves to travel, advise startups, and spend time with his family. Lives to innovate! Opinions my own!