k3d is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker.
Installation
brew install k3d
Create a cluster named k3d with just a single server node:
k3d cluster create k3d
# Creating multi-server clusters
k3d cluster create k3d --servers 2
# Adding server nodes to a running cluster¶
# In theory (and also in practice in most cases), this is as easy as executing the following command:
k3d node create newserver --cluster multiserver --role server
kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3d-k3d-server-1 Ready master 3m8s v1.18.16+k3s1
k3d-k3d-server-0 Ready master 3m25s v1.18.16+k3s1
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1aa78d2f128 rancher/k3d-proxy:v4.3.0 "/bin/sh -c nginx-pr…" 4 minutes ago Up 3 minutes 80/tcp, 0.0.0.0:55194->6443/tcp k3d-k3d-serverlb
0d83b5d6b2a0 rancher/k3s:latest "/bin/k3s server --t…" 4 minutes ago Up 3 minutes k3d-k3d-server-1
19e59f345d6b rancher/k3s:latest "/bin/k3s server --c…" 4 minutes ago Up 3 minutes k3d-k3d-server-0
Get the new cluster’s connection details merged into your default kubeconfig (usually specified using the KUBECONFIG environment variable or the default path $HOME/.kube/config) and directly switch to the new context:
k3d kubeconfig merge k3d --kubeconfig-switch-context