How to setup Hetzner load balancer on a Kubernetes cluster

TL;DR: Recently (June 2020) Hetzner added a cloud native load balancer with Kubernetes support. Learn how to use it.

Image for post
Image for post
We finally have load balancer in Hetzner!

Introduction

Until a couple of months ago (June 2020) Germany Hetzner Cloud provider did not have a native cloud load balancer in its portfolio.

To achieve a “LoadBalancer” service in an Hetzner Kubernetes cluster you must to use a software solution like as MetalLB.

I wrote this previous post about how to create a Rancher Kubernetes cluster on Hetzner cloud using MetalLB.

Now we are going to see how to create a Kubernetes cluster using the new Load Balancer service already available in Hetzner.

Hetzner Load Balancer at glance

The new and claimed Load Balancer (LB) service has a entry level price of 4.9€/mo. Not so bad.

For that price you have a LB with a traffic support up to 20 TB/mo, 5 services (“ports”) and 25 targets (nodes). It’s enough for small/medium production services.

For more details visit “Load Balancer — Hetzner Online GmbH”.

Hetzner has its own Kubernetes cloud controller manager and now includes the LB support.

Cloud provider

As probably you know, Kubernetes implements by default the major cloud providers: AWS, Azure, GCP, …

This let’s to create or destroy new nodes, volumes or load balancers on demand.

For the rest of cloud providers, Kubernetes includes a interface that the cloud provider must implement to give support it.

In this case, when we create the cluster we must specify the cloud provider as external and later apply the 3th-party cloud-controller-manager manifest (Hetzner in our case).

Cluster creation

Let’s go. We use Rancher to create the cluster.

First we specify our needs using the UI.

Image for post
Image for post

Under “Kubernetes options” we select “External” in “Cloud provider

Image for post
Image for post

Now we switch into YAML mode to add the following as addons:

  • A Hetzner API Token as secret.
  • The Hetzner cloud-controller-manager manifest URL.
Image for post
Image for post
A button to change the view point of the same world
Image for post
Image for post
The magic addons

The addons and addons_include are children of rancher_kubernetes_engine_config. Take care of the indentation.

Remember replace <YOUR-HETZNER-API-TOKEN> with the yours!

Now click on “Create” and wait for the cluster creation.

If something goes wrong, you can apply the secret and manifest after.

Usage

We demonstrate its usage with the ingress-nginx controller.

First we create our first load balancer in the Hetzner UI.

Image for post
Image for post

Just select your preferred location, give a name (remember that name!) and press on “Create & Buy now”.

Now we need to edit ingress service definition and put the right annotations and service type:

It’s very important to set-up the right health check port. In my case that port was 30787. You can view it the ingress-nginx manifest.

You can check the full list of annotations directly from the source code in GitHub.

If it works, you can see something similar to this screen capture.

Image for post
Image for post
Load Balancer Control Panel on Hetzner

I hope this post has been useful to you.

Now Hetzner becomes a 100% Kubernetes solution ;)

Related posts

Please, if you liked it, give it a round of applause. And if you want to know more about DevOps, Kubernetes, Docker, etc … follow me :)

Image for post
Image for post

Written by

CTO @ Digitalilusion.com & DigitalSecured.net Beyond-Full-stack developer #go #python #kubernetes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store