Last active
March 16, 2025 22:43
-
-
Save ams0/d21f0d1967b59f6b5d6f083186b74c54 to your computer and use it in GitHub Desktop.
Create a Kind cluster with Cilium as LoadBalancer service provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Default values | |
DEFAULTK8SVERSION="v1.32.2" | |
DEFAULTNAME="kind" | |
CILIUM_VERSION="1.17.0" | |
DEFAULTIMAGE="kindest/node" | |
# Initialize variables with default values | |
K8SVERSION=$DEFAULTK8SVERSION | |
NAME=$DEFAULTNAME | |
IMAGE=$DEFAULTIMAGE | |
PRELOAD=$DEFAULTPRELOAD | |
GWAPI_VERSION="v1.2.0" | |
# Function to display usage | |
usage() { | |
echo "Usage: $0 [-k <k8s_version, v1.30.0>] [-n <cluster_name, kind>] [-i <image repo>] [-h <hostpath to be mounted on nodes>]" | |
exit 1 | |
} | |
# Parse command-line options | |
while getopts "k:n:i:h:p:c:m:" opt; do | |
case ${opt} in | |
k ) K8SVERSION=${OPTARG} ;; | |
n ) NAME=${OPTARG} ;; | |
i ) IMAGE=${OPTARG} ;; | |
\? ) usage ;; | |
esac | |
done | |
# NODE_CONFIG=$(cat <<EOF | |
# - role: control-plane | |
# kubeadmConfigPatches: | |
# - | | |
# kind: InitConfiguration | |
# nodeRegistration: | |
# kubeletExtraArgs: | |
# node-labels: "ingress-ready=true" | |
# extraPortMappings: | |
# - containerPort: 80 | |
# hostPort: 8080 | |
# protocol: TCP | |
# - containerPort: 443 | |
# hostPort: 6443 | |
# protocol: TCP | |
# - role: worker | |
# - role: worker | |
# - role: worker | |
# EOF | |
# ) | |
# Create the cluster | |
kind create cluster --name ${NAME} --image kindest/node:${K8SVERSION} --config - <<EOF | |
kind: Cluster | |
apiVersion: kind.x-k8s.io/v1alpha4 | |
networking: | |
disableDefaultCNI: true | |
kubeProxyMode: none | |
nodes: | |
- role: control-plane | |
- role: worker | |
EOF | |
echo "Cluster ${NAME} created with Kubernetes version ${K8SVERSION}" | |
echo "Initializing Cilium with version ${CILIUM_VERSION}..." | |
cilium install --version ${CILIUM_VERSION} \ | |
--set kubeProxyReplacement="true" \ | |
--set routingMode="native" \ | |
--set ipv4NativeRoutingCIDR="10.244.0.0/16" \ | |
--set k8sServiceHost="${NAME}-control-plane" \ | |
--set k8sServicePort=6443 \ | |
--set l2announcements.enabled=true \ | |
--set l2announcements.leaseDuration="3s" \ | |
--set l2announcements.leaseRenewDeadline="1s" \ | |
--set l2announcements.leaseRetryPeriod="500ms" \ | |
--set devices="{eth0,net0}" \ | |
--set externalIPs.enabled=true \ | |
--set autoDirectNodeRoutes=true \ | |
--set operator.replicas=2 | |
kubectl wait po -n kube-system --timeout=600s -l k8s-app=cilium -l app.kubernetes.io/name=cilium-agent --for condition=Ready | |
# helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/ | |
# helm repo update | |
helm upgrade --install --set args={--kubelet-insecure-tls} metrics-server --repo https://kubernetes-sigs.github.io/metrics-server/ metrics-server --namespace kube-system | |
# Install the Gateway API CRDs | |
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/${GWAPI_VERSION}/experimental-install.yaml | |
kubectl apply -f - <<EOF | |
apiVersion: "cilium.io/v2alpha1" | |
kind: CiliumLoadBalancerIPPool | |
metadata: | |
name: "lb-pool-1" | |
spec: | |
blocks: | |
- cidr: "172.18.250.0/24" | |
--- | |
apiVersion: "cilium.io/v2alpha1" | |
kind: CiliumL2AnnouncementPolicy | |
metadata: | |
name: announcement-policy | |
spec: | |
externalIPs: false | |
loadBalancerIPs: true | |
interfaces: | |
- ^eth[0-9]+ | |
nodeSelector: | |
matchExpressions: | |
- key: node-role.kubernetes.io/control-plane | |
operator: DoesNotExist | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment