DEV Community

Cover image for Kubernetes Cluster Step By Step
Neeraj Kumar
Neeraj Kumar

Posted on

Kubernetes Cluster Step By Step

A Kubernetes cluster is a group of nodes or machines running together. At the highest level of Kubernetes, there are two types of servers: a Master node and Worker nodes. These servers can be either Virtual Machines (VMs) or physical servers (Bare metal). Together, these servers form a Kubernetes cluster, and they are controlled by the services that make up the Control Plane.

Prerequisites:

  • Choose a Cloud Provider: Popular choices include AWS, Google Cloud Platform (GCP), Microsoft Azure, and others. Alternatively, you can use on-premises solutions like VMware or tools like Minikube for local development.

  • Install Necessary Tools: kubectl: Kubernetes command-line tool kubeadm, kubelet, and kubernetes-cni: Install these on each cluster node.

Step 1: Provision the Infrastructure
On Cloud Providers:

  • Create VM instances or nodes based on your chosen provider.

  • Ensure that each node has a compatible OS (Ubuntu, CentOS, etc.).
    

On-Premises or Local:

  • Set up physical or virtual machines.
    
  • Ensure network connectivity between nodes.
    

Step 2: Install Docker (or Another Container Runtime)
Install Docker on each node or use an alternative container runtime:



# For Ubuntu
sudo apt update
sudo apt install docker.io
sudo systemctl enable --now docker



Enter fullscreen mode Exit fullscreen mode

Step 3: Install kubeadm, kubelet, and kubectl



# For Ubuntu
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo systemctl enable --now kubelet



Enter fullscreen mode Exit fullscreen mode

Step 4: Initialize the Master Node



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



Enter fullscreen mode Exit fullscreen mode

Step 5: Set Up Cluster Networking
Choose a network plugin for your cluster. For example, Calico or Flannel. Install the chosen plugin on the master node:



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



Enter fullscreen mode Exit fullscreen mode

Step 6: Join Worker Nodes
run the kubeadm join command provided at the end of the master node initialization.



sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash <hash>



Enter fullscreen mode Exit fullscreen mode

Step 7: Verify Cluster Setup

On the master node, run:



kubectl get nodes
kubectl get pods --all-namespaces



Enter fullscreen mode Exit fullscreen mode

Step 8: Deploy an Application
Deploy a sample application to test your cluster:



kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort



Enter fullscreen mode Exit fullscreen mode

Step 9: Access Your Application
Retrieve the NodePort and access the deployed application:



kubectl get svc



Enter fullscreen mode Exit fullscreen mode

Visit http://node-ip:node-port in your web browser.

https://kubernetes.io/

Top comments (0)