How to Install Kubernetes on CentOS 7

Kubernetes is a powerful open-source platform for automating deployment, scaling, and management of containerized applications. This guide will show you how to install Kubernetes on CentOS 7.

Disabling SELinux

Disable SELinux as it can interfere with Kubernetes:

sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

Installing Docker

Kubernetes requires a container runtime; Docker is a popular choice:

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io -y
sudo systemctl start docker
sudo systemctl enable docker

Configuring Kubernetes Repository

Add the Kubernetes repository:

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
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

Installing Kubernetes Components

Install Kubernetes components (kubelet, kubeadm, kubectl):

sudo yum install -y kubelet kubeadm kubectl
sudo systemctl enable kubelet
sudo systemctl start kubelet

Disabling Swap

Kubernetes requires swap to be disabled:

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

Initializing Kubernetes Cluster

Initialize the Kubernetes cluster using kubeadm:

sudo kubeadm init

Configuring kubectl

To start using Kubernetes, set up the local kubeconfig:

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

Deploying Pod Network

Install a pod network so that your pods can communicate with each other. Calico is a common choice:

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Joining Worker Nodes

Use the token provided by the `kubeadm init` command to join worker nodes to your cluster.

Your CentOS 7 server now has Kubernetes installed. This setup forms the foundation for deploying and managing containerized applications at scale with Kubernetes.

About the author

Technical Sahil

Sahil Dhamija is a visionary entrepreneur and tech enthusiast, proudly owning multiple companies across India, the US, the UK, and the UAE. As the founder of AInventions Technologies LLC, DigitalMarkethink Solutions LLC, WebReinvent Technologies LLC, BusinessMate Software Solutions LLC, and co-founder of Hostyaga FZE LLC, Sahil is a dynamic leader shaping the future of technology and digital marketing.

Apart from leading his businesses, Sahil is a passionate tech YouTuber, sharing insights and tutorials on various technological topics. He also serves as the CTO at Vayuna Corporate Travels Pvt Ltd and as Product Head at Vayuna Voicetech Pvt Ltd, where he oversees cutting-edge solutions in corporate travel and voice technology. Additionally, Sahil is a creative force in the film industry, producing films through Gentle Breeze Films Pvt Ltd.

Driven by innovation and creativity, Sahil continues to push boundaries in technology, media, and business.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *