Using HAProxy as a Kubernetes Ingress Controller

Whenever I’ve needed a Kubernetes Ingress controller in the past I’ve always used Nginx, not because it’s better than everything else but just because I was familiar with it. Outside of Kubernetes I’ve always used HAProxy as my reverse-proxy of choice and been very happy with it, it’s always performed well and been easy to configure. Recently HAProxy released v1.5 of their Ingress controller so I thought it was time to try HAProxy instead of Nginx.

In this article I’m going to show the steps to get the HAProxy Ingress running within Kubernetes and configure it to allow access. I’m going to be using Azure Kubernetes Service but these steps should work for any Kubernetes setup.

I’ve already got Kubernetes setup (Azure makes this easy) however if you don’t you can quickly get a running instance by running the following script (make sure to remove the installation of Nginx and it’s configuration as that’s not needed). We’re going to be using Helm for HAProxy deployment as it makes it really quick and easy to get it running with minimal configuration required, I’m going to presume you have Helm already setup but if not you can follow the steps here. You will also need Kubectl installed and configured.

Let’s start by adding the HAProxy Helm repository by running the following Powershell:

helm repo add haproxytech

We can then update the Helm chats

helm repo update

Now we can use Helm to install the HAProxy Ingress Controller. Make sure you update $publicIP with an actual public IP address.

helm install kubernetes-ingress haproxytech/kubernetes-ingress --set controller.service.type=LoadBalancer --set controller.service.loadBalancerIP="$publicIP"

We can check the deployment was successful by running the following kubectl command:

kubectl get deployments

and we should see the following:

We can also check the public IP address was set correctly by getting the services and checking the external IP.

kubectl get services

That all looks good to me!

Now that the HAProxy Ingress Controller is running we can create another deployment before configuring HAProxy to route traffic to it. In this example I’m just going to deploy my basic Helloworld image that I normally use for tutorials

kubectl create deployment helloworld --image tomaustin/helloworldnetcore

Once created expose the deployment:

kubectl expose deployment helloworld --name helloworld --port 80

We can now just configure the Ingress Controller using Kubectl and that should be pretty much it. Save the following to a file and apply it using Kubectl, make sure to update ‘yourdnsnamegoeshere’ with your dns address.

kind: Ingress
  name: ingress
  namespace: default
  annotations: "true"
  - host: yourdnsnamegoeshere
      - path: /
          serviceName: helloworld
          servicePort: 80
kubectl apply -f ingress.yml

That should be it! If all went to plan you should be able to navigate to your dns address and see your service

The HAProxy Ingress Controller can do a fair bit so make sure to check out the documentation here. If you encountered any issues then don’t hesitate to get in touch by either leaving a comment or contacting me on Twitter. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.