Skip to content

KinD cluster setup with MetalLB

This setup procedure configures a Kubernetes-in-Docker (KinD) cluster integrated with MetalLB to provide external load balancing capabilities.^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]

Prerequisites

Deploying the cluster requires a Linux environment and the installation of three specific command-line tools:

  1. kubectl
  2. kind
  3. docker^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]

The configuration is designed specifically for Linux; attempting to run the setup script on other operating systems will result in an error message.^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]

IP Allocation

MetalLB relies on the Docker network subnet created by KinD to assign public IP addresses.^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]

The IP allocation logic is split across four octets: * 1st & 2nd Octets: Determined automatically by the Docker network. * 3rd Octet: Configurable via the ip-octet parameter (default: 255). * 4th Octet: Hardcoded to the range 200–240.^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]

Consequently, a single cluster supports a maximum of 40 public IPv4 addresses.^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]

Cluster Configuration

The setup script ./setupkind.sh accepts the following arguments to customize the deployment^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]:

  • --cluster-name / -n: Specifies the name of the cluster (defaults to cluster1).
  • --k8s-release / -r: Defines the Kubernetes version to install (defaults to the latest available release).
  • --ip-octet / -s: Sets the 3rd octet for public IP addresses (valid range: 100–255).

Multi-Cluster Deployment

When provisioning multiple clusters, it is critical to assign a unique ip-octet to each instance to prevent address overlapping^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md].

Example Deployment:

# Create the first cluster using IP range x.x.255.200-240
./setupkind.sh --cluster-name cluster1 --ip-octet 255

# Create a second cluster using IP range x.x.245.200-240
./setupkind.sh --cluster-name cluster2 --ip-octet 245
^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]

Sources

^[400-devops__07-Monitoring-and-Observability__k8s-istio__samples__kind-lb__README.md]