Kubernetes K8s Setup on CentOS:7 with easy steps.
![Rakesh Kumar Jangid](https://cdn.hashnode.com/res/hashnode/image/upload/v1702629612426/m6B3zcC7w.jpg)
5 min read
Table of contents
- k8s Setting up on-premise virtual machines OR Cloud AWS Ec2 Instances.
- Step 1: Check your IP or create a network using #nmcli
- Step 2: Disable swap memory, selinux & firewall
- Step 3: Accessing SSH without using a password by sharing our public key.
- Step 4: Install Docker-CE Engine (Execute on all master + slave nodes both)
- Step 5: To update or add kernel arguments for both infra environments, and enable the bridge for all nodes including master.
- Step 6: Add Kubernetes Yum Repo from Google
- Step 7: Install kubeadm, kubelet, kubectl packages
- Step 8: Start kubelet services agent
- Step 9: Start Docker Host, containerd services (On all nodes including master)
- Step 10: Initialize kubeadm init command (On Master Node only)
- Step 11: Start cluster configuration at MASTER NODE Only with regular user.
- Step 12: Download CNI Weave net (Execute only on Master Node) โ ( Treated as Router)
- Step 13: Go to the output of Step 10 and find the <kubeadm join> code and copy it at each worker node.
- Step-14: Check the connected cluster status at the Master Node
![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702620787744/3e22edc3-5476-452f-bb8d-b494aaf55ad0.png)
๐ก
Taking inspiration from and dedicated to our training guru, Shri Maninder sir.
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
๐ก
Note: This Step-1 is only for On-Primise VMs, not for cloud AWS instances. and execute this step-1 on all cluster nodes including the master node .
# 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
๐ก
Note: In the shortcut edit
/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/hosts
file
# 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.
๐ก
NOTE: Only From the master node, we'll generate a public key and then share it with the other worker nodes.
# 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
๐ก
Note: Execute on all cluster nodes including the master node
# 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
๐ก
Note: Execute on all cluster nodes including master node
# 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
๐ก
We will join the Worker node with the Master Node inside the Cluster in the future, so keep the output safe.
# 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)
๐ก
Official weave net link: <Official web page link>
$ 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
๐ก
Tip: If we forget join/hash code then we can run the following command :
# 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
0
Subscribe to my newsletter
Read articles from Rakesh Kumar Jangid directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Kubernetesclusterk8ssetupvmwareAWSLinuxguideDevopsDevops articlesDevOps Journey#Devopscommunitycentos7clustersEC2 instance
Written by
![Rakesh Kumar Jangid](https://cdn.hashnode.com/res/hashnode/image/upload/v1702629612426/m6B3zcC7w.jpg)
Rakesh Kumar Jangid
Rakesh Kumar Jangid
Let's learn together and serve the society, Make India Proud.