Setting up K8s Local Cluster
Utilizing Docker Containers for k8s cluster creation
k3d uses the k3s docker image to setup the cluster, so this will run a docker container to setup the kubernetes node, which is not recommended for the production use.
- Install k3d
- Create Cluster
Clear execution steps and output are updated in the gist.
Install k3d
I am using mac, here is what I did brew install k3d, follow the official docs for instalaltion of k3d other environments
Create Cluster
Single node cluster
- Create
k3d cluster create myclusterandk3d cluster list - Validate nodes
kubectl get nodes - Delete Cluster
k3d cluster delete mycluster
Multi Node cluster
- Create
k3d cluster create mycluster --agents 2 --servers 1andk3d cluster list - Validate nodes
kubectl get nodes - Delete Cluster
k3d cluster delete mycluster
Multi Node cluster with Config
Create the cluster config file k3d-cluster.yml
apiVersion: k3d.io/v1alpha4
kind: Simple
metadata:
name: dev
servers: 1
agents: 2
image: docker.io/rancher/k3s:v1.30.3-k3s1
ports:
- port: 30000-30100:30000-30100
nodeFilters:
- server:*
registries:
create:
name: dev
host: 0.0.0.0
hostPort: "5000"
options:
k3s:
extraArgs:
- arg: --disable=traefik
nodeFilters:
- server:*- Create
k3d cluster create --config k3d-cluster.ymlandk3d cluster list - Validate nodes
kubectl get nodes - Delete Cluster
k3d cluster delete mycluster
We now able to execute the k3d commands and setup the cluster, use it for the k8s local cluster practice.
