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:
-
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.
- On Linux/Mac:
-
Start a Cluster
- Run:
minikube start
- This will create a single-node Kubernetes cluster locally.
- Run:
-
Access the Dashboard
- Launch the Kubernetes Dashboard:
minikube dashboard
- Launch the Kubernetes Dashboard:
-
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
- Example:
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:
-
Install Kind
- Run:
GO111MODULE=on go install sigs.k8s.io/kind@latest
- Run:
-
Create a Cluster
- Run:
kind create cluster
- This creates a Kubernetes cluster inside Docker containers.
- Run:
-
Interact with the Cluster
- Use
kubectl
to manage the cluster:kubectl get nodes
- Use
Setting Up Kubernetes on Cloud
1. Google Kubernetes Engine (GKE)
Prerequisites:
- Google Cloud account.
- Install Google Cloud SDK and authenticate:
gcloud auth login
.
Steps:
-
Enable GKE API
- Run:
gcloud services enable container.googleapis.com
- Run:
-
Create a Cluster
- Run:
gcloud container clusters create my-cluster --num-nodes=3
- Run:
-
Connect to the Cluster
- Run:
gcloud container clusters get-credentials my-cluster
- Run:
-
Deploy an Application
- Example:
kubectl create deployment my-app --image=nginx
- Example:
2. Amazon Elastic Kubernetes Service (EKS)
Prerequisites:
- AWS account.
- Install AWS CLI and eksctl.
Steps:
-
Create a Cluster
- Run:
eksctl create cluster --name=my-cluster --region=us-west-2
- Run:
-
Verify the Cluster
- Run:
kubectl get nodes
- Run:
-
Deploy an Application
- Example:
kubectl create deployment my-app --image=nginx
- Example:
3. Azure Kubernetes Service (AKS)
Prerequisites:
- Azure account.
- Install Azure CLI.
Steps:
-
Create a Resource Group
- Run:
az group create --name myResourceGroup --location eastus
- Run:
-
Create a Cluster
- Run:
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys
- Run:
-
Connect to the Cluster
- Run:
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
- Run:
-
Deploy an Application
- Example:
kubectl create deployment my-app --image=nginx
- Example:
Tools for Managing Kubernetes Clusters
- kubectl: The Kubernetes CLI for managing clusters.
- Lens: A popular GUI for Kubernetes management.
- 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