How to do Kubernetes setup

Let’s see how to do Kubernetes setup on a server cluster. The example is applied on a machine cluster running CentOS7 but can be replicated on any Linux-based machine.

Kubernetes Set Up

Let’s look together at all the steps related to Kuberntes set up(link to the art what is Kubernetes) in as much detail as possible.


We need:

  • Multiple servers running CentOS7 (1 master node and 1+ worker nodes)
  • One user account on each machine with administrative privileges
  • Docker(link to the What is Docker art) installed on each machine

Configuring the Kubernetes repository

First, we must always consider that Kubernetes packages are not available through the official CentOS 7 repositories. This step therefore must be executed on the master node and on each worker node.

It is therefore the following command that must be run to retrieve the repository from which to subsequently retrieve the installer for Kubernetes:

cat <<EOF > /etc/yum.repos.d/kubernetes.repo

Installation of kubelet, kubeadm, and kubectl

These 3 basic packages are required to be able to use Kubernetes. Install the following packages on each node doing so as you see in the example:

sudo yum install -y kubelet kubeadm kubectl

systemctl enable kubelet

systemctl start kubelet

Before deploying a cluster, be sure to set up hostnames by configuring the firewall and kernel settings.

Set the hostname of a node

To give a unique host name to each of your nodes, use this command:

sudo hostnamectl set-hostname master-node


sudo hostnamectl set-hostname worker-node1

In this example, the master node is now named master-node, while a worker node is named worker-node1.

It now creates a DNS record to resolve the hostname for all nodes: master-node node1. node1 worker-node

Configure the firewall

Nodes, containers and pods must be able to communicate across the cluster to perform their functions. On CentOS by default Firewalld is installed. Add the following ports by entering the commands listed.

On the Master Node therefore run:

sudo firewall-cmd –permanent –add-port=6443/tcp

sudo firewall-cmd –permanent –add-port=2379-2380/tcp

sudo firewall-cmd –permanent –add-port=10250/tcp

sudo firewall-cmd –permanent –add-port=10251/tcp

sudo firewall-cmd –permanent –add-port=10252/tcp

sudo firewall-cmd –permanent –add-port=10255/tcp

sudo firewall-cmd –reload

Having arrived at this point run these commands on each worker node:

sudo firewall-cmd –permanent –add-port=10251/tcp

sudo firewall-cmd –permanent –add-port=10255/tcp

firewall-cmd –reload

Update Iptables Settings

Set the value of net.bridge.bridge-nf-call-iptables to “1” in the sysctl configuration file. This ensures that packets are properly processed by the IP tables when filtering and port forwarding.

cat <<EOF > /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1


sysctl –system

Disable SELinux

Containers must access the host filesystem. SELinux must be set to permissive mode, which disables its security features.

Use the following commands to disable SELinux

sudo setenforce 0

sudo sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/’ /etc/selinux/config

Disable SWAP

Finally, we must disable SWAP to allow kubelet to function properly:

sudo sed -i ‘/swap/d’ /etc/fstab

sudo swapoff -a

Create a cluster with kubeadm

Initialize the cluster with the following command:

sudo kubeadm init –pod-network-cidr=

The process may take several minutes to complete depending on network speed. Upon completion of this command, a kubeadm join message is displayed. Make a note of the record and use it to join the worker nodes to the cluster at a later stage.

Manage the cluster as a standard user

To use the cluster you must be able to log in as a standard user. Run the following set of commands:

mkdir -p $HOME/.kube

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

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

Set Pod Network

The pod network allows nodes within the cluster to communicate with each other. Several Kubernetes network options are available. Use the following command to install the flannel pod network add-on:

sudo kubectl apply -f

If you decide to use flannel, change the firewall rules to allow traffic on flannel’s default port 8285.

Verify kluster status

Verify the status of the nodes by running the following command on the master server:

sudo kubectl get nodes

Once a pod network is installed, you can confirm that it is working by checking that the CoreDNS pod is running by typing:

sudo kubectl get pods –all-namespaces

Add a worker node to the cluster

You can use the kubeadm join command on each worker node to connect it to the cluster.

kubeadm join –discovery-token cfgrty.1234567890jyrfgd –discovery-token-ca-cert-hash sha256:1234..cdef

In conclusion 

You have successfully installed Kubernetes on CentOS and can now manage clusters on multiple servers.

This Kubernetes tutorial provides a good starting point for exploring the many options this platform has to offer. Use Kubernetes to autoscale your containers so you can spend less time micro-managing each one!

Replace the codes with those on your main server. Repeat this action for each worker node on your cluster.

Share: Facebook Twitter Linkedin