Skip to content

K3D Cluster Setup Script

This script automates the creation of a K3D cluster with customizable options, such as Docker network CIDR, service network CIDR, private registry setup, and load balancer port configuration. It generates a k3d-cluster-config.yaml file and creates a cluster based on the configuration.


🚀 Features

  • Automatically installs the latest K3D version.
  • Generates a custom K3D cluster configuration file (k3d-cluster-config.yaml).
  • Supports local Docker registry creation.
  • Configurable network and service CIDRs.
  • Customizable K3D load balancer port.
  • Automatically switches kubectl to the new cluster context.

📝 Usage

Run the script with the following options to configure and create the K3D cluster:

Script Options

Option Description Default
-h, --help Show the help message and exit.
--docker-network-cidr Specify the Docker network CIDR (e.g., 192.168.1.0/24). None
--service-network-cidr Specify the service network CIDR (e.g., 10.43.0.0/16). None
--k3d-loadbalancer-port Set the K3D load balancer port. 8081
--override Override the existing K3D configuration file (k3d-cluster-config.yaml), if not and already exists, will use the existing configuration.

📋 Example: Default Cluster Creation

./set-up-k3d.sh