Wednesday, April 25, 2018

Kubernetes - Master Node Configuration

For installing Kubernetes , we will be doing that on 2 machines. The Machine details include    -  Master Node      -  Worker Node

Configuration on Master Node 
Set the Hostname for the master node as ‘k8s-master’  
hostnamectl set-hostname ‘k8s-master’

Disable Selinux
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

Configure the Firewall rules
firewall-cmd --permanent --add-port=6443/tcp
firewall-cmd --permanent --add-port=2379-2380/tcp
firewall-cmd --permanent --add-port=10250/tcp
firewall-cmd --permanent --add-port=10251/tcp
firewall-cmd --permanent --add-port=10252/tcp
firewall-cmd --permanent --add-port=10255/tcp
firewall-cmd --reload

Set the bridge-nf-call-iptables to 1
modprobe br_netfilter
echo ‘1’ > /proc/sys/net/bridge/bridge-nf-call-iptables

These control whether or not packets traversing the bridge are sent to iptables for processing
Configure the Kubernetes Yum Repo
Create a kubernetes.repo  file under /etc/yum.repos.d/ with the below contents,


Install , Enable & Start Docker and kubeadm
yum install kubeadm docker -y
systemctl restart docker && systemctl enable docker
systemctl  restart kubelet && systemctl enable kubelet
Initialize the Kubernetes Master by kubeadm
Run the “kubeadm init” command to initialize the kubernetes master , if all goes well will be seeing an output similar to the below

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

You can now join any number of machines by running the following on each node
as root:

  kubeadm join --token pe7y1r.zk9u6c07g2nlwm3h --discovery-token-ca-cert-hash sha256:48dfb2c9eda08aaed84a70011221804c80adcd700e73d870fd12d041b0054641

Save the contents of this output since we will be using in connecting the worker nodes with the master node.

Configure the cluster to use as Root user
Once the master is up and running , we then need to configure our cluster to be used by root user. Execute the commands ,

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Once the commands are executed , get the pod list using the Kubectl command as ,
We will be seeing all pods running in the current cluster. Once Pod “dns” is still in pending. 
If we get the node list even, we see that the master is still in “NotReady” state. We need to get the Master to ready state and also the dns pod to running state. We need to deploy the pod network so that containers in other hosts communicate with each other. POD network is the overlay network between worker nodes.

Note - An overlay network is a telecommunications network that is built on top of another network and is supported by its infrastructure. An overlay network decouples network services from the underlying infrastructure by encapsulating one packet inside of another packet.

The network must be deployed before any application. Kube-dns is a internal helper service will not startup before a network is installed. Several projects provide kubernetes pod networks using CNI ( Container network interface ) and we will be using one from the weave cloud

Run the below commands to get the Pod Network running and master to ready state,
export kubever=$(kubectl version | base64 | tr -d '\n')
kubectl apply -f "$kubever"

Once we execute the above commands , we see that there are couple of service accounts being created. If all goes well and we run the get pods commands as,
We will be able to see all the Pods running and also the  master in Ready State.

[root@manja17-I13330 ~]# kubectl get nodes
NAME                 STATUS    ROLES     AGE       VERSION
manja17-i13330    Ready     master    1d        v1.10.1

Now that all are up and running we are done with our master. We need to configure the worker node.

No comments :

Post a Comment