Skip to content

Test

What Will You Do

In this section you will create and deploy a test NGINX workload that will use the MetalLB loadbalancer


Assumptions

  • You have already configured and installed MetalLB on your upstream Kubernetes cluster

Step 1: Create Namespace

In this step, you will create a namespace for the test NGINX workload. The "nginx-namespace.yaml" file contains the declarative specification

The following items may need to be updated if you used alternate names.

  • value: metallb-cluster
kind: ManagedNamespace
apiVersion: config.rafay.dev/v2
metadata:
  name: metallb-test-workload
  description: namespace for metallb test workload
  labels:
  annotations:
spec:
  type: RafayWizard
  resourceQuota:
  placement:
    placementType: ClusterSpecific
    clusterLabels:
    - key: rafay.dev/clusterName
      value: metallb-cluster
  • Open Terminal (on macOS/Linux) or Command Prompt (Windows) and navigate to the folder where you forked the Git repository
  • Navigate to the folder "/getstarted/metallb/namespace"
  • Type the command below
rctl create namespace -f nginx-namespace.yaml

If you did not encounter any errors, you can optionally verify if everything was created correctly on the controller.

  • Navigate to the "defaultproject" project in your Org
  • Select Infrastructure -> Namespaces
  • You should see an namesapce called "metallb-test-workload"

Namespace

Now, we need to publish the namespace to the cluster

  • Type the command below
rctl publish namespace metallb-test-workload

If you did not encounter any errors, you can optionally verify if everything was created correctly on the cluster.

  • Click on the Kubectl button on the cluster to open a virtual terminal and run the following kubectl command
kubectl get ns

You should see a message like below

NAME                    STATUS   AGE
default                 Active   21h
kube-node-lease         Active   21h
kube-public             Active   21h
kube-system             Active   21h
metallb                 Active   20m
metallb-test-workload   Active   35s
openebs                 Active   21h
rafay-infra             Active   21h
rafay-system            Active   21h

Step 2: Update Workload Manifest

In this step, we will update the NGINX manifest, "metallb-nginx.yaml", to use a static IP address from the MetalLB loadbalancer IP pool.

To set a static IP for the NGINX workload, we must assign a "loadBalancerIP" to the spec. This should be set to an IP from the static address pool defined in the custom values file for the MetalLB addon.

  • Update the loadbalancerIP with an IP address from the MetalLB IP pool

  • loadBalancerIP: 192.168.86.212

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
  namespace: metallb-test-workload
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx
  namespace: metallb-test-workload
spec:
  loadBalancerIP: 192.168.86.212
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: LoadBalancer

Step 3: Create Workload

In this step, you will create a workload on the cluster using the "metallb-test-workload.yaml" file which contains the declarative specification for our test workload. This workload will use the NGINX manifest in the "metallb-nginx.yaml" file.

The following items may need to be updated if you used alternate names.

  • project: defaultproject
  • clusters: metallb-cluster
name: metallb-test-workload
namespace: metallb-test-workload
project: defaultproject
type: NativeYaml
clusters: metallb-cluster
payload: metallb-nginx.yaml
  • Open Terminal (on macOS/Linux) or Command Prompt (Windows) and navigate to the folder where you forked the Git repository
  • Navigate to the folder "/getstarted/metallb/workload"
  • Type the command below
rctl create workload metallb-test-workload.yaml

If there were no errors, you should see a message like below

Workload created successfully

Now, let us publish the newly created workload to the cluster. The workload can be deployed to multiple clusters as per the configured "placement policy". In this case, you are deploying to a single cluster.

rctl publish workload metallb-test-workload

In the web console, click on Applications -> Workloads. You should see something like the following.

Published Workload


Step 4: Verify Workload

Click on the Kubectl button on the cluster to open a virtual terminal and run the following kubectl command

kubectl get services -n metallb-test-workload

You should see a message like below

NAME    TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
nginx   LoadBalancer   10.100.175.4   192.168.86.212   80:32452/TCP   3m36s

MetalLB is listening for services of type LoadBalancer and immediately assigns an external IP (an IP chosen from the range you selected when you set up MetalLB). View the new service and the external IP address MetalLB assigned to it.

  • Open a web browser and navigate to the "EXTERNAL-IP" assigned to NGINX.

NGINX


Recap

Congratulations! You have successfully created and deployed a workload to use the MetalLB Load Balancer.