Install and configure Kubernetes on Ubuntu/Debian and CentOS/RHEL

setup and config Kubernetes on Ubuntu/Debian CentOS/RHEL install

Kubernetes is a powerful open-source container orchestration platform used for automating the deployment, scaling, and management of containerized applications. This step-by-step guide will walk you through the process of installing Kubernetes on both Ubuntu/Debian and CentOS/RHEL systems. We will use popular tools such as kubeadmkubectl, and kubelet to set up a functional Kubernetes cluster.

Prerequisites

Before diving into the installation process, ensure that you have the following prerequisites in place:

  • A machine running Ubuntu, Debian, CentOS, or RHEL with at least 2GB of RAM (4GB or more is recommended).
  • A user account with appropriate privileges (sudo for Ubuntu/Debian, root for CentOS/RHEL).
  • A stable internet connection.
  • Familiarity with basic Linux command-line operations.

Installing Kubernetes on Ubuntu/Debian

Step 1: Update Your System

Begin by updating your system to ensure that you have the latest package information and security updates:

$ sudo apt update && sudo apt upgrade -y

Step 2: Install Docker

Kubernetes requires a container runtime to manage containers. We’ll use Docker in this guide. You can follow this article to learn how to install and use Docker on Ubuntu LTS. Once Docker is installed, return to this guide to continue with the Kubernetes installation process.

Step 3: Disable Swap

Kubernetes performs best when swap is disabled. Disable it with the following commands:

$ sudo swapoff -a
$ sudo sed -i '/ swap / s/^/#/' /etc/fstab

Step 4: Install Kubernetes Components

Install the necessary Kubernetes components (kubeadmkubectl, and kubelet):

$ sudo apt install -y kubelet kubeadm kubectl
$ sudo systemctl enable kubelet

Step 5: Initialize Kubernetes with kubeadm

On your master node, initialize Kubernetes using kubeadm. Don’t forget to replace <your-pod-network-cidr> with your preferred Pod network CIDR (e.g., 192.168.0.0/16):

$ sudo kubeadm init --pod-network-cidr=<your-pod-network-cidr>

Step 6: Set Up Kubectl

To interact with your Kubernetes cluster, set up the Kubernetes configuration for your user:

$ 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: Configure Pod Network

Select a Pod network add-on and install it. For instance, you can choose to install Calico:

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

Step 8: Join Worker Nodes (Optional)

If you have worker nodes, you can add them to the cluster using the kubeadm join command provided during the master initialization.

Installing Kubernetes on CentOS/RHEL

Step 1: Update Your System

Ensure your system is up-to-date by running the following command:

$ sudo yum update -y

Step 2: Install Docker

Kubernetes relies on a container runtime like Docker, which you can install as follows:

$ sudo yum install docker -y
$ sudo systemctl enable docker
$ sudo systemctl start docker

Step 3: Disable Swap

Optimize Kubernetes performance by disabling swap:

$ sudo swapoff -a
$ sudo sed -i '/ swap / s/^/#/' /etc/fstab

Step 4: Install Kubernetes Components

Install Kubernetes components (kubeadmkubectl, and kubelet) using the following steps:

$ sudo tee /etc/yum.repos.d/kubernetes.repo <<EOF
[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
$ sudo yum install -y kubelet kubeadm kubectl
$ sudo systemctl enable kubelet

Step 5: Initialize Kubernetes with kubeadm

Initialize Kubernetes on the master node, ensuring to specify your desired Pod network CIDR:

$ sudo kubeadm init --pod-network-cidr=<your-pod-network-cidr>

Step 6: Set Up Kubectl

Configure the Kubernetes configuration for your user:

$ 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: Configure Pod Network

Choose a Pod network add-on, such as Calico, and deploy it:

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

Step 8: Join Worker Nodes (Optional)

If you have worker nodes, you can include them in the cluster by using the kubeadm join command provided during the master initialization.

Conclusion

Congratulations! You’ve successfully installed Kubernetes on both Ubuntu/Debian and CentOS/RHEL systems. Kubernetes is now ready to manage your containerized applications and workloads. Remember to secure your cluster, manage deployments, and explore Kubernetes features to unlock its full potential. Enjoy orchestrating your containers with Kubernetes!

LEAVE A COMMENT