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 https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce

cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

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

/etc/systemd/system/multi-user.target.wants/kubelet.service
/usr/lib/systemd/system/kubelet.service
/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf

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

kubeadm init –apiserver-advertise-address=0.0.0.0 –apiserver-cert-extra-sans=kube-master,192.168.77.202 –pod-network-cidr=10.244.0.0/16

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 https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

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 :: http://10.0.15.10:30691/
node 1 :: http://10.0.15.10:30691/

# – 3 create image

# – 4 test image

# – 5 create deployment

# – 6 Run deployment

# – 7 install helm and tiller