G
GuideDevOps
Lesson 3 of 17

Installing Kubernetes

Part of the Kubernetes tutorial series.

Local Setup (for Learning)

When learning Kubernetes, you don't need a massive cloud account. A lightweight local cluster is perfect.

Option 1: Minikube (Most Popular)

Minikube runs a single-node Kubernetes cluster inside a hypervisor on your local machine.

Installation (macOS with Homebrew):

brew install minikube
minikube start

Installation (Windows):

# Using Chocolatey
choco install minikube
minikube start

Installation (Linux):

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start

Verify it's working:

kubectl cluster-info
kubectl get nodes

Useful Commands:

minikube start              # Start the cluster
minikube stop               # Stop the cluster (saves resources)
minikube delete             # Delete the cluster entirely
minikube status             # Check cluster status
minikube logs               # View cluster logs
minikube dash board         # Open the Kubernetes dashboard
minikube addons list        # View available add-ons
minikube addons enable metrics-server  # Enable metrics (for HPA)

Pros:

  • Simple to install and remove
  • Full Kubernetes functionality
  • Good for learning and development
  • Works on Mac, Windows, and Linux

Cons:

  • Single node (not multi-node like production)
  • Can be slow (emulates a full cluster)
  • Limited resources compared to real clusters

Option 2: Kind (Kubernetes in Docker)

Kind runs Kubernetes nodes as Docker containers. It's faster than Minikube and more suitable for CI/CD.

Installation:

# Download the latest binary
curl -L https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 -o kind
chmod +x kind
sudo mv kind /usr/local/bin/
 
# Or use Homebrew on macOS
brew install kind

Create a cluster:

kind create cluster
kind get clusters
kubectl cluster-info

Multi-node cluster:

# Create a file: kind-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker

Then:

kind create cluster --config kind-config.yaml

Useful Commands:

kind create cluster --name my-cluster     # Create cluster with custom name
kind get clusters                         # List clusters
kind delete cluster --name my-cluster     # Delete cluster
kind load docker-image my-image:latest    # Load local Docker image into cluster

Pros:

  • Fast startup and teardown
  • Can create multi-node clusters
  • Perfect for CI/CD
  • Lower resource overhead than Minikube

Cons:

  • Requires Docker to be installed
  • Less feature-complete (no metrics server by default)

Option 3: Docker Desktop

Docker Desktop includes Kubernetes if you enable it.

Setup:

  1. Install Docker Desktop
  2. Go to Settings → Kubernetes
  3. Check "Enable Kubernetes"
  4. Click "Apply & Restart"

Verify:

kubectl cluster-info
docker ps  # You'll see Kubernetes containers

Pros:

  • Minimal setup (already have Docker)
  • Integrated in your development workflow

Cons:

  • Needs more resources from Docker Desktop
  • Single node cluster
  • Updates tied to Docker Desktop version

Installing kubectl

kubectl is the command-line interface to Kubernetes. You need it to interact with any cluster.

macOS:

brew install kubectl
# or
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Windows:

choco install kubernetes-cli
# or download from: https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/

Linux:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Verify:

kubectl version
kubectl cluster-info

Cloud-Based Kubernetes (Managed Services)

In production, you don't want to manage the Control Plane yourself. Cloud providers offer managed Kubernetes:

AWS EKS (Elastic Kubernetes Service)

Setup:

# Install AWS CLI and eksctl
brew install awscli eksctl
 
# Create a cluster
eksctl create cluster \
  --name production-cluster \
  --version 1.27 \
  --region us-east-1 \
  --nodegroup-name standard-workers \
  --node-type t3.medium \
  --nodes 3

Costs:

  • Control plane: $0.10-0.15/hour
  • Worker nodes: Standard EC2 pricing
  • Data transfer: Standard AWS pricing

Google GKE (Google Kubernetes Engine)

Setup:

# Install gcloud CLI and kubectl
curl https://sdk.cloud.google.com | bash
 
# Initialize
gcloud init
 
# Create a cluster
gcloud container clusters create production-cluster \
  --zone us-central1-a \
  --num-nodes 3 \
  --machine-type n1-standard-1

Azure AKS (Azure Kubernetes Service)

Setup:

# Install Azure CLI
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
 
# Login
az login
 
# Create a cluster
az aks create \
  --resource-group myResourceGroup \
  --name production-cluster \
  --node-count 3 \
  --vm-set-type VirtualMachineScaleSets

Cluster Configuration

kubeconfig File

Your local machine needs to know how to connect to Kubernetes clusters. This information is stored in ~/.kube/config.

View your config:

cat ~/.kube/config

Structure:

apiVersion: v1
kind: Config
clusters:
- cluster:
    certificate-authority-data: LS0t...   # CA certificate
    server: https://127.0.0.1:6443        # API server address
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
users:
- name: minikube
  user:
    client-certificate-data: LS0t...
    client-key-data: LS0t...

Useful Commands:

kubectl config view                    # View config
kubectl config get-clusters            # List clusters
kubectl config get-contexts            # List contexts
kubectl config use-context minikube    # Switch cluster
kubectl config current-context         # Show current cluster

Verifying Your Installation

Step 1: Check Cluster Info

kubectl cluster-info

Expected output:

Kubernetes control plane is running at https://127.0.0.1:6443
CoreDNS is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

Step 2: Check Nodes

kubectl get nodes

Expected output (Minikube):

NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   5m    v1.27.0

Step 3: Check System Pods

kubectl get pods --namespace kube-system

Expected output:

NAME                               READY   STATUS    RESTARTS   AGE
coredns-5d78c0869f-9qhxm          1/1     Running   0          5m
etcd-minikube                      1/1     Running   0          5m
kube-apiserver-minikube            1/1     Running   0          5m
kube-controller-manager-minikube   1/1     Running   0          5m
kube-proxy-gkn2v                   1/1     Running   0          5m
kube-scheduler-minikube            1/1     Running   0          5m

Step 4: Deploy a Test Pod

kubectl run test-pod --image=nginx:latest
kubectl get pods
kubectl port-forward pod/test-pod 8080:80
# Visit http://localhost:8080 in your browser
kubectl delete pod test-pod

Cleanup

Remove Minikube

minikube delete

Remove Kind Cluster

kind delete cluster

Remove Docker Desktop Kubernetes

Go to Settings → Kubernetes and uncheck "Enable Kubernetes"


Troubleshooting Installation

Problem: kubectl command not found

Solution: Ensure /usr/local/bin is in your PATH

echo $PATH

Problem: Unable to connect to the server: dial tcp 127.0.0.1:6443: connect: connection refused

Solution: Start the cluster

minikube start
# or for Kind:
docker ps  # Ensure Docker is running

Problem: Not enough disk space

Solution: Minikube needs ~20GB. Clean up Docker

docker system prune -a

Problem: Docker daemon not running (on macOS/Windows)

Solution: Start Docker Desktop application