Ashish Singh

How to Set Up Kubernetes Locally and on the Cloud: Step-by-Step Guide

Setting Up Kubernetes Locally and on the Cloud


Introduction

Setting up Kubernetes is the first step toward mastering container orchestration. This guide walks you through setting up Kubernetes both locally (using Minikube or Kind) and on a cloud platform (GKE, EKS, or AKS).


Setting Up Kubernetes Locally

1. Using Minikube

Minikube is a lightweight tool for running Kubernetes clusters locally.

Prerequisites:

  • Install a hypervisor like VirtualBox or Docker.
  • Install Minikube and kubectl (Kubernetes CLI).

Steps:

  1. Install Minikube

    • On Linux/Mac: curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && sudo install minikube-linux-amd64 /usr/local/bin/minikube
    • On Windows: Use the installer available at Minikube’s website.
  2. Start a Cluster

    • Run: minikube start
    • This will create a single-node Kubernetes cluster locally.
  3. Access the Dashboard

    • Launch the Kubernetes Dashboard: minikube dashboard
  4. Deploy an Application

    • Example: kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
    • Expose the deployment: kubectl expose deployment hello-minikube --type=NodePort --port=8080

2. Using Kind (Kubernetes in Docker)

Kind runs Kubernetes clusters in Docker containers, making it ideal for testing and CI/CD pipelines.

Prerequisites:

  • Install Docker.
  • Install Kind.

Steps:

  1. Install Kind

    • Run: GO111MODULE=on go install sigs.k8s.io/kind@latest
  2. Create a Cluster

    • Run: kind create cluster
    • This creates a Kubernetes cluster inside Docker containers.
  3. Interact with the Cluster

    • Use kubectl to manage the cluster: kubectl get nodes

Setting Up Kubernetes on Cloud

1. Google Kubernetes Engine (GKE)

Prerequisites:

  • Google Cloud account.
  • Install Google Cloud SDK and authenticate: gcloud auth login.

Steps:

  1. Enable GKE API

    • Run: gcloud services enable container.googleapis.com
  2. Create a Cluster

    • Run: gcloud container clusters create my-cluster --num-nodes=3
  3. Connect to the Cluster

    • Run: gcloud container clusters get-credentials my-cluster
  4. Deploy an Application

    • Example: kubectl create deployment my-app --image=nginx

2. Amazon Elastic Kubernetes Service (EKS)

Prerequisites:

  • AWS account.
  • Install AWS CLI and eksctl.

Steps:

  1. Create a Cluster

    • Run: eksctl create cluster --name=my-cluster --region=us-west-2
  2. Verify the Cluster

    • Run: kubectl get nodes
  3. Deploy an Application

    • Example: kubectl create deployment my-app --image=nginx

3. Azure Kubernetes Service (AKS)

Prerequisites:

  • Azure account.
  • Install Azure CLI.

Steps:

  1. Create a Resource Group

    • Run: az group create --name myResourceGroup --location eastus
  2. Create a Cluster

    • Run: az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys
  3. Connect to the Cluster

    • Run: az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
  4. Deploy an Application

    • Example: kubectl create deployment my-app --image=nginx

Tools for Managing Kubernetes Clusters

  1. kubectl: The Kubernetes CLI for managing clusters.
  2. Lens: A popular GUI for Kubernetes management.
  3. Helm: A package manager for deploying applications.

Conclusion

Setting up Kubernetes locally or on the cloud gives you hands-on experience to understand its core concepts. Choose the environment that aligns with your goals and resources.

Next Steps

In the next lesson, we’ll explore the core concepts of Kubernetes, including Pods, Deployments, and Services.

Engagement

  • Share your setup experience in the comments!
  • Like and subscribe for more hands-on Kubernetes tutorials.
  • Visit Github Repo

About the Instructor

Ashish Singh specializes in backend development, DevOps, and cloud technologies. Stay tuned for practical, in-depth tutorials to elevate your skills!

Follow me on Social Media