### Install MetalLB with Helm using a values file Source: https://metallb.io/installation Installs MetalLB with a custom values file. This is recommended for providing configs in Helm values. ```bash helm install metallb metallb/metallb -f values.yaml ``` -------------------------------- ### Install MetalLB with native backend Source: https://metallb.io/installation Installs MetalLB in native mode, a lightweight deployment with the built-in native BGP implementation. Suitable for L2-only or simple BGP setups, but does not support BFD or IPv6 BGP. ```bash kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.16.1/config/manifests/metallb-native.yaml ``` -------------------------------- ### Install MetalLB with Helm using default settings Source: https://metallb.io/installation Adds the MetalLB Helm chart repository and installs MetalLB with default settings. By default, the Helm chart deploys MetalLB using the FRR-K8s mode. ```bash helm repo add metallb https://metallb.github.io/metallb helm install metallb metallb/metallb ``` -------------------------------- ### Run configmaptocrs container to convert ConfigMap Source: https://metallb.io/configuration/migration_to_crds Run the configmaptocrs container with the ConfigMap file mapped into /var/input. The example assumes MetalLB is installed in the metallb-system namespace and the ConfigMap is named config. On success, it generates a resources.yaml file containing the new MetalLB CRD based config. ```bash kubectl get configmap -n metallb-system -o yaml config > config.yaml docker run -d -v $(pwd):/var/input quay.io/metallb/configmaptocrs ``` -------------------------------- ### Install MetalLB with FRR-K8s backend Source: https://metallb.io/installation Installs MetalLB in FRR-K8s mode, which provides BGP with BFD support, IPv6, and the ability to merge additional FRR configuration. This is the recommended backend for most deployments. ```bash kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.16.1/config/manifests/metallb-frr-k8s.yaml ``` -------------------------------- ### Get ServiceL2Status and ServiceBGPStatus Source: https://metallb.io/faq Shows how to list ServiceL2Status and ServiceBGPStatus resources to see which node advertises a given service. ```bash $ kubectl get servicel2statuses -n metallb-system NAME ALLOCATED NODE SERVICE NAME SERVICE NAMESPACE l2-r8jwb kind-worker2 service1 ns1 l2-svkqj kind-worker service2 ns2 $ kubectl get servicebgpstatuses -n metallb-system NAME NODE SERVICE NAME SERVICE NAMESPACE bgp-82jzt kind-worker2 service4 ns4 bgp-b8fmt kind-worker2 service3 ns3 bgp-bt56x kind-worker service4 ns4 bgp-c64s2 kind-worker service3 ns3 ``` -------------------------------- ### Install MetalLB with deprecated FRR backend Source: https://metallb.io/installation Installs MetalLB in FRR mode, which configures FRR directly without the FRR-K8s layer. This mode is deprecated; migrate to FRR-K8s mode instead. ```bash kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.16.1/config/manifests/metallb-frr.yaml ``` -------------------------------- ### Example MetalLB ConfigMap config.yaml Source: https://metallb.io/configuration/migration_to_crds Example MetalLB ConfigMap named config.yaml that the generator converts. It defines a BGP peer and an address pool with a BGP advertisement. ```yaml apiVersion: v1 kind: ConfigMap metadata: namespace: metallb-system name: config data: config: | peers: - my-asn: 64512 peer-asn: 64512 peer-address: 10.96.0.100 address-pools: - name: my-ip-space protocol: bgp addresses: - 198.51.100.0/24 bgp-advertisements: - aggregation-length: 32 localpref: 100 communities: - 64512:1234 ``` -------------------------------- ### Debug speaker container with ephemeral container Source: https://metallb.io/troubleshooting Command to start an ephemeral container targeting the speaker pod for debugging, since the speaker and controller containers are based on a distroless image. ```bash kubectl debug -it -n metallb-system -c --target=speaker --image= ``` -------------------------------- ### Get list of contributors for release notes Source: https://metallb.io/community/release-process Run this git log command to list contributors between the previous tag and the current branch. Replace CUR-BRANCH and PREV-TAG with the appropriate values. ```bash git log --format="%aN" $(git merge-base CUR-BRANCH PREV-TAG)..CUR-BRANCH | sort -u | tr '\n' ',' | sed -e 's/,/, /g' ``` -------------------------------- ### Run the release script Source: https://metallb.io/community/release-process Run this command to create the appropriate branches, commits, and tags in your local repository. The working directory must be completely clean. ```bash inv release X.Y.Z ``` -------------------------------- ### Run controller and speaker locally with go run Source: https://metallb.io/community Run the MetalLB controller and speaker locally against a cluster. The controller requires the -kubeconfig and -namespace flags; the speaker additionally requires -node-name. ```bash metallb$ go run ./controller/main.go ./controller/service.go -namespace metallb-system -kubeconfig $KUBECONFIG metallb$ go run ./speaker/main.go ./speaker/*controller.go -namespace metallb-system -kubeconfig $KUBECONFIG -node-name node0 ``` -------------------------------- ### FRR-K8s BGP metrics example Source: https://metallb.io/prometheus-metrics Example of FRR-K8s BGP metrics exposed by the FRR-K8s pods. The `peer` label contains only the peer IP address (without port). ```prometheus # HELP frrk8s_bgp_updates_total Number of BGP UPDATE messages sent # TYPE frrk8s_bgp_updates_total counter frrk8s_bgp_updates_total{peer="172.23.0.5"} 1 frrk8s_bgp_updates_total{peer="172.23.0.6"} 1 frrk8s_bgp_updates_total{peer="172.30.0.2"} 1 frrk8s_bgp_updates_total{peer="172.30.0.3"} 1 ``` -------------------------------- ### Deploy MetalLB with Kustomize using FRR-K8s mode Source: https://metallb.io/installation Deploys MetalLB with the FRR-K8s mode (recommended) by pointing Kustomize at the remote kustomization file. The kustomization.yml sets the namespace to metallb-system and includes the frr-k8s resource from the main branch. ```yaml # kustomization.yml namespace: metallb-system resources: - github.com/metallb/metallb/config/frr-k8s?ref=main ``` -------------------------------- ### Repoint live-website branch to new tag Source: https://metallb.io/community/release-process Move the live-website branch to the newly created tag and force-push it to trigger Netlify redeployment of metallb.io. ```bash git branch -f live-website vX.Y.Z ``` ```bash git push -f origin live-website ``` -------------------------------- ### Deploy MetalLB with Kustomize using native BGP Source: https://metallb.io/installation Deploys MetalLB with the native BGP implementation by pointing Kustomize at the remote kustomization file. The kustomization.yml sets the namespace to metallb-system and includes the native resource from the v0.16.1 tag. ```yaml # kustomization.yml namespace: metallb-system resources: - github.com/metallb/metallb/config/native?ref=v0.16.1 ``` -------------------------------- ### Configure PreferDualStack service and BGPAdvertisement Source: https://metallb.io/configuration/_advanced_ipaddresspool_configuration Use these two YAML resources together to configure a LoadBalancer service with PreferDualStack IP family policy and a BGPAdvertisement that references the pools. The service requests an IPv6 and IPv4 address, and the advertisement lists the pools from which MetalLB can allocate. When the dualstack-pool is available, the service receives one IPv4 and one IPv6 from it. ```yaml apiVersion: v1 kind: Service metadata: name: my-app spec: type: LoadBalancer ipFamilyPolicy: PreferDualStack ipFamilies: - ipv6 - ipv4 ``` ```yaml apiVersion: metallb.io/v1beta1 kind: BGPAdvertisement metadata: name: external namespace: metallb-system spec: ipAddressPools: - ipv4-pool - ipv6-pool - dualstack-pool ``` -------------------------------- ### FRR-K8s BGP metrics with VRF label Source: https://metallb.io/prometheus-metrics Example of FRR-K8s BGP metrics with an additional `vrf` label when using BGP with a VRF. ```prometheus frrk8s_bgp_updates_total{peer="172.23.0.5"} 1 frrk8s_bgp_updates_total{peer="172.23.0.5",vrf="red"} 1 ``` -------------------------------- ### Generated resources.yaml from configmaptocrs Source: https://metallb.io/configuration/migration_to_crds Output of the generator for the example ConfigMap. It produces a BGPPeer, an IPAddressPool, and a BGPAdvertisement resource, followed by a message indicating the pod was deleted. ```yaml # This was autogenerated by MetalLB's custom resource generator. apiVersion: metallb.io/v1beta2 kind: BGPPeer metadata: creationTimestamp: null name: peer1 namespace: metallb-system spec: holdTime: 1m30s keepaliveTime: 0s myASN: 64512 passwordSecret: {} peerASN: 64512 peerAddress: 10.96.0.100 status: {} --- apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: creationTimestamp: null name: my-ip-space namespace: metallb-system spec: addresses: - 198.51.100.0/24 status: {} --- apiVersion: metallb.io/v1beta1 kind: BGPAdvertisement metadata: creationTimestamp: null name: bgpadvertisement1 namespace: metallb-system spec: aggregationLength: 32 communities: - 64512:1234 ipAddressPools: - my-ip-space localPref: 100 status: {} --- pod "configmaptocrs" deleted ``` -------------------------------- ### Deploy MetalLB with Kustomize using FRR mode (deprecated) Source: https://metallb.io/installation Deploys MetalLB with the FRR mode (deprecated) by pointing Kustomize at the remote kustomization file. The kustomization.yml sets the namespace to metallb-system and includes the frr resource from the v0.16.1 tag. ```yaml # kustomization.yml namespace: metallb-system resources: - github.com/metallb/metallb/config/frr?ref=v0.16.1 ``` -------------------------------- ### Enable BGP Graceful Restart on a BGPPeer Source: https://metallb.io/configuration/_advanced_bgp_configuration Configure a BGPPeer with graceful restart enabled. The field enableGracefulRestart is immutable, so it must be set at creation time. This example sets it to true for the peer at 172.30.0.3. ```yaml apiVersion: metallb.io/v1beta2 kind: BGPPeer metadata: name: example namespace: metallb-system spec: myASN: 64512 peerASN: 64512 peerAddress: 172.30.0.3 enableGracefulRestart: true ``` -------------------------------- ### Generate release notes with gen_relnotes.sh Source: https://metallb.io/community/release-process Run this script to generate release notes for a commit interval. The GITHUB_TOKEN environment variable must be set with read access to Contents, Pull requests, and Commit statuses. ```bash website/gen_relnotes.sh ``` -------------------------------- ### Disable automatic address allocation with autoAssign: false Source: https://metallb.io/configuration/_advanced_ipaddresspool_configuration Two IPAddressPool examples showing the default pool with automatic allocation enabled and a pool with autoAssign set to false to prevent automatic allocation of expensive addresses. ```yaml apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: cheap namespace: metallb-system spec: addresses: - 192.168.10.0/24 ``` ```yaml apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: expensive namespace: metallb-system spec: addresses: - 42.176.25.64/30 autoAssign: false ``` -------------------------------- ### Configure BGP peering via a VRF Source: https://metallb.io/configuration/_advanced_bgp_configuration Sets the vrf field on a BGPPeer to establish BGP/BFD sessions using interfaces with that VRF as master. MetalLB announces through the session's interface, but host network setup is required to route traffic to the CNI. ```yaml apiVersion: metallb.io/v1beta2 kind: BGPPeer metadata: name: example namespace: metallb-system spec: myASN: 64512 peerASN: 64512 peerAddress: 172.30.0.3 peerPort: 179 vrf: "red" ``` -------------------------------- ### Filter ServiceBGPStatus by labels Source: https://metallb.io/faq Shows how to filter ServiceBGPStatus resources using labels for service name, namespace, and node. ```bash $ kubectl get servicebgpstatuses -n metallb-system -l metallb.io/service-name="service3",metallb.io/service-namespace="ns3",metallb.io/node=kind-worker NAME NODE SERVICE NAME SERVICE NAMESPACE bgp-c64s2 kind-worker service3 ns3 ```