How to Install Kubernetes Cluster on CentOS 7


How to Install Kubernetes Cluster on CentOS 7

Kubernetes, an open-source container orchestration platform, has become a cornerstone in modern cloud-native application development. Setting up a Kubernetes cluster on CentOS 7 can be a valuable skill for anyone involved in managing containerized applications. In this guide, we will walk through the process of installing Kubernetes on a CentOS 7 server, step by step.

Prerequisites:

Before diving into the installation process, ensure that you have:

  1. A CentOS 7 server with root access.
  2. At least 2 servers (nodes) for a basic Kubernetes cluster.
  3. Disable SELinux and set up a proper hostname for each node.

Step 1: Update the System:

Always start by ensuring your system is up to date. Run the following commands on each node:

sudo yum update
sudo reboot

Step 2: Install Docker:

Kubernetes relies on containerization, and Docker is the preferred container runtime. Install Docker by executing the following commands on all nodes:

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

Step 3: Install Kubernetes Repository:

Next, add the Kubernetes repository to your system:

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

Step 4: Install Kubernetes Components:

Install the necessary Kubernetes components - kubelet, kubeadm, and kubectl:

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

Step 5: Initialize the Kubernetes Master:

On the designated master node, initialize the Kubernetes control plane:

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

Follow the on-screen instructions and execute the provided commands to set up your Kubernetes configuration.

Step 6: Set Up Cluster Networking:

For networking within the cluster, install a network plugin. Calico is a popular choice:

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

Step 7: Join Worker Nodes to the Cluster:

On each worker node, join the cluster by running the command obtained from the kubeadm init output on the master node.

Step 8: Verify Cluster Status:

Ensure the cluster is up and running:

kubectl get nodes
kubectl get pods --all-namespaces

Step 9: Deploy a Sample Application:

Test your Kubernetes cluster by deploying a sample application:

kubectl create deployment hello-world --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment hello-world --type=NodePort --port=8080

Access the application using the worker node's IP and the assigned NodePort.

Congratulations! You have successfully installed and configured a Kubernetes cluster on CentOS 7.

Related Searches and Questions asked:

  • Building Optimized Containers for Kubernetes
  • How to Install Kubernetes on a Bare Metal Server
  • Kubectl Port-Forward: Kubernetes Port Forwarding Guide
  • Kubernetes Security Best Practices
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.