Kubernetes Cluster Step By Step

Kubernetes Cluster Step By Step


A Kubernetes cluster is a set of nodes used to run containerized applications managed by Kubernetes. It ensures that applications are deployed and running as expected, while providing features like scaling, load balancing, and self-healing

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

        

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

        

Step 4: Initialize the Master Node

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

        

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

        

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>

        

Step 7: Verify Cluster Setup

On the master node, run:

kubectl get nodes
kubectl get pods --all-namespaces

        

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

        

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

kubectl get svc

        

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

To view or add a comment, sign in

Others also viewed

Explore topics