GitHub EN PT

K8s by Example: Local Cluster

You need a cluster to run Kubernetes. For local development, kind (Kubernetes in Docker) is the fastest way to get started. It runs a cluster inside Docker containers.

terminal

Install kind using your package manager. On macOS use Homebrew, on Linux download the binary directly.

# macOS
$ brew install kind

# 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/kind
terminal

Create a cluster. This pulls the node image and starts a container. Takes about 30 seconds.

$ kind create cluster
Creating cluster "kind" ...
 Ensuring node image (kindest/node:v1.31.0)
 Preparing nodes
 Writing configuration
 Starting control-plane
 Installing CNI
 Installing StorageClass
Set kubectl context to "kind-kind"
terminal

Verify the cluster is running. kind automatically configures kubectl to connect to your new cluster.

$ kubectl cluster-info
Kubernetes control plane is running at https://127.0.0.1:6443
CoreDNS is running at https://127.0.0.1:6443/api/v1/...
terminal

List nodes in the cluster. A basic kind cluster has one node that acts as both control plane and worker.

$ kubectl get nodes
NAME                 STATUS   ROLES           AGE   VERSION
kind-control-plane   Ready    control-plane   45s   v1.31.0
multi-node.yaml

For a more realistic setup, create a multi-node cluster. This config creates one control plane and two workers.

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: worker
  - role: worker

Pass the config file when creating the cluster.

$ kind create cluster --config multi-node.yaml
$ kubectl get nodes
NAME                 STATUS   ROLES           AGE   VERSION
kind-control-plane   Ready    control-plane   60s   v1.31.0
kind-worker          Ready    <none>          30s   v1.31.0
kind-worker2         Ready    <none>          30s   v1.31.0
terminal

Delete the cluster when you’re done. This removes all containers and frees up resources.

$ kind delete cluster
Deleting cluster "kind" ...
Deleted nodes: ["kind-control-plane"]
terminal

Other options: minikube (more features, slower), k3s (lightweight, good for edge), or Docker Desktop (enable in settings).

# minikube
$ minikube start

# k3s (Linux only)
$ curl -sfL https://get.k3s.io | sh -

# Docker Desktop: Settings → Kubernetes → Enable

Index | Use arrow keys to navigate