Install MetalLb and Nginx Ingress on bare-metal cluster

Install MetalLb and Nginx Ingress on bare-metal cluster

Installing Metallb network load balancer and Nginx Ingress controller on a bare-metal Kubernetes cluster

ยท

4 min read

In the last article I set up FluxCD and ChartMuseum in my cluster and I was eager to start working on the CI/CD workflow, but quickly realized that I need to install some additional tools in order to solve one minor issue.

So what's the problem?

As part of the continuous integration pipeline, the process will need to generate the helm charts for the services and push them to ChartMuseum.

In order to do this, I have to expose ChartMuseum service to the outside world, because it will be called from GitHub actions which obviously don't run in my local network.

What's the plan?

I will install Nginx Ingress Controller to help with the routing, but in order for it to work, I must first ensure I have a network load balancer that sits in front. In typical cloud environments, this step is not required due to load balancers being available on-demand, but in my bare-metal scenario I don't have this benefit and I can install a pure software solution like MetalLb.

After this, I'll pick a DNS for ChartMuseum and use a free service like noip.com to map it to my home router.

So let's start.

Installing Metallb

Installation is pretty straightforward and easy. We only need to get our hands on some free IPs from our internal network and then set up the chart.

Find a free IP range

You must first identify on which network your router is allocating IPs and then check a few of them to not be taken.

In the image below you can see my default gateway is 192.168.1.1 so it means that I have to pick some free IPs in the range 192.168.1.1-192.168.1.254.

image.png

You can check if an IP is free by pinging it on the console, or I recommend using this PowerShell script because we will require at least 10 free IPs. Make sure you replace the script inputs like in my example:

Test-PingWF -iprange (1..25 | % {"192.168.1."+$_})

image.png

If any IP is taken it should appear in the result list. You can see in the image I have only 192.168.1.1 taken which is the default gateway so the IP range that we'll allow Metallb is 192.168.1.2-192.168.1.25.

Create the charts

I'll use the bitnami chart available here and let Flux apply it to my cluster.

If you want to follow the code in this tutorial here is the repository link.

First, let's create the bitnami repository for Flux to use

# /infrastructure/sources/bitnami.yaml
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
  name: bitnami
spec:
  url: https://charts.bitnami.com/bitnami
  interval: 10m

and the helm release

# /infrastructure/metallb/release.yaml
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: metallb
spec:
  interval: 5m
  chart:
    spec:
      chart: metallb
      version: "2.6.10"
      sourceRef:
        kind: HelmRepository
        name: bitnami
        namespace: flux-system
      interval: 5m
  values:
    configInline:
      address-pools:
      - name: default
        protocol: layer2
        addresses:
        - 192.168.1.2-192.168.1.25

with the corresponding kustomization

# /infrastructure/metallb/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: infrastructure
resources:
  - release.yaml

Installing Nginx

Add the helm repository

# /infrastructure/sources/nginx.yaml
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
  name: ingress-nginx
  namespace: flux-system
spec:
  url: https://kubernetes.github.io/ingress-nginx
  interval: 10m

and the helm release

# /infrastructure/nginx/release.yaml
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: nginx
spec:
  interval: 5m
  chart:
    spec:
      chart: ingress-nginx
      version: "4.0.18"
      sourceRef:
        kind: HelmRepository
        name: ingress-nginx
        namespace: flux-system
      interval: 5m

with the kustomization

# /infrastructure/nginx/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: infrastructure
resources:
  - release.yaml

Let's wrap up with the repositories kustomization update

# /infrastructure/sources/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: flux-system
resources:
  - chartmuseum.yaml
  - bitnami.yaml
  - nginx.yaml

I have also restructured namespaces from the last article and now we have everything under 'infrastructure' namespace

# /infrastructure/namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: infrastructure
  labels:
    name: infrastructure

And final update to root kustomization

# /infrastructure/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - namespace.yaml
  - sources
  - chartmuseum
  - metallb
  - nginx

Now we push the code and Flux should take it from here and install everything in our cluster.

This post got so long already and I think it's best to finish exposing ChartMuseum to the outside world in the next article.

Let me know if you need any help and thank you for reading!

See you in the next one! ๐Ÿป

ย