Add MetalLB configuration and resources for Kubernetes

This commit is contained in:
2025-03-23 12:51:54 +01:00
parent cd605de7a9
commit d58eb635d2
6 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
# /infrastructure/controllers/metallb/config-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: metallb-config
namespace: metallb-system
spec:
template:
spec:
serviceAccountName: metallb-config-sa
containers:
- name: kubectl
image: bitnami/kubectl:latest
command:
- /bin/bash
- -c
- |
# Get the external IP of the node using kubectl
SERVER_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}')
echo "Detected server IP: $SERVER_IP"
cat <<EOF | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: first-pool
namespace: metallb-system
spec:
addresses:
- ${SERVER_IP}/32
EOF
cat <<EOF | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: l2-advert
namespace: metallb-system
spec:
ipAddressPools:
- first-pool
EOF
echo "MetalLB configured to use IP: $SERVER_IP"
restartPolicy: OnFailure
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: metallb-config-sa
namespace: metallb-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: metallb-config-role
rules:
- apiGroups: ["metallb.io"]
resources: ["ipaddresspools", "l2advertisements"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: metallb-config-rolebinding
subjects:
- kind: ServiceAccount
name: metallb-config-sa
namespace: metallb-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: metallb-config-role

View File

@@ -0,0 +1,8 @@
# /infrastructure/controllers/metallb/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- namespace.yaml
- repository.yaml
- release.yaml
- config-job.yaml

View File

@@ -0,0 +1,5 @@
# /infrastructure/controllers/metallb/namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: metallb-system

View File

@@ -0,0 +1,20 @@
# /infrastructure/controllers/metallb/release.yaml
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: metallb
namespace: metallb-system
spec:
interval: 15m
chart:
spec:
chart: metallb
version: "0.14.9"
sourceRef:
kind: HelmRepository
name: metallb
namespace: metallb-system
interval: 15m
values:
crds:
enabled: true

View File

@@ -0,0 +1,9 @@
# /infrastructure/controllers/metallb/repository.yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: metallb
namespace: metallb-system
spec:
interval: 24h
url: https://metallb.github.io/metallb