Skip to content

Kubernetes_installation

Chapter 17: Kubernetes Installation - Setting Up Your Cluster

Section titled “Chapter 17: Kubernetes Installation - Setting Up Your Cluster”
  1. Introduction to Kubernetes Installation
  2. Installation Options
  3. Minikube
  4. Kind (Kubernetes in Docker)
  5. k3s - Lightweight Kubernetes
  6. Production Clusters
  7. kubectl Installation
  8. Verifying Your Installation
  9. Hands-on Lab
  10. Summary

Setting up Kubernetes can range from a simple single-node local cluster to a complex multi-node production environment. In this chapter, we’ll explore various installation methods and help you choose the right one for your needs.

┌─────────────────────────────────────────────────────────────────────────────┐
│ KUBERNETES INSTALLATION OPTIONS │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Local Development Production Clusters │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Minikube │ │ Managed K8s │ │
│ │ - Single node │ │ - EKS │ │
│ │ - VM-based │ │ - GKE │ │
│ │ - Easy setup │ │ - AKS │ │
│ └─────────────────┘ │ - DigitalOcean │ │
│ └─────────────────┘ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Kind │ │ Self-Managed │ │
│ │ - Docker-based│ │ - kubeadm │ │
│ │ - Fast │ │ - Kubespray │ │
│ │ - No VM │ │ - RKE │ │
│ └─────────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────────┐ │
│ │ k3s │ │
│ │ - Lightweight │ │
│ │ - Edge/IoT │ │
│ │ - Quick start│ │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ INSTALLATION OPTIONS COMPARISON │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Option │ Pros │ Cons │ Best For │
│ ─────────────┼───────────────────┼─────────────────┼───────────────── │
│ Minikube │ Full K8s features│ VM overhead │ Learning, dev │
│ Kind │ No VM, fast │ Docker required │ CI/CD, testing │
│ k3s │ Very lightweight │ Limited support │ Edge, IoT, dev │
│ kubeadm │ Production-ready │ Manual setup │ Self-hosted prod │
│ EKS/GKE/AKS │ Managed, scalable │ Cloud cost │ Production │
│ │
│ Requirements: │
│ ──────────── │
│ • Minikube: 2+ CPU, 2GB RAM, VirtualBox/Hypervisor │
│ • Kind: Docker, 2GB RAM │
│ • k3s: 512MB RAM (1GB recommended) │
│ • kubeadm: 2+ nodes, 2GB RAM each │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

Minikube is a tool that lets you run Kubernetes locally. It creates a single-node cluster inside a VM, providing a full Kubernetes experience for learning and development.

Terminal window
# Install Minikube on Linux
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# Install on macOS
brew install minikube
# Install on Windows
# Download from: https://github.com/kubernetes/minikube/releases
Terminal window
# Start with default settings
minikube start
# Specify VM driver
minikube start --driver=virtualbox
minikube start --driver=docker
minikube start --driver=hyperkit
# Specify Kubernetes version
minikube start --kubernetes-version=v1.28.0
# Allocate resources
minikube start --cpus=4 --memory=8192
# Use existing Kubernetes cluster
minikube start --driver=none
# Start with specific container runtime
minikube start --container-runtime=containerd
Terminal window
# Check status
minikube status
# Stop cluster
minikube stop
# Delete cluster
minikube delete
# SSH into node
minikube ssh
# Get IP address
minikube ip
# Access dashboard
minikube dashboard
# Addons management
minikube addons list
minikube addons enable ingress
minikube addons enable metrics-server
┌─────────────────────────────────────────────────────────────────────────────┐
│ MINIKUBE WITH DOCKER DRIVER │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Traditional (VM) Docker Driver │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Host │ │ Host │ │
│ │ │ │ │ │
│ │ ┌───────────┐ │ │ ┌───────────┐ │ │
│ │ │ VM │ │ │ │ Docker │ │ │
│ │ │ ┌───────┐ │ │ │ │ ┌───────┐ │ │ │
│ │ │ │ K8s │ │ │ │ │ │ K8s │ │ │ │
│ │ │ │ Node │ │ │ │ │ │ Node │ │ │ │
│ │ │ └───────┘ │ │ │ │ └───────┘ │ │ │
│ │ └───────────┘ │ │ └───────────┘ │ │
│ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Hypervisor │ │ Direct Docker │ │
│ │ (VirtualBox, │ │ Integration │ │
│ │ Hyper-V, etc)│ │ │ │
│ └─────────────────┘ └─────────────────┘ │
│ │
│ Benefits: │
│ • No VM required │
│ • Faster startup │
│ • Less resource overhead │
│ • Native Docker CLI integration │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

Kind creates Kubernetes clusters using Docker containers as nodes. It’s designed for testing Kubernetes itself and is excellent for CI/CD pipelines.

Terminal window
# Install Kind on Linux
curl -Lo kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x kind
sudo mv kind /usr/local/bin/
# Install on macOS
brew install kind
# Install on Windows
# Using Chocolatey
choco install kind
# Or using Go
go install sigs.k8s.io/kind@v0.20.0
Terminal window
# Create a simple cluster
kind create cluster
# Create with a specific name
kind create cluster --name my-cluster
# Create with a specific Kubernetes version
kind create cluster --image kindest/node:v1.28.0
# Create multi-node cluster
kind create cluster --config kind-config.yaml
kind-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
- role: worker
- role: worker
Terminal window
# Create cluster with config
kind create cluster --config kind-config.yaml
Terminal window
# List clusters
kind get clusters
# Delete cluster
kind delete cluster
kind delete cluster --name my-cluster
# Load image into cluster
kind load docker-image myapp:latest
# Export logs
kind export logs

k3s is a highly available, certified Kubernetes distribution designed for production workloads in resource-constrained environments. It’s a binary under 100MB that bundles everything needed.

Terminal window
# Install k3s (single node)
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" sh -
# Check status
kubectl get nodes
systemctl status k3s
# Get node token (for adding nodes)
cat /var/lib/rancher/k3s/server/node-token
Terminal window
# Quick start
curl -sfL https://get.k3s.io | sh -
# With specific version
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.28.0 sh -
# Access kubectl
kubectl get nodes
sudo kubectl get nodes
Terminal window
# First server node
curl -sfL https://get.k3s.io | \
INSTALL_K3S_EXEC="server --cluster-init" \
K3S_TOKEN=<node-token> sh -
# Additional server nodes
curl -sfL https://get.k3s.io | \
INSTALL_K3S_EXEC="server --server https://<server-ip>:6443" \
K3S_TOKEN=<node-token> sh -
# Worker nodes
curl -sfL https://get.k3s.io | \
INSTALL_K3S_EXEC="agent" \
K3S_URL=https://<server-ip>:6443 \
K3S_TOKEN=<node-token> sh -
┌─────────────────────────────────────────────────────────────────────────────┐
│ K3S vs STANDARD KUBERNETES │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Feature │ Standard K8s │ k3s │
│ ──────────────────┼────────────────────┼────────────── │
│ Size │ ~600MB+ │ ~100MB │
│ Installation │ Complex (kubeadm) │ Simple script │
│ Dependencies │ Many │ Bundled │
│ Database │ etcd (external) │ SQLite (embedded) │
│ Memory Usage │ High │ Low (~500MB) │
│ Supported addons│ All │ Most (traefik, servicelb) │
│ │
│ What's removed in k3s: │
│ • Legacy auth mechanisms │
│ • In-tree cloud providers (can be added) │
│ • Some alpha features │
│ │
│ What's added in k3s: │
│ • Built-in ingress controller (Traefik) │
│ • Built-in service load balancer (Servicelb) │
│ • Built-in local storage provider │
│ • Simplified containerd setup │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ MANAGED KUBERNETES SERVICES │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │
│ │ EKS │ │ GKE │ │ AKS │ │
│ │ (AWS) │ │ (GCP) │ │ (Azure) │ │
│ │ │ │ │ │ │ │
│ │ • Fargate │ │ • Autopilot │ │ • Virtual │ │
│ │ • Self-managed│ │ • Standard │ │ Nodes │ │
│ │ • EKS Anywhere│ │ • GKE Hub │ │ • Azure CNI │ │
│ └────────────────┘ └────────────────┘ └────────────────┘ │
│ │
│ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │
│ │ DO Kubernetes│ │ Linode LKE │ │ OKE │ │
│ │ (DigitalOcean)│ │ (Akamai) │ │ (Oracle) │ │
│ └────────────────┘ └────────────────┘ └────────────────┘ │
│ │
│ Benefits of Managed Services: │
│ • Automatic upgrades │
│ • High availability │
│ • Integrated load balancing │
│ • Security and compliance │
│ • Monitoring and logging │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
Terminal window
# Install eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin/
# Create cluster
eksctl create cluster \
--name my-cluster \
--region us-west-2 \
--nodegroup-name standard-workers \
--node-type t3.medium \
--nodes 3
# Create with config file
eksctl create cluster -f cluster-config.yaml
cluster-config.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: my-cluster
region: us-west-2
nodeGroups:
- name: standard-workers
instanceType: t3.medium
desiredCapacity: 3
minSize: 2
maxSize: 5
Terminal window
# Install prerequisites
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
# Add Kubernetes repository
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
# Install components
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
# Initialize master
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
# Setup kubectl
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# Install CNI (Calico example)
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Terminal window
# Linux
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
# macOS
brew install kubectl
# Verify installation
kubectl version --client
Terminal window
# Get cluster credentials
aws eks update-kubeconfig --name my-cluster
# Or manually configure
kubectl config set-cluster my-cluster \
--server=https://<endpoint> \
--certificate-authority=/path/to/ca.crt
kubectl config set-credentials admin \
--token=<bearer-token>
kubectl config use-context my-cluster
Terminal window
# Bash
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
# Zsh
source <(kubectl completion zsh)
echo "source <(kubectl completion zsh)" >> ~/.zshrc

Terminal window
# Get cluster info
kubectl cluster-info
# Get nodes
kubectl get nodes
# Get component statuses
kubectl get componentstatuses
# or (deprecated in v1.19+)
kubectl get --raw='/apis/healthz.kubernetes.io/v1/healthz'
# Describe node
kubectl describe node <node-name>
# Get all namespaces
kubectl get ns
Terminal window
# Run a test pod
kubectl run nginx --image=nginx --port=80
# Check pod status
kubectl get pods
# Get pod details
kubectl describe pod nginx
# Delete test pod
kubectl delete pod nginx
┌─────────────────────────────────────────────────────────────────────────────┐
│ COMMON INSTALLATION ISSUES │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Issue: "The connection to the server localhost:8080 was refused" │
│ Solution: │
│ • Ensure kubectl is configured: cat ~/.kube/config │
│ • For minikube: minikube start │
│ • For kind: kind get kubeconfig │
│ │
│ Issue: "Node NotReady" │
│ Solution: │
│ • Check CNI installation: kubectl get pods -n kube-system │
│ • Check kubelet logs: journalctl -u kubelet │
│ │
│ Issue: "ImagePullBackOff" │
│ Solution: │
│ • Check image name is correct │
│ • For private registry: Create image pull secret │
│ │
│ Issue: "No nodes available to schedule pods" │
│ Solution: │
│ • Check node status: kubectl get nodes │
│ • Check resources: kubectl describe node <node> │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

Lab: Setting Up Local Kubernetes with Minikube

Section titled “Lab: Setting Up Local Kubernetes with Minikube”

In this hands-on lab, we’ll set up a local Kubernetes cluster using Minikube.

  • Docker installed
  • VirtualBox or another hypervisor
  • 4GB RAM available
Terminal window
# Step 1: Install Minikube
# Linux
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# Step 2: Install kubectl
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
# Step 3: Start Minikube with Docker driver
minikube start --driver=docker --cpus=2 --memory=4096
# Step 4: Verify installation
kubectl cluster-info
kubectl get nodes
# Step 5: Enable addons
minikube addons enable ingress
minikube addons enable metrics-server
minikube addons list
# Step 6: Deploy a test application
kubectl create deployment nginx --image=nginx
kubectl get pods -w
# Step 7: Expose the deployment
kubectl expose deployment nginx --port=80 --type=NodePort
# Step 8: Access the service
minikube service nginx
# Step 9: Check dashboard
minikube dashboard
# Step 10: Clean up
minikube delete

  1. Choose the right tool - Minikube for dev, Kind for CI/CD, k3s for edge
  2. kubectl is essential - Install and configure it for all clusters
  3. Managed services - EKS/GKE/AKS for production
  4. Verify installation - Check nodes, pods, and component status
Terminal window
# Minikube
minikube start
minikube stop
minikube delete
# Kind
kind create cluster
kind get clusters
kind delete cluster
# k3s
curl -sfL https://get.k3s.io | sh -
kubectl get nodes
# kubectl
kubectl cluster-info
kubectl get nodes
kubectl get pods -A

In the next chapter, we’ll explore Kubernetes ReplicaSets (Chapter 19), covering:

  • ReplicaSet concepts
  • Scaling applications
  • Managing replicas