From e7fd978b892a61bfa4c3f334c9f694c24ac6baa3 Mon Sep 17 00:00:00 2001 From: payneio Date: Tue, 3 Jun 2025 23:32:41 -0700 Subject: [PATCH] Updates MetalLB to install with kustomize instea of ks default. --- docs/SETUP.md | 2 +- .../metallb/configuration/kustomization.yaml | 18 ++++++++++++++++ .../pool.yaml} | 8 +++---- .../metallb/installation/kustomization.yaml | 3 +++ .../metallb/metallb-helm-config.yaml | 12 ----------- .../metallb/metallb-pool.yaml | 21 ------------------- infrastructure_setup/setup-metallb.sh | 18 ++++++---------- 7 files changed, 31 insertions(+), 51 deletions(-) create mode 100644 infrastructure_setup/metallb/configuration/kustomization.yaml rename infrastructure_setup/metallb/{metallb-config.yaml => configuration/pool.yaml} (62%) create mode 100644 infrastructure_setup/metallb/installation/kustomization.yaml delete mode 100644 infrastructure_setup/metallb/metallb-helm-config.yaml delete mode 100644 infrastructure_setup/metallb/metallb-pool.yaml diff --git a/docs/SETUP.md b/docs/SETUP.md index bb9c15f..a2d16d1 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -40,7 +40,7 @@ K3s provides a fully-compliant Kubernetes distribution in a small footprint: ```bash # Install K3s without the default load balancer (we'll use MetalLB) -curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode=644 --disable servicelb +curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode=644 --disable servicelb --disable metallb # Set up kubectl configuration mkdir -p ~/.kube diff --git a/infrastructure_setup/metallb/configuration/kustomization.yaml b/infrastructure_setup/metallb/configuration/kustomization.yaml new file mode 100644 index 0000000..dafe7d8 --- /dev/null +++ b/infrastructure_setup/metallb/configuration/kustomization.yaml @@ -0,0 +1,18 @@ +namespace: metallb-system +resources: + - pool.yaml +configMapGenerator: + - name: metallb-config + envs: + - config/config.env +replacements: + - source: + kind: ConfigMap + name: metallb-config + fieldPath: data.CLUSTER_LOAD_BALANCER_RANGE + targets: + - select: + kind: IPAddressPool + name: first-pool + fieldPaths: + - spec.addresses.0 diff --git a/infrastructure_setup/metallb/metallb-config.yaml b/infrastructure_setup/metallb/configuration/pool.yaml similarity index 62% rename from infrastructure_setup/metallb/metallb-config.yaml rename to infrastructure_setup/metallb/configuration/pool.yaml index 594bd43..5d40b3d 100644 --- a/infrastructure_setup/metallb/metallb-config.yaml +++ b/infrastructure_setup/metallb/configuration/pool.yaml @@ -1,16 +1,14 @@ --- -# Define IP address pool for MetalLB apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: - name: production + name: first-pool namespace: metallb-system spec: addresses: - - ${CLUSTER_LOAD_BALANCER_RANGE} + - PLACEHOLDER_CLUSTER_LOAD_BALANCER_RANGE --- -# Define Layer 2 advertisement for the IP pool apiVersion: metallb.io/v1beta1 kind: L2Advertisement metadata: @@ -18,4 +16,4 @@ metadata: namespace: metallb-system spec: ipAddressPools: - - production \ No newline at end of file + - first-pool diff --git a/infrastructure_setup/metallb/installation/kustomization.yaml b/infrastructure_setup/metallb/installation/kustomization.yaml new file mode 100644 index 0000000..e6e0425 --- /dev/null +++ b/infrastructure_setup/metallb/installation/kustomization.yaml @@ -0,0 +1,3 @@ +namespace: metallb-system +resources: + - github.com/metallb/metallb/config/native?ref=v0.15.0 diff --git a/infrastructure_setup/metallb/metallb-helm-config.yaml b/infrastructure_setup/metallb/metallb-helm-config.yaml deleted file mode 100644 index 35fe1c2..0000000 --- a/infrastructure_setup/metallb/metallb-helm-config.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: helm.cattle.io/v1 -kind: HelmChartConfig -metadata: - name: metallb - namespace: kube-system -spec: - valuesContent: |- - apiVersion: v1 - crds: - enabled: true - controller: - configInline: null \ No newline at end of file diff --git a/infrastructure_setup/metallb/metallb-pool.yaml b/infrastructure_setup/metallb/metallb-pool.yaml deleted file mode 100644 index b88e14b..0000000 --- a/infrastructure_setup/metallb/metallb-pool.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -# Define IP address pool for MetalLB using the new format -apiVersion: metallb.io/v1beta1 -kind: IPAddressPool -metadata: - name: production - namespace: metallb-system -spec: - addresses: - - 192.168.8.240-192.168.8.250 - ---- -# Define Layer 2 advertisement for the IP pool using the new format -apiVersion: metallb.io/v1beta1 -kind: L2Advertisement -metadata: - name: l2-advertisement - namespace: metallb-system -spec: - ipAddressPools: - - production \ No newline at end of file diff --git a/infrastructure_setup/setup-metallb.sh b/infrastructure_setup/setup-metallb.sh index 0d2654d..c600ef3 100755 --- a/infrastructure_setup/setup-metallb.sh +++ b/infrastructure_setup/setup-metallb.sh @@ -12,22 +12,16 @@ fi echo "Setting up MetalLB..." -# TODO: Remove the helm config in preference to a native config. - echo "Deploying MetalLB..." -cat ${SCRIPT_DIR}/metallb/metallb-helm-config.yaml | envsubst | kubectl apply -f - +# cat ${SCRIPT_DIR}/metallb/metallb-helm-config.yaml | envsubst | kubectl apply -f - +kubectl apply -k metallb/installation echo "Waiting for MetalLB to be deployed..." -kubectl wait --for=condition=complete job -l helm.sh/chart=metallb -n kube-system --timeout=120s || echo "Warning: Timeout waiting for MetalLB Helm job" +kubectl wait --for=condition=Available deployment/controller -n metallb-system --timeout=60s +sleep 10 # Extra buffer for webhook initialization -echo "Waiting for MetalLB controller to be ready..." -kubectl get namespace metallb-system &>/dev/null || (echo "Waiting for metallb-system namespace to be created..." && sleep 30) -kubectl wait --for=condition=Available deployment -l app.kubernetes.io/instance=metallb -n metallb-system --timeout=60s || echo "Warning: Timeout waiting for controller deployment" - -echo "Configuring MetalLB IP address pool..." -kubectl get namespace metallb-system &>/dev/null && \ -kubectl apply -f "${SCRIPT_DIR}/metallb/metallb-pool.yaml" || \ -echo "Warning: metallb-system namespace not ready yet. Pool configuration will be skipped. Run this script again in a few minutes." +echo "Customizing MetalLB..." +kubectl apply -k metallb/configuration echo "✅ MetalLB installed and configured" echo ""