Read on:

Beginners’ Guide for Microsoft Hyper-V: Overview of Hyper-V – Part 1
Beginners’ Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V Using Server Manager – Part 2
Beginners’ Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V with PowerShell – Part 3
Read More

When running self-hosted Kubernetes in your Hyper-V environment, many configuration decisions must be made to successfully self-host your applications and services. One of those considerations is getting traffic into your Kubernetes cluster. In cloud-hosted environments, much of this configuration is taken care of automatically. However, one area of your self-hosted configuration you must consider is external IP addresses. Let’s look at Windows Kubernetes self-hosted load balancer for beginners and see why this is important and how you can deploy your own Kubernetes LoadBalancer.

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!

Downsides to NodePort and ExternalIP

NodePort is one of the basic ways to get traffic into a Kubernetes cluster. You essentially assign a high-range port that Kubernetes exposes on every Node in the cluster. The port is chosen from the range: 30000-32767. Once a NodePort is established, for production deployments, you could set up an external load balancer that would forward requests for that service to the node IP addresses and the assigned port.

There are drawbacks to using NodePort:

  • It adds complexity when trying to troubleshoot
  • For thousands of services or applications, scalability is affected since you can only use a set number of ports: 30000-32767
  • NodePort is a less secure solution since it uses high-range ports and it bypasses many of the security configurations in Kubernetes
  • It can lead to less effective monitoring of services

Another method is the use of the ExternalIP service type.

Download Banner

What is a Kubernetes Load Balancer?

When you consider Kubernetes documentation related to type LoadBalancer, the official documentation notes the following:

“Kubernetes provides functionality equivalent to type equals ClusterIP to pods within the cluster and extends it by programming the (external to Kubernetes) load balancer with entries for the nodes hosting the relevant Kubernetes pods. The Kubernetes control plane automates the creation of the external load balancer, health checks (if needed), and packet filtering rules (if needed). Once the cloud provider allocates an IP address for the load balancer, the control plane looks up that external IP address and populates it into the Service object.”

Kubernetes does not offer an in-the-box implementation of a network load balancer to configure services with type LoadBalancer. It uses “glue code” in the box to coordinate with the various IaaS platforms, including GCP, AWS, and Azure, to call out to the cloud coordinator to provide an IP address for the service.

When you are running bare-metal Kubernetes on-premises in a self-hosted environment, the load balancer is something you will need to consider and provide for your services.

MetalLB free and open-source load balancer

Since Kubernetes does not offer a built-in load balancer for assigning IPs to services running in your Kubernetes cluster, we need to use our own solution to assign IPs to services. One of the best free and open-source solutions available for those looking to start working with services of type LoadBalancer in their self-hosted Kubernetes cluster is MetalLB.

MetalLB is a free and open-source solution that is easy to set up and configure and provides many excellent capabilities to self-hosted bare-metal Kubernetes clusters. Let’s see how we can easily install and configure MetalLB in a Microk8s cluster configuration running in Hyper-V.

Address allocation

MetalLB works on the administrator, providing pools of IP addresses for MetalLB to allocate for the services running in your Kubernetes cluster. Administrators may carve out a pool of IP addresses from their DHCP scope and allow MetalLB to use these to assign IP addresses to services.

You can define multiple pools of IP addresses for MetalLB, which can be from RFC1918 private IPs, or you can assign public IP addresses. MetalLB also announces the IP addresses to the outside network, and the IPs live inside the cluster. There are a couple of configuration modes for MetalLB for announcing IP addresses.

  • Layer 2 mode (ARP/NDP)
  • BGP mode

With Layer 2 mode, MetalLB uses standard IP address discovery protocols such as ARP or NDP. The Layer 2 mode is the most basic configuration and usually “just works” in most networks.

MetalLB can provide the most robust load-balancing features and capabilities in the BGP configuration mode. When you use BGP configuration mode, you are able to establish true load-balancing across your multiple nodes and granularly control access via BGP policies.

Installing MetalLB

The process to install MetalLB in our Hyper-V Microk8s installation is straightforward. With Microk8s, you can install and configure MetalLB with a simple, single-line command. Below, you can see the command we use to enable MetalLB:

  • sudo microk8s enable metallb:

Windows Kubernetes Load Balancer

Enabling MetalLB in Microk8s

The above shows the various steps the installation goes through when provisioning the MetalLB installation in Microk8s. In addition, you will see it configure a new MetalLB controller and advertise the pools. Below, if we examine the service further, we can see the service name running in the metallb-system namespace and the pods running.

Windows Kubernetes Load Balancer

MetalLB service and pods

We can look further into the configuration with a couple of other commands. Note the following:

  • sudo microk8s kubectl get ipaddresspools.metallb.io -A
  • sudo microk8s kubectl describe ipaddresspoools.metallb.io -A

Using these commands, we can take a look at all configured address pools and describe them for more detail and information gathering.

Windows Kubernetes Load Balancer

Looking at the configuration of IP address pools in MetalLB

Windows Kubernetes Load Balancer FAQs

What is MetalLB?

MetalLB is a free and open-source load balancer solution for Kubernetes. It provides the missing load balancer functionality for Kubernetes clusters when they run on-premises in self-hosted environments. Unlike cloud environments, on-premises environments don’t have cloud-controlled IP address orchestration with Kubernetes.

Why do you need a load balancer in Kubernetes?

Load balancers in Kubernetes on-premises or cloud environments are needed to assign IP address information to internal Kubernetes services. These are inaccessible from the outside network without a way to communicate with internal services.

Is MetalLB free?

Yes, MetalLB is a free and open-source project that is freely available for use.

Wrapping Up

Windows Kubernetes load balancer configuration is required when self-hosting services in your on-premises Kubernetes cluster. It allows providing connectivity to internal services in your Kubernetes cluster. MetalLB is a freely available load balancer in bare metal self-hosted Kubernetes clusters. When hosting Windows Kubernetes clusters on-premises, MetalLB can effectively handle IP address assignments for your Kubernetes services.

Read More on the Series:

Beginners Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V in Windows Server Core – Part 4
Beginners Guide for Microsoft Hyper-V: Remote Management of Hyper-V – Part 5
Beginners Guide for Microsoft Hyper-V: How to Install Hyper-V Server – Part 6
Beginner’s Guide for Microsoft Hyper-V: What is Azure Stack HCI – Part 7
Beginner’s Guide for Microsoft Hyper-V: Windows Admin Center Hyper-V Management – Part 8
Beginner’s Guide for Microsoft Hyper-V: Configuration of Hyper-V Networking Best Practices – Part 9
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Storage Best Practices and Configuration – Part 10
Beginner’s Guide for Microsoft Hyper-V: How to build a Virtual Lab with Hyper-V – Part 11
Beginner’s Guide for Microsoft Hyper-V: Top 10 PowerShell Commands for Hyper-V – Part 12
Beginner’s Guide for Microsoft Hyper-V: How to Create a Hyper-V Virtual Machine – Part 13
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Shared Storage for Beginners – Part 14
Beginner’s Guide for Microsoft Hyper-V: How to Create Hyper-V Cluster – Part 15
Beginner’s Guide for Microsoft Hyper-V: What is Non-Uniform Memory Access (NUMA) – Part 16
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Dynamic Memory – Part 17
Beginner’s Guide for Microsoft Hyper-V: Cluster Aware Updating (CAU) – Part 18
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Containers – Part 19
Beginner’s Guide for Microsoft Hyper-V: Managing Windows Server Containers with Windows Admin Center – Part 20
Beginner’s Guide for Microsoft Hyper-V: What are Hyper-V Checkpoints – Part 21
Beginners Guide for Microsoft Hyper-V: How to Create Cluster Shared Volumes (CSVs) – Part 22
Beginners’ Guide for Microsoft Hyper-V: VHD vs VHDX Vs AVHD/AVHDX: Overview of Virtual Disk Formats – Part 23
Beginners’ Guide for Microsoft Hyper-V: Hyper-V Live Migration – Part 24
Beginners’ Guide for Microsoft Hyper-V: Hyper-V High Availability – Part 25
Beginners’ Guide for Microsoft Hyper-V: How to Export and Import Hyper-V VM’s – Part 26
Beginners’ Guide for Microsoft Hyper-V: How To Install Docker Container on Windows Server – Part 27
Beginners’ Guide for Microsoft Hyper-V: How to Run Linux Containers on Hyper-V – Part 28
Beginners’ Guide for Microsoft Hyper-V: Containers vs Virtual Machines – Part 29
Beginners’ Guide for Microsoft Hyper-V: What is Azure Arc VM Management – Part 30
Beginners’ Guide for Microsoft Hyper-V: Azure Features in Windows Admin Center – Part 31
Beginners’ Guide for Microsoft Hyper-V: What is Microsoft Azure Arc – Part 32
Beginners Guide for Microsoft Hyper-V: How to Create a Virtual Switch in Hyper-V using Windows Admin Center – Part 33
Beginners Guide for Microsoft Hyper-V: Managing Hyper-V Server with Azure Arc – Part 34
Beginners Guide for Microsoft Hyper-V: Learn How to Install MicroK8s on Windows Kubernetes – Part 35
Beginners Guide for Microsoft Hyper-V: Top 8 Basic Docker Commands You Should Know – Part 36
Beginners’ Guide for Microsoft Hyper-V: Windows Docker Container Networking in Hyper-V – Part 37
Beginners’ Guide for Microsoft Hyper-V: How to run IIS in Docker Container – Part 38
Beginners’ Guide for Microsoft Hyper-V: How to install and run Linux on Windows with WSL – Part 39
Beginners’ Guide for Microsoft Hyper-V: How to use Multipass on Windows Hyper-V – Part 40
Beginners’ Guide for Microsoft Hyper-V: Windows Kubernetes Ingress Controller – Part 41

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

Rate this post