The cart is empty

Kubernetes is an open-source platform designed for automating deployment, scaling, and operation of application containers. Setting up and managing a Kubernetes cluster on CentOS 7 requires careful planning and configuration. This article provides a detailed guide to setting up and configuring a Kubernetes cluster on CentOS 7.

Prerequisites

Before getting started, it's important to ensure that all servers (nodes) intended to be part of the cluster meet the following prerequisites:

  • CentOS 7 installed on all nodes.
  • Minimum 2GB RAM for each node (Master and Worker nodes).
  • 2 CPUs for the Master node.
  • Full network access between all nodes in the cluster.
  • Disabled firewall or configured rules to allow communication between nodes.
  • Disabled SELinux or set to permissive mode.
  • Docker installed as the container runtime.

1. System Preparation

Perform the following steps on all nodes to prepare the system:

a. Set Hostname

hostnamectl set-hostname <hostname>

b. Configure Hosts File

Edit the /etc/hosts file on all nodes to include the IP addresses and hostnames of all cluster members.

c. Disable SELinux

setenforce 0
sed -i --follow-symlinks 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux

d. Disable Firewall

systemctl stop firewalld
systemctl disable firewalld

2. Install Docker

Docker is a prerequisite for running containers. Install Docker on all nodes:

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker
systemctl enable docker

3. Add Kubernetes Repository

Add the official Kubernetes repository on all nodes:

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

4. Install Kubernetes

Install Kubernetes on all nodes:

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

5. Initialize Master Node

Initialize the cluster on the Master node using kubeadm:

kubeadm init --pod-network-cidr=192.168.0.0/16

Take note of the output, which includes the token for joining Worker nodes after initialization.

6. Configure kubectl Environment

Set up kubectl on the Master node to interact with the cluster:

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

7. Deploy Network Plugin

Deploy a network plugin, such as Weave Net, for container communication:

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

8. Join Worker Nodes

On each Worker node, join the cluster using the tokens obtained during Master node initialization:

kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>

Upon completing these steps, your Kubernetes cluster on CentOS 7 should be operational. You can start deploying containerized applications and leverage Kubernetes capabilities for their management. Remember to regularly update your cluster and monitor its performance and security.