This is how to install Kubernetes on the Linux machine (CentOS7) – Master Node + Worker Node
Prerequisite – Install Docker
docker version
Check the OS
cat /etc/redhat-release
Switch User to root
sudo su
Disable SELinux
- SELinux (Security Enhanced Linux) is a Linux kernel security module
- Enforcing: SELinux allows access based on SELinux policy rules. (default)
- Permissive: SELinux only logs actions that would have been denied if running in enforcing mode.
- Disabled: No SELinux policy is loaded.
- The containers need to access the host file system
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
Enable the br_netfilter module for cluster communication
- This ensures that packets are properly processed by IP tables during filtering and port forwarding.
modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
Disable swap to prevent memory allocation issues
swapoff -a
vim /etc/fstab
- Comment out the swap line

Add the Kubernetes repo
cat <<EOF> /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
Install Kubernetes
yum install -y kubelet kubeadm kubectl
Check the docker
sudo systemctl enable docker
sudo systemctl start docker
docker image ls
Enable Kubernetes
- The kubelet service will not start until you run kubeadm init.
sudo systemctl enable kubelet
Initialize the cluster using the IP range for Flannel – Master Only
- This is only for the master node. Do not run this on a worker node.
kubeadm init --pod-network-cidr=10.244.0.0/16
- Copies the last command “kubeadmin join”

Exit sudo and Copy the config – Manage Cluster as Regular User – Master Only
exit
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Check the Installation – Master
kubectl get nodes
- There is 1 node and its status is “NotReady”
Deploy Flannel – Master Only
- A Pod Network allows nodes within the cluster to communicate. The flannel virtual network add-on is used for this purpose.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get nodes
- Now the node is ready
Join worker nodes to master – Worker
- This is only for the worker node.
- In the worker node, run the “kubeadm join” command copied before
sudo kubeadm join 172.31.115.9:6443 --token lzbl14.prno5dl0kxm73jee --discovery-token-ca-cert-hash sha256:1f73ceb22b2af3bec315d35abd313f19576d96bfd0cee771df2f9763f8bb00f7
Check the cluster State – Master
kubectl get nodes
kubectl get pods --all-namespaces
kubectl cluster-info
- You can see all nodes (master + workers)
Testing
Create a simple pod running an nginx container
cat << EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
EOF
Get a list of pods and verify that your new nginx pod is in the Running state
kubectl get pods
kubectl describe pod nginx
Get the IP addresses of your pods
kubectl get pods -o wide
- Get the ip address of the pod and curl to the ip == > you can get the nginx welcome page

Delete the pod
kubectl delete pod nginx