Kubernetes
It is easy to get lost in the details of Kubernetes, but at the end of the day, what Kubernetes is doing is pretty simple. Cheryl Hung of the CNCF describes Kubernetes as a control loop. Declare how you want your system to look (3 copies of container image a and 2 copies of container image b) and Kubernetes makes that happen. Kubernetes compares the desired state to the actual state, and if they aren’t the same, it takes steps to correct it.
Kubernetes is made up many components that do not know are care about each other. The components all talk to each other through the API server. Each of these components operates its own function and then exposes metrics, that we can collect for monitoring later on. We can break down the components into three main parts.
1. The Control Plane - The Master
2. Nodes - Where pods get scheduled
3. Pods - Holds containers
Kubernetes and Docker are both comprehensive de-facto solutions to intelligently manage containerized applications and provide powerful capabilities, and from this some confusion has emerged. “Kubernetes” is now sometimes used as a shorthand for an entire container environment based on Kubernetes. In reality, they are not directly comparable, have different roots, and solve for different things.
[Master Node] |192.0.0.20 ---------------- 192.0.0.30| [Worker Node]
master-node <---------------------> worker-node
Lets start to setup Kubernetes Cluster:-
Configure Master Node:-
Step:1 Update Hostname
[root@master ~]# vim /etc/hosts
# hostnamectl set-hostname master-node
# cat <> /etc/hosts
192.0.0.20 master-node
192.0.0.30 worker-node
Step:2 Disable Selinux
[root@master ~]# setenforce 0
[root@master ~]# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
[root@master ~]# reboot
Step:3 Allow ports on Firewall If it is running
[root@master ~]# firewall-cmd --permanent --add-port=6443/tcp
[root@master ~]# firewall-cmd --permanent --add-port=2379-2380/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10250/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10251/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10252/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10255/tcp
[root@master ~]# firewall-cmd –reload
[root@master ~]# modprobe br_netfilter
[root@master ~]# echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
Step:4 Setup the Kubernetes Repo
[root@master ~]# 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
Step:5 Install Kubeadm and Docker
[root@master ~]# yum install kubeadm docker -y
Step:6 Start and Enable Services
[root@master ~]# systemctl enable docker
[root@master ~]# systemctl start docker
[root@master ~]# systemctl enable kubelet
[root@master ~]# systemctl start kubelet
Step:7 Initialize Kubernetes Master
[root@master ~]# swapoff -a
[root@master ~]# kubeadm init
#Copy last line because you will need to run it on the worker nodes.It will look like as below.
kubeadm join 192.0.0.20:6443 --token 0734wq.nxruvpz3ddneizn7 \
--discovery-token-ca-cert-hash sha256:107866f0cfa9a467508bf2ecbb18ab9be8750c82cda6d598ada64686bc686c6a
Step:8 In order to use as root, Please run below:
[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master ~]# chown $(id -u):$(id -g) $HOME/.kube/config
Step:9 Setup Your Pod Network
[root@master ~]# export kubever=$(kubectl version | base64 | tr -d '\n')
[root@master ~]# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"
Now check the status of your master-node, it should be Ready.
[root@master ~]# kubectl get nodes
Setup Worker Node:-
Step:1 Update Hostname
[root@master ~]# vim /etc/hosts
# hostnamectl set-hostname master-node
# cat <> /etc/hosts
192.0.0.20 master-node
192.0.0.30 worker-node
Step:2 Disable Selinux
[root@master ~]# setenforce 0
[root@master ~]# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
[root@master ~]# reboot
Step:3 Allow ports on Firewall If it is running
[root@master ~]# firewall-cmd --permanent --add-port=6443/tcp
[root@master ~]# firewall-cmd --permanent --add-port=2379-2380/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10250/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10251/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10252/tcp
[root@master ~]# firewall-cmd --permanent --add-port=10255/tcp
[root@master ~]# firewall-cmd –reload
[root@master ~]# modprobe br_netfilter
[root@master ~]# echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
Step:4 Setup the Kubernetes Repo
[root@master ~]# 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
Step:5 Install Kubeadm and Docker
[root@master ~]# yum install kubeadm docker -y
Step:6 Start and Enable Services
[root@master ~]# systemctl enable docker
[root@master ~]# systemctl start docker
[root@master ~]# systemctl enable kubelet
[root@master ~]# systemctl start kubelet
Step:7 Join the Worker Node to the Kubernetes Cluster
#paste here the copied line from master
[root@worker ~]#
kubeadm join 192.0.0.20:6443 --token 0734wq.nxruvpz3ddneizn7 \
--discovery-token-ca-cert-hash sha256:107866f0cfa9a467508bf2ecbb18ab9be8750c82cda6d598ada64686bc686c6a
Step:8 In order to use as root, Please run below:
[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# cp -i /etc/kubernetes/kubelet.conf $HOME/.kube/config
[root@master ~]# chown $(id -u):$(id -g) $HOME/.kube/config
Now check the status of your master-node, it will show worker-node also.
[root@master ~]# kubectl get nodes
Now, You are ready to use kubernetes!