[Kubernetes (K8S)] Helm install MetalLB to handle ServiceType Loadbalancer for bare metal within Kubernetes (K8S)

MetalLB

MetalLB is an open source, rock solid LoadBalancer. It handles the ServiceType: Loadbalancer for bare metal Kubernetes clusters, using standard routing protocols.

This article is about how to use Pulumi, kubernetes (K8S) provider, Helm Chart and TypeScript SDK to deploy MetalLB within Kubernetes (K8S).

Prerequisites

  • Kubernetes (K8S)
    Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

    For more information about installing and using Kubernetes (K8s), see the Kubernetes (K8s) Docs.

  • Helm
    Helm is the best way to find, share, and use software built for Kubernetes.

    For more information about installing and using Helm, see the Helm Docs.

Installation

Custom Values.yaml

Remember to replace the values within {{ }}.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# values.yaml

# charts/values.yaml at master · bitnami/charts
# https://github.com/bitnami/charts/blob/master/bitnami/metallb/values.yaml

## To configure MetalLB, you must specify ONE of the following two
## options.
#
## existingConfigMap specifies the name of an externally-defined
## ConfigMap to use as the configuration. Helm will not manage the
## contents of this ConfigMap, it is your responsibility to create it.
#
# existingConfigMap: metallb-config
#
## configInline specifies MetalLB's configuration directly, in yaml
## format. When configInline is used, Helm manages MetalLB's
## configuration ConfigMap as part of the release, and
## existingConfigMap is ignored.
## Refer to https://metallb.universe.tf/configuration/ for
## available options.
#
configInline: |
# https://metallb.universe.tf/configuration/#layer-2-configuration
address-pools:
- name: default
protocol: layer2
addresses:
# Replace with idle IP in the same subnet as the node IP.
- {{ .Values.addresses }}

Install by Helm

Helm install metallb into metallb namespace.

1
2
3
4
5
6
7
8
9
10
11
# crate namespace:
$ kubectl create namespace metallb-system

# Add the Helm repository:
$ helm repo add bitnami https://charts.bitnami.com/bitnami

# Update your local Helm chart repository cache:
$ helm repo update

# To install Helm chart:
$ helm install metallb bitnami/metallb --namespace metallb-system -f values.yaml

See Helm release about metallb.

1
2
3
$ helm list --namespace metallb-system
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
metallb metallb-system 4 2020-09-19 11:26:07.970123 +0800 +0800 deployed metallb-0.1.24 0.9.3

See pods about metallb.

1
2
3
4
5
$ kubectl get pods -n metallb-system
NAME READY STATUS RESTARTS AGE
metallb-controller-f899f5594-7d29x 1/1 Running 6 15d
metallb-speaker-xkksl 1/1 Running 44 30d
metallb-speaker-xsqgx 1/1 Running 35 30d

Example

Create Deployment and Service(LoadBalancer) for Nginx.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# https://raw.githubusercontent.com/metallb/metallb/main/manifests/tutorial-2.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1
ports:
- name: http
containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancer

Apply manifest file.

1
$ kubectl apply -f tutorial-2.yaml

Then, check svc or Service.

1
2
3
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx LoadBalancer 10.105.4.74 <Your addresse> 80:32159/TCP 31d

References

[1] charts/bitnami/metallb at master · bitnami/charts - https://github.com/bitnami/charts/tree/master/bitnami/metallb

[2] MetalLB, bare metal load-balancer for Kubernetes - https://metallb.universe.tf/installation/

[3] metallb/metallb: A network load-balancer implementation for Kubernetes using standard routing protocols - https://github.com/metallb/metallb

[4] Helm - https://helm.sh/

[5] Kubernetes - https://kubernetes.io/