haproxy-unified-gateway
A Helm chart for HAProxy Unified Gateway - Kubernetes Gateway API Controller
About this chart
HAProxy Unified Gateway
A Kubernetes Gateway API controller powered by HAProxy. HAProxy Unified Gateway (HUG) implements the Gateway API specification to provide advanced traffic management capabilities.
Detailed documentation can be found within the Official Documentation.
Introduction
This chart bootstraps a HAProxy Unified Gateway deployment/daemonset on a Kubernetes cluster using the Helm package manager.
Prerequisites
- Kubernetes 1.26+
- Helm 3.6+ (recommended 3.7+)
Before you begin
Setting up a Kubernetes Cluster
The quickest way to setup a Kubernetes cluster is with Azure Kubernetes Service, AWS Elastic Kubernetes Service or Google Kubernetes Engine using their respective quick-start guides.
For setting up Kubernetes on other cloud platforms or bare-metal servers refer to the Kubernetes getting started guide.
Install Helm
Get the latest Helm release.
Adding Helm chart repo
Once you have Helm installed, add the haproxytech Chart Repository as follows:
helm repo add haproxytech https://haproxytech.github.io/helm-charts
helm repo update
Installing the chart
To install the chart as my-release deployment:
helm install my-release haproxytech/haproxy-unified-gateway
The chart installs the HUG and Gateway API CRDs through hook Jobs (see CRD and Gateway API installation jobs), so no separate CRD step is needed. See also the official installation guide.
Routing the first request
The controller serves Gateways whose GatewayClass has controllerName: gate.haproxy.org/hug. A minimal setup sending all traffic of an HTTP listener to a Service echo:
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: hug
spec:
controllerName: gate.haproxy.org/hug
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gw
spec:
gatewayClassName: hug
listeners:
- name: http
port: 31090
protocol: HTTP
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: echo
spec:
parentRefs:
- name: gw
rules:
- backendRefs:
- name: echo
port: 8080
For each listener the controller adds a port named <protocol>-<port> (here http-31090) to the chart's Service, so the route is reachable at my-release-haproxy-unified-gateway:31090 inside the cluster, or through the NodePort the controller allocates for it.
Installing with unique name
To auto-generate controller and its resources names when installing, use the following:
helm install haproxytech/haproxy-unified-gateway \
--generate-name
Installing from a private registry
To install the chart using a private registry for controller into a separate namespace prod.
NOTE: The namespace must exist; add --create-namespace to have Helm create it (eg. instead of kubectl create namespace prod)
helm install my-release haproxytech/haproxy-unified-gateway \
--namespace prod \
--create-namespace \
--set controller.image.tag=SOMETAG \
--set controller.imagePullSecrets[0].name=my-pull-secret
Using values from YAML file
As opposed to using many --set invocations, much simpler approach is to define value overrides in a separate YAML file and specify them when invoking Helm:
myhug.yaml:
controller:
kind: DaemonSet
service:
type: LoadBalancer
annotations:
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
And invoking Helm becomes:
helm install my-release -f myhug.yaml haproxytech/haproxy-unified-gateway
Installing as DaemonSet
Default controller mode is Deployment, but it is possible to use DaemonSet as well:
helm install my-release haproxytech/haproxy-unified-gateway \
--set controller.kind=DaemonSet
Installing with host networking (DaemonSet)
When using DaemonSet mode, you can enable host networking (for host ports instead, see DaemonSet with host ports):
helm install my-release haproxytech/haproxy-unified-gateway \
--set controller.kind=DaemonSet \
--set controller.daemonset.useHostNetwork=true \
--set controller.dnsPolicy=ClusterFirstWithHostNet
Installing with service annotations
On some environments like EKS and GKE there might be a need to pass service annotations. Syntax can become a little tedious however:
helm install my-release haproxytech/haproxy-unified-gateway \
--set controller.service.type=LoadBalancer \
--set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-internal"="0.0.0.0/0" \
--set-string controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-cross-zone-load-balancing-enabled"="true"
NOTE: With helm --set it is needed to put quotes and escape dots in the annotation key and commas in the value string. Use --set-string for values such as true or numbers, which --set turns into a boolean or integer that Kubernetes rejects as an annotation value.
Installing with LoadBalancer IP
When using a LoadBalancer service type, you can request a specific IP address (provider-dependent):
helm install my-release haproxytech/haproxy-unified-gateway \
--set controller.service.type=LoadBalancer \
--set controller.service.loadBalancerIP="203.0.113.10"
Or using a values file:
controller:
service:
type: LoadBalancer
loadBalancerIP: "203.0.113.10"
NOTE: Not all cloud providers support this field. Refer to your cloud provider's documentation for LoadBalancer IP allocation.
NOTE: loadBalancerIP is deprecated as of Kubernetes 1.24 in favour of provider-specific annotations. To select a particular load balancer implementation, prefer loadBalancerClass below.
Selecting a LoadBalancer implementation
When more than one load balancer controller runs in a cluster, loadBalancerClass picks which one reconciles the Service. Leaving it unset uses the cluster's default implementation. Available since chart 1.2.0.
helm install my-release haproxytech/haproxy-unified-gateway \
--set controller.service.type=LoadBalancer \
--set controller.service.loadBalancerClass="example.com/internal-lb"
Or using a values file, together with a source IP allowlist:
controller:
service:
type: LoadBalancer
loadBalancerClass: example.com/internal-lb
loadBalancerSourceRanges:
- 192.0.2.0/24
- 198.51.100.0/24
| Key | Description | Default |
|---|---|---|
controller.service.loadBalancerIP | Requested LB IP (provider-dependent, deprecated since Kubernetes 1.24). | "" |
controller.service.loadBalancerSourceRanges | CIDR allowlist for the LB. | [] |
controller.service.loadBalancerClass | LoadBalancerClass selecting the LB implementation. | null |
All three fields render only when controller.service.type is LoadBalancer.
NOTE: loadBalancerClass is immutable while the Service stays type LoadBalancer. Kubernetes rejects a change on an existing Service, so helm upgrade cannot alter it in place - the Service has to be recreated (for example by deleting it and re-running the upgrade).
NOTE: loadBalancerSourceRanges is only enforced by providers that implement it; check your provider's documentation before relying on it as a security control.
Installing with Horizontal Pod Autoscaler (HPA)
HPA automatically scales number of replicas in Deployment and adjusts replica count for the controller:
helm install my-release haproxytech/haproxy-unified-gateway \
--set controller.autoscaling.enabled=true
Enabling Prometheus monitoring
HUG exposes two separate metrics endpoints:
stat(port 31024) — HAProxy native metrics (haproxy_*prefix): connections, request rates, backend health, latency, error codes (reference)metrics(port 31060) — HUG controller metrics (hug_*prefix): event batch processing, config generation, cert/map operations, HAProxy reloads (reference)
The chart supports both ServiceMonitor and PodMonitor for Prometheus Operator integration. These are mutually exclusive — enable only one (the chart fails at render when both are enabled). The default ServiceMonitor endpoints scrape both; the default PodMonitor endpoints scrape only stat (see below). Enabling the ServiceMonitor also creates a ClusterIP metrics Service (<fullname>-metrics) exposing stat and metrics; it requires controller.service.enabled.
Note: HAProxy serves the stat endpoint only once the controller has programmed its first Gateway; until then that scrape target is down. The chart passes --stats-port from controller.containerPort.stat, so change the port there rather than through extraArgs.
Note: Requires Prometheus Operator installed in the cluster. The monitoring.coreos.com/v1 API must be available.
Metrics authentication
The controller metrics endpoint (metrics port) supports three authentication modes via controller.metricsAuth:
| Mode | Default | Protocol | Description |
|---|---|---|---|
kube-rbac | yes | HTTPS | Kubernetes TokenReview/SubjectAccessReview — Prometheus authenticates with its ServiceAccount token |
none | HTTP | No authentication | |
basic | HTTPS | HTTP Basic Authentication with username/password |
Default setup (kube-rbac)
By default the chart uses kube-rbac authentication. The controller serves metrics over HTTPS and validates bearer tokens via the Kubernetes API. To set it up:
Step 1. Create a ClusterRole that grants access to the /metrics endpoint and bind it to the Prometheus ServiceAccount:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: hug-metrics-reader
rules:
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: hug-metrics-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: hug-metrics-reader
subjects:
- kind: ServiceAccount
name: prometheus # adjust to your Prometheus SA name
namespace: monitoring # adjust to your Prometheus namespace
Step 2. Enable the ServiceMonitor. The default endpoints are pre-configured for kube-rbac — stat uses plain HTTP, metrics uses HTTPS with the Prometheus pod's ServiceAccount token:
controller:
serviceMonitor:
enabled: true
extraLabels:
release: prometheus # match your Prometheus serviceMonitorSelector
That's it. The default values.yaml endpoints already include the correct HTTPS + bearer token configuration for the metrics port:
# Default endpoints (already set in values.yaml):
endpoints:
- port: stat
path: /metrics
scheme: http
interval: 30s
- port: metrics
path: /metrics
scheme: https
interval: 30s
tlsConfig:
insecureSkipVerify: true
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
Using no authentication
To disable metrics authentication:
controller:
metricsAuth: none
serviceMonitor:
enabled: true
endpoints:
- port: stat
path: /metrics
scheme: http
interval: 30s
- port: metrics
path: /metrics
scheme: http
interval: 30s
Using basic authentication
The Secret hug-metrics-basic-auth (keys username and password) is not created by the chart; create it in the release namespace first.
controller:
metricsAuth: basic
extraArgs:
- --metrics-basic-auth-user=prometheus
- --metrics-basic-auth-password=secret
serviceMonitor:
enabled: true
endpoints:
- port: stat
path: /metrics
scheme: http
interval: 30s
- port: metrics
path: /metrics
scheme: https
interval: 30s
tlsConfig:
insecureSkipVerify: true
basicAuth:
username:
name: hug-metrics-basic-auth
key: username
password:
name: hug-metrics-basic-auth
key: password
To keep the password out of the pod arguments, the controller also reads the credentials from the METRICS_BASIC_AUTH_USER and METRICS_BASIC_AUTH_PASSWORD environment variables; set them from the same Secret instead of the two extraArgs:
controller:
extraEnvs:
- name:
Deploy haproxy-unified-gateway with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has haproxy-unified-gateway on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the charthaproxy-unified-gateway is pinned at v1.4.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply