Deploying Metallb and Exposing an application

In this blog post we will see how to deploy Metallb and also expose an application and access the same with the help of Metallb loadbalancer.

To install MetalLB, apply the manifest:

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
Create IP Pool:

In order to assign an IP to the services, MetalLB must be instructed to do so via the IPAddressPool CR. All the IPs allocated via IPAddressPools contribute to the pool of IPs that MetalLB uses to assign IPs to services. Multiple instances of IPAddressPools can co-exist and addresses can be defined by CIDR, by range, and both IPV4 and IPV6 addresses can be assigned.

Create IPAddressPool.yml file with the below spec

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: first-pool
  namespace: metallb-system
spec:
  addresses:
  - 10.20.65.60-10.20.65.70
  

Create the IP pool for metallb by running the command kubectl create -f IPAddressPool.yml

Create Layer 2 Configuration

Layer 2 mode is the simplest to configure: in many cases, you don’t need any protocol-specific configuration, only IP addresses.

Create L2Advertisement.yml with the below spec. This L2Advertisement is associated with the first-pool IPAddressPool that is created above.

apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: example
  namespace: metallb-system
spec:
  ipAddressPools:
  - first-pool

Create the L2Advertisement for metallb by running the command kubectl create -f L2Advertisement.yml

Note: The above L2Advertisement is associated with the IP pool named first-pool that we created sometime back. If you would want the same L2Advertisement to be used for all the IP pools, use the below manifest file for the L2Advertisement.

apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: example
  namespace: metallb-system
Create an application and access it externally:

Now that the Metallb configuration is completed, let’s create an application and try to expose it as a type LoadBalancer.

From the below screenshot, you see that I have a nginx pod created and I have exposed it as a load balancer.

We can now access the installed Nginx application with the External-IP assigned to the Nginx service. This IP is assigned from the IP pool that we created during the metallb configuration.

You can see that we are now able to access the Nginx application successfully. I hope this blog post helps someone. If you agree, feel free to share it with others. Happy learning! 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: