Learn how to set up Kubernetes environments for development and production - from local clusters with minikube and kind to managed cloud services.
Setting up Kubernetes correctly is crucial for both development and production environments. This lesson covers various installation methods from lightweight local development options to production-grade cluster setups. You'll learn to choose the right approach based on your use case and set up your first Kubernetes cluster.
We'll explore minikube and kind for local development, understand managed Kubernetes services from major cloud providers, and introduce kubeadm for bare-metal production deployments.
There are multiple ways to run Kubernetes, each suited for different use cases:
Local Development:
Managed Services (Cloud):
Self-Managed Production:
Choosing the Right Option:
minikube is the most popular tool for running Kubernetes locally. It supports multiple drivers (Docker, VirtualBox, HyperV, etc.) and provides features like add-ons and multi-node clusters.
Key Features:
System Requirements:
Best Practices:
kind (Kubernetes IN Docker) creates Kubernetes clusters using Docker containers as nodes. It's extremely fast to start and ideal for CI/CD pipelines and local testing.
Advantages:
Use Cases:
Limitations:
kubectl is the command-line tool for interacting with Kubernetes clusters. Proper configuration is essential for managing multiple clusters and contexts.
Key Concepts:
Configuration Files:
Best Practices:
Cloud providers offer managed Kubernetes services that handle the control plane, making it easier to run production workloads.
Amazon EKS (Elastic Kubernetes Service):
Azure AKS (Azure Kubernetes Service):
Google GKE (Google Kubernetes Engine):
Considerations:
kubeadm is the official tool for creating production Kubernetes clusters. It handles the complex task of bootstrapping a cluster that meets Kubernetes conformance requirements.
Prerequisites:
Components to Install:
High Availability:
Let's set up a complete local Kubernetes development environment with minikube and configure it for development workflows.
1#!/bin/bash
2# Complete Development Cluster Setup
3# ===================================
4
5set -e
6
7echo "========================================"
8echo " Kubernetes Development Environment"
9echo "========================================"
10
11# Check prerequisites
12echo -e "
13[1/8] Checking prerequisites..."
14command -v docker >/dev/null 2>&1 || { echo "Docker required but not installed."; exit 1; }
15echo "✓ Docker is installed"
16
17# Install or check minikube
18echo -e "
19[2/8] Setting up minikube..."
20if ! command -v minikube &> /dev/null; then
21 echo "Installing minikube..."
22 if [[ "$OSTYPE" == "darwin"* ]]; then
23 brew install minikube
24 elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
25 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
26 sudo install minikube-linux-amd64 /usr/local/bin/minikube
27 rm minikube-linux-amd64
28 fi
29fi
30echo "✓ minikube is installed: $(minikube version --short)"
31
32# Check for existing cluster
33echo -e "
34[3/8] Checking cluster status..."
35if minikube status 2>/dev/null | grep -q "Running"; then
36 echo "Cluster already running"
37 read -p "Delete and recreate? (y/n) " -n 1 -r
38 echo
39 if [[ $REPLY =~ ^[Yy]$ ]]; then
40 minikube delete
41 fi
42fi
43
44# Start cluster with recommended settings
45echo -e "
46[4/8] Starting Kubernetes cluster..."
47minikube start --cpus 4 --memory 8192 --disk-size 30g --driver docker --kubernetes-version v1.28.0
48
49# Wait for cluster to be ready
50echo -e "
51[5/8] Waiting for cluster to be ready..."
52kubectl wait --for=condition=Ready nodes --all --timeout=120s
53
54# Enable essential add-ons
55echo -e "
56[6/8] Enabling add-ons..."
57minikube addons enable ingress
58minikube addons enable metrics-server
59minikube addons enable dashboard
60minikube addons enable registry
61
62echo "Enabled add-ons:"
63minikube addons list | grep enabled
64
65# Create development namespace
66echo -e "
67[7/8] Setting up development namespace..."
68kubectl create namespace development --dry-run=client -o yaml | kubectl apply -f -
69kubectl config set-context --current --namespace=development
70
71# Deploy a test application
72echo -e "
73[8/8] Deploying test application..."
74cat <<EOF | kubectl apply -f -
75apiVersion: apps/v1
76kind: Deployment
77metadata:
78 name: hello-dev
79 namespace: development
80spec:
81 replicas: 2
82 selector:
83 matchLabels:
84 app: hello-dev
85 template:
86 metadata:
87 labels:
88 app: hello-dev
89 spec:
90 containers:
91 - name: hello
92 image: paulbouwer/hello-kubernetes:1.10
93 ports:
94 - containerPort: 8080
95 resources:
96 requests:
97 memory: "64Mi"
98 cpu: "100m"
99 limits:
100 memory: "128Mi"
101 cpu: "200m"
102---
103apiVersion: v1
104kind: Service
105metadata:
106 name: hello-dev-svc
107 namespace: development
108spec:
109 type: NodePort
110 selector:
111 app: hello-dev
112 ports:
113 - port: 80
114 targetPort: 8080
115 nodePort: 30080
116EOF
117
118# Wait for deployment
119kubectl rollout status deployment/hello-dev -n development
120
121# Print summary
122echo -e "
123========================================"
124echo " Setup Complete!"
125echo "========================================"
126echo ""
127echo "Cluster Info:"
128kubectl cluster-info
129echo ""
130echo "Nodes:"
131kubectl get nodes -o wide
132echo ""
133echo "Test Application:"
134kubectl get pods,svc -n development
135echo ""
136echo "Access test app:"
137echo " URL: $(minikube service hello-dev-svc -n development --url)"
138echo ""
139echo "Useful commands:"
140echo " minikube dashboard # Open dashboard"
141echo " minikube tunnel # Enable LoadBalancer"
142echo " minikube ssh # SSH into node"
143echo " minikube stop # Stop cluster"
144echo " minikube delete # Delete cluster"
145echo ""
146echo "Happy developing!"Your progress is saved in this browser, on this device only.