Quick Kubernetes Cluster Setup in less than 10 Minutes
tl;dr
- Install Docker: Run
brew install docker
and start Docker. - Install kind: Execute
brew install kind
. - Install kubectl: Use
brew install kubectl
. - Create a Kubernetes cluster:
kind create cluster
. - Experiment with Kubernetes.
- Delete the cluster:
kind delete cluster
when done.
Introduction
This guide provides a fast method for setting up a local, miniature Kubernetes (k8s) cluster, primarily for testing or learning purposes. This is not an exhaustive tutorial on Kubernetes.
Previously, I utilized Minikube for quick Kubernetes testing, but have since shifted to Kind.
What is Kind?
kind is a tool for running local Kubernetes clusters using Docker container "nodes".
Reasons for preferring Kind over Minikube:
- Architecture: Kind operates differently from Minikube. While Kind creates Kubernetes clusters inside Docker containers, Minikube establishes a single-node Kubernetes cluster on a local machine.
- Deployment: Kind is designed for local development and testing, enabling rapid setup of multiple clusters. Minikube, in contrast, offers a more comprehensive Kubernetes experience for local development, including features like load balancing, secrets, and persistent volumes.
While kind
does not require kubectl
, having it installed is beneficial for following certain examples. For kubectl
installation, refer to the official kubectl installation documentation.
Installation Requirements (using Homebrew):
- Docker:
brew install docker
- kubectl:
brew install kubectl
- kind:
brew install kind
- Start a Kubernetes cluster:
kind create cluster
Creating 4 Pods
Creating a Resource from a YAML File
kubectl apply -f deployment.yaml
where deployment.yaml
contains:
apiVersion: apps/v1
kind: Deployment
metadata:
name: www
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
replicas: 4
minReadySeconds: 4
selector:
matchLabels:
app: www
template:
metadata:
labels:
app: www
spec:
terminationGracePeriodSeconds: 2
containers:
- name: image1
image: erkules/nginxhostname:v1
Verifying Pod Creation
Execute the following command to ensure the pods have been created successfully:
kubectl get pods
You should see output similar to:
NAME READY STATUS RESTARTS AGE
www 1/1 Running 0 10m
www-65b4c66678-kwk8x 1/1 Running 0 11m
www-65b4c66678-l6bzf 1/1 Running 0 11m
www-65b4c66678-nbb9s 1/1 Running 0 11m
www-65b4c66678-qg2qn 1/1 Running 0 11m
This quick setup guide should help you get a Kubernetes cluster up and running in no time, perfect for learning and experimentation.
Sources
- kind
- Install and Set Up kubectl on macOS | Kubernetes
- Kind vs minikube | What are the differences?
- The Essential Kubectl Commands: Handy Cheat Sheet
Dimitri Missoh | 2024-01-22