Kubernetes K8s Setup on CentOS:7 with easy steps.

Hey everyone! In this article, we'll learn how to set up a Kubernetes (k8s) cluster on a Linux CentOS 7 machine. You can do this either on cloud servers or virtual machines within your infrastructure.
If you are trying to set up a Kubernetes (k8s) cluster on an Ubuntu machine, try this article link: https://rakeshkumarjangid.hashnode.dev/how-to-setup-kubernetes-cluster-over-cloud-on-ubuntu-os, So let's start...
k8s Setting up on-premise virtual machines OR Cloud AWS Ec2 Instances.
| Cluster Type | Specifications | OS Type |
| On-Primise VM (1 Master + 2 Worker) | 4 GRB RAM, 2 Core, 20 GB storage in each machine | Centos:7 |
| Cloud AWS | T2.Medium or up | AWS Linux |
Step 1: Check your IP or create a network using #nmcli
# cat /etc/os-release
# nmcli con show
NAME UUID TYPE DEVICE
ens160 4443b0e3-1b19-3b0e-9861-7f0fbf825f6c ethernet ens160
| VMs Nodes-Private-IP | VMs Node-Hostname |
| 192.168.1.1 | master.localhost.com |
| 192.168.1.2 | w1.localhost.com |
| 192.168.1.3 | w2.localhost.com |
# hostnamectl set-hostname master.localhost.com && exec bash
# nmcli con mod ens160 ipv4.addresses 192.168.1.1/24 ipv4.gateway 192.168.1.255 ipv4.dns 8.8.8.8
# nmcli con up ens160
/etc/sysconfig/network-scripts/ifcfg-ensp* file.# vi /etc/sysconfig/network-scripts/ifcfg-ensp***
IPADDR= ?
NETMASK= ?
GATEWAY=?
DNS1=?
- Mention the hostname and IP address in the
/etc/hostsfile
# vi /etc/hosts
192.168.1.1 www.master.localhost.com
192.168.1.2 www.w1.localhost.com
192.168.1.3 www.w2.localhost.com
:wq!
Step 2: Disable swap memory, selinux & firewall
# swapoff -a
# sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# setenforce 0
# sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
# systemctl disable firewalld && systemctl stop firewalld
# free -h
# sestatus
# systemctl statuts firewalld
Step 3: Accessing SSH without using a password by sharing our public key.
# ssh-keygen -t rsa
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.X
Step 4: Install Docker-CE Engine (Execute on all master + slave nodes both)
# yum-config-manager --add-repo https://download.docker.com/linux/centos/dockerce.repo
# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum install docker-ce-20* -y
# systemctl start docker && systemctl enable docker
Step 5: To update or add kernel arguments for both infra environments, and enable the bridge for all nodes including master.
# 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 6: Add Kubernetes Yum Repo from Google
# cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
Step 7: Install kubeadm, kubelet, kubectl packages
# yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
Step 8: Start kubelet services agent
# systemctl restart kubelet ; systemctl enable kubelet ; systemctl status kubelet
Step 9: Start Docker Host, containerd services (On all nodes including master)
# systemctl enable docker && systemctl restart docker
Step 10: Initialize kubeadm init command (On Master Node only)
# kubeadm init
# echo "kubeadm join 172.31.4.165:6443 --token kw9d4k.l44fcziztb3br21a \
--discovery-token-ca-cert-hash
sha256:2952821ac60c0ddb079cc82bd621a72e61aae08a4e700c4f8d457058d7f51dd7" > ~/join.txt
Step 11: Start cluster configuration at MASTER NODE Only with regular user.
$ mkdir -p $HOME/.kube
$ cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ chown $(id -u):$(id -g) $HOME/.kube/config
Step 12: Download CNI Weave net (Execute only on Master Node) → ( Treated as Router)
$ https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
Step 13: Go to the output of Step 10 and find the <kubeadm join> code and copy it at each worker node.
# kubeadm join 172.31.4.165:6443 --token kw9d4k.l44fcziztb3br21a \
--discovery-token-ca-cert-hash
sha256:2952821ac60c0ddb079cc82bd621a72e61aae08a4e700c4f8d457058d7f51dd7
# kubeadm token create --print-join-command
Step-14: Check the connected cluster status at the Master Node
$ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master.localhost.com Ready master 1d 1.27.2 192.168.1.1 <none> CentOS Linux 7 (Core) 4.19.0-19-amd64 docker://20.10.7
w1.localhost.com Ready <none> 1d 1.27.2 192.168.1.2 <none> CentOS Linux 7 (Core) 4.19.0-19-amd64 docker://20.10.7
w2.localhost.com Ready <none> 1d 1.27.2 192.168.1.3 <none> CentOS Linux 7 (Core) 4.19.0-19-amd64 docker://20.10.7
$ kubectl get ns
$ kubectl get pods -n kube-system -o wide
$ kubect api-resources
$ kubectl get po -n kube-system -o wide
Congratulations to all. Thanks you sir
About the author
Let's learn together and serve the society, Make India Proud.
Comments
Join the discussionNo comments yet. Be the first to comment.
Kubernetes-Series
Kubernetes, or K8s, is a system for managing containerized apps in a clustered environment. It provides efficient ways of managing distributed components across various infrastructures.






