How to Install Kubernetes Cluster on Centos

                                    How to Install Kubernetes Cluster on Centos

 

Kubernetes (k8s) is an open-source, cloud-native, container orchestration and management platform. It’s the go-to way to automate the deployment, scaling, and maintenance of containerised applications across different nodes.

What is a Kubernetes Cluster?

A Kubernetes cluster consists of a Master and at least one to several worker node(s). The Master is the virtual machine (VM) that administers all activities on your cluster. A node is a VM that serves as a worker machine in your k8s cluster to host running applications.

 

Prerequisites:-
• Multiple CentOS 7 VMs (Cloud Servers) to house the Master and worker nodes.
• Docker or any other container runtime.

Step 1. Install Docker on all CentOS 7 VMs :-

1.      #yum check-update

2.      Install the dependencies

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

3.      Add and enable official Docker Repository to CentOS 7

              # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

4.      Install the latest Docker version on CentOS 7

             # yum install docker-ce

5.      Manage Docker Service

              #systemctl start docker
             #systemctl enable docker
              #systemctl status docker

Step 2. Set up the Kubernetes Repository :-

1.      #vi /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

Save and quit.

Step 3. Install Kubelet on CentOS 7:-

The first core module that we need to install on every node is Kubelet.

1.      #yum install -y kubelet 

Step 4. Install kubeadm and kubectl on CentOS 7:-

kubeadm, the next core module, will also have to be installed on every machine.

             # yum install -y kubeadm

(Note that kubeadm automatically inOn your Master node, update your hostname using the following command:

Step 5. Set hostnames:-

On your Master node, update your hostname using the following command:

# hostnamectl set-hostname master-node

And

# hostnamectl set-hostname W-node1
Now open the /etc/hosts file and edit the hostnames for your worker nodes:
# cat <<EOF>> /etc/hosts
10.168.10.207 master-node
10.168.10.208 node1 W-node1
10.168.10.209 node2 W-node2
EOF

Step 6. Disable SElinux:-

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

Step 7. Add firewall rules:-

To allow seamless communication between pods, containers, and VMs, we need to add rules to our firewall on the Master node.

# 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
You will also need to run the following commands on each worker node:
#firewall-cmd --permanent --add-port=10251/tcp
#firewall-cmd --permanent --add-port=10255/tcp
#firewall-cmd –reload
 Step 8. Update iptables config:-

We need to update the net.bridge.bridge-nf-call-iptables parameter in our sysctl file to ensure proper processing of packets across all machines.

#cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# sysctl --system

Step 9. Disable swap:-

For Kubelet to work, we also need to disable swap on all of our VMs:

#sed -i '/swap/d' /etc/fstab
#swapoff -a

 

Deploying a Kubernetes Cluster on CentOS 7

Step 1. kubeadm initialization:-

 

To launch a new Kubernetes cluster instance, you need to initialize kubeadm.

#kubeadm init

You will also get an auto-generated command at the end of the output. Copy the text following the line Then you can join any number of worker nodes by running the following on each as root: as highlighted in the above screenshot and save it somewhere safe. We will use this to add worker nodes to our cluster.

#kubeadm token create --print-join-command

Step 2. Create required directories and start managing Kubernetes cluster :-

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

Step 3. Set up Pod network for the Cluster:-

Pods within a cluster are connected via the pod network. At this point, it’s not working. This can be verified by entering the following two commands:

#kubectl get nodes
#kubectl get pods --all-namespaces
 
As you can see, the status of masternode is NotReady. The CoreDNS service is also not running. To fix this, run the following commands:
#export kubever=$(kubectl version | base64 | tr -d '\n')
#kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$kubever
 
And now if you verify the statuses of your node and CoreDNS service, you should get Ready and Running

 

Step 4. Add nodes to your cluster:-

#kubeadm join 102.130.118.27:6443 --token 848gwg.mpe76povky8qeqvu --discovery-token-ca-cert-hash sha256:f0a16f51dcc077da9e41f01bdcbc465343668f36d55f41250c570a2be8321eac

Running the following command on the master-node should show your newly added node.

#kubectl get nodes

 

To set the role for your worker node, use the following command:

#kubectl label node w-node1 node-role.kubernetes.io/worker=worker

 

 

  • 0 Uživatelům pomohlo
Byla tato odpověď nápomocná?

Powered by WHMCompleteSolution