Cloud & Orchestration

How to install kubernetes cluster

We will set kubernetes cluster with 1 kub master and 2 nodes [3 Virtual Servers. (VMs)]

# – 1 Master

swapoff -a

# disable swap /etc/fstab

# Disable SE Linux and IPv6

setenforce 0
sed -i –follow-symlinks ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/sysconfig/selinux

hostnamectl set-hostname kube-node3

set time zone and sync date and time.

If the server has firewalld then open these ports. If its iptables then run appropriate commands.

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 –permanent –add-port=8001/tcp

firewall-cmd –reload

modprobe br_netfilter

echo ‘1’ > /proc/sys/net/bridge/bridge-nf-call-iptables

# Update /etc/hosts file on master and worker nodes

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager –add-repo
yum install -y docker-ce

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

vi /etc/yum.repos.d/kubernetes.repo

yum install -y kubelet kubeadm kubectl

systemctl start docker && systemctl enable docker
systemctl start kubelet && systemctl enable kubelet

sudo reboot


>> (This command to be un on master node only)
# Kubernetes Cluster Initialization

kubeadm init –apiserver-advertise-address= –apiserver-cert-extra-sans=kube-master, –pod-network-cidr=

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

# Next, deploy the flannel network to the kubernetes cluster using the kubectl command.

kubectl apply -f

kubectl get nodes
kubectl get pods –all-namespaces

# – 2 Worker node
# Adding node01 and node02 to the Cluster

run all above commands till server reboot.

>> (Make sure that this is run on woker nodes only)

kubeadm join kube-master:6443 –token yt6oqo.7kxhocxh1q08fphp –discovery-token-ca-cert-hash sha256:59a9016869db4bcc1f2055496af20b5dffdd1cd28ffe42fc5808c23190b11384

kubectl get nodes
kubectl get pods –all-namespaces

Testing Create First Pod

kubectl create deployment nginx –image=nginx
kubectl describe deployment nginx
kubectl create service nodeport nginx –tcp=80:80

kubectl get pods
kubectl get svc

curl node01:30691
curl node02:30691

from browser :

node 1 ::
node 1 ::

# – 3 create image

# – 4 test image

# – 5 create deployment

# – 6 Run deployment

# – 7 install helm and tiller

How add new worker node to kubernetes cluster.

# How add new worker node to kubernetes cluster.

Try to create new as per below command as initial token is valid only 24 hours.

Here ttl=0 means, generated token will never expire.

[[email protected] ~]# kubeadm token generate

[[email protected] ~]# kubeadm token create xdsm9b.3j0i25r2vozi9cbd –print-join-command –ttl=0

kubeadm join –token xdsm9b.3j0i25r2vozi9cbd –discovery-token-ca-cert-hash sha256:59a9016869db4bcc1f2055496af20b5dffdd1cd28ffe42fc5808c23190b11384

Go to Top