Guide to Setting Up a Kubernetes Cluster on CentOS

Guide to Setting Up a Kubernetes Cluster on CentOS

Are you looking to set up a Kubernetes cluster for your applications but unsure where to start? Kubernetes, an open-source container orchestration platform, can help manage and scale your containerized applications with ease. In this guide, we'll walk you through the step-by-step process of setting up a Kubernetes cluster on CentOS, using Kubernetes version 1.27.

Prerequisites

Before we dive into the installation process, ensure that you have the following prerequisites:

  • 2 CPUs on the machine that you use as a control-plane node.
  • 2 GiB or more of RAM per machine.
  • One or more machines running a deb/rpm-compatible Linux OS (e.g., CentOS).
  • Full network connectivity among all machines in the cluster.

Step 1: Installing a Runtime

Remove the Older Version of the Docker

sudo yum remove docker \

docker-client \

docker-client-latest \

docker-common \

docker-latest \

docker-latest-logrotate \

docker-logrotate \

docker-engine

Set Up the Docker Repository

sudo yum install -y yum-utils

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install Containerd

sudo yum install docker-ce docker-ce-cli containerd.io

Step 2: Install and Configure Prerequisites

sudo tee /etc/modules-load.d/k8s.conf <<EOF

overlay

br_netfilter

EOF

sudo modprobe overlay

sudo modprobe br_netfilter

sudo tee /etc/sysctl.d/k8s.conf <<EOF

net.bridge.bridge-nf-call-iptables = 1

net.bridge.bridge-nf-call-ip6tables = 1

net.ipv4.ip_forward = 1

EOF

sudo sysctl --system

Verify sysctl Configuration

sysctl net.bridge.bridge-nf-call-iptables

sysctl net.bridge.bridge-nf-call-ip6tables

sysctl net.ipv4.ip_forward

Step 3: Configuring the systemd cgroup driver

Edit the Containerd Configuration

sudo tee -a /etc/containerd/config.toml <<EOF

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]

SystemdCgroup = true

EOF

sudo systemctl restart containerd

Step 4: Install Kubeadm, Kubelet, and Kubectl

Set SELinux to Permissive Mode

sudo setenforce 0

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

Add the Kubernetes yum Repository

sudo tee /etc/yum.repos.d/kubernetes.repo <<EOF

[kubernetes]

name=Kubernetes

baseurl=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/

enabled=1

gpgcheck=1

gpgkey=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key

exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni

EOF

sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

sudo systemctl enable --now kubelet

Step 5: Initialize the Control Plane

Make sure Containerd is running

sudo systemctl status containerd

Initialize the control plane

kubeadm init

Step 6: Post-Initialization Setup

After the control plane has been initialized successfully, run these commands

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 7: Join the nodes

Use the join token to join the worker nodes to the cluster.

kubeadm join <control-plane-host>

Step 8: Install the Pod Network

kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml

Change the Configuration Options

kubectl get ds -A

kubectl edit ds weavenet

Under the environment variable section, add:

- name: IPALLOC_RANGE

value: 10.244.0.0/16












要查看或添加评论,请登录

Muhammad Shaheer的更多文章

  • DevOps is about tools or principles?

    DevOps is about tools or principles?

    Case Studies from The DevOps Handbook The DevOps Handbook, written by Gene Kim, Jez Humble, Patrick Debois, and John…

    2 条评论
  • Comparing Messaging Service Pricing

    Comparing Messaging Service Pricing

    Messaging services are essential components in modern cloud architectures, facilitating communication between…

社区洞察

其他会员也浏览了