kubernetes-ingress
A Helm chart for HAProxy Kubernetes Ingress Controller
About this chart
HAProxy Kubernetes Ingress Controller
An ingress controller is a Kubernetes resource that routes traffic from outside your cluster to services within the cluster. HAProxy Kubernetes Ingress Controller uses ConfigMap to store the haproxy configuration.
Detailed documentation can be found within the Official Documentation, including installing with Helm.
Additional configuration details can be found in the Ingress annotation reference, the ConfigMap options reference and the controller startup arguments reference.
Introduction
This chart bootstraps an HAProxy kubernetes-ingress deployment/daemonset on a Kubernetes cluster using the Helm package manager.
Prerequisites
- Kubernetes 1.23+ (recommended 1.24+)
- 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
Alternatively if you want to proceed with just OCI-based repository, skip this step and follow the installation with OCI.
Installing the chart
To install the chart as my-release deployment from the Chart Repository:
helm install my-release haproxytech/kubernetes-ingress
Alternatively also have OCI-based repository available for simplified access (requires Helm 3.8+):
helm install my-release oci://ghcr.io/haproxytech/helm-charts/kubernetes-ingress
Installing with unique name
To auto-generate controller and its resources names when installing, use the following:
helm install haproxytech/kubernetes-ingress \
--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-ingress haproxytech/kubernetes-ingress \
--namespace prod \
--create-namespace \
--set controller.image.tag=SOMETAG \
--set controller.imageCredentials.registry=myregistry.domain.com \
--set controller.imageCredentials.username=MYUSERNAME \
--set controller.imageCredentials.password=MYPASSWORD
Alternatively, use a pre-configured (existing) imagePullSecret in the same namespace:
helm install my-ingress haproxytech/kubernetes-ingress \
--namespace prod \
--set controller.image.tag=SOMETAG \
--set controller.existingImagePullSecret=name-of-existing-image-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:
mylb.yaml:
controller:
kind: DaemonSet
ingressClass: haproxy
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 (compare to the previous example):
helm install my-ingress -f mylb.yaml haproxytech/kubernetes-ingress
A typical YAML file for TCP services looks like (provided that the TCP services ConfigMap "default/tcp" was created):
controller:
service:
tcpPorts:
- name: mysql
port: 3306
targetPort: 3306
extraArgs:
- --configmap-tcp-services=default/tcp
Installing as DaemonSet
Default controller mode is Deployment, but it is possible to use DaemonSet as well:
helm install my-ingress haproxytech/kubernetes-ingress \
--set controller.kind=DaemonSet
Installing in multi-ingress environment
It is also possible to set controller ingress class to be used in multi-ingress environments:
helm install my-ingress haproxytech/kubernetes-ingress \
--set controller.kind=DaemonSet \
--set controller.ingressClass=haproxy
NOTE: make sure your Ingress resources select the class with spec.ingressClassName: haproxy (the older kubernetes.io/ingress.class: haproxy annotation is deprecated).
Installing Gateway API support
Gateway API support can be installed and used with the controller. Supported features can be seen in the Ingress Controller documentation.
helm install my-ingress haproxytech/kubernetes-ingress \
--set controller.kubernetesGateway.enabled=true \
--set controller.kubernetesGateway.gatewayControllerName=haproxy.org/gateway-controller
NOTE: Gateway API is not part of the default k8s API so its CRDs need to be installed separately; see Enable the Gateway API.
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-ingress haproxytech/kubernetes-ingress \
--set controller.kind=DaemonSet \
--set controller.ingressClass=haproxy \
--set controller.service.type=LoadBalancer \
--set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-internal"="0.0.0.0/0" \
--set 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.
Installing with Horizontal Pod Autoscaler (HPA)
HPA automatically scales number of replicas in Deployment or Replication Controller and adjusts replica count for the controller:
helm install my-ingress haproxytech/kubernetes-ingress \
--set controller.autoscaling.enabled=true
Installing the ServiceMonitor
If you're using the Prometheus Operator, you can automatically install the ServiceMonitor definition in order to automate the scraping options according to your needs.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/kube-prometheus-stack \
--set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false \
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
helm install my-ingress haproxytech/kubernetes-ingress \
--set controller.serviceMonitor.enabled=true
Installing the PodMonitor
As an alternative to a ServiceMonitor you can use a PodMonitor, which targets the pods directly instead of using a service.
If you're using the Prometheus Operator, you can automatically install the PodMonitor definition in order to automate the scraping options according to your needs.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/kube-prometheus-stack \
--set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false \
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
helm install my-ingress haproxytech/kubernetes-ingress \
--set controller.podMonitor.enabled=true
Installing with Kubernetes Event-driven Autoscaling (KEDA)
KEDA is an improved scaling solution built on top of HPA which allows autoscaling criteria based on information from any event source including Prometheus metrics collected from HAProxy native Prometheus Exporter.
To enable KEDA, you will also need to install Prometheus Operator and ServiceMonitor enabled (serverAddress has to point at the prometheus-kube-prometheus-prometheus Service; the example assumes the Prometheus release below, installed in the default namespace):
mykeda.yaml:
controller:
kind: Deployment
serviceMonitor:
enabled: true
keda:
enabled: true
minReplicas: 1
maxReplicas: 5
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus-kube-prometheus-prometheus.default.svc:9090
metricName: haproxy_frontend_current_sessions
threshold: "100"
query: sum(rate(haproxy_frontend_current_sessions{proxy="http"}[2m]))
Note: Other options to trigger scaling can be found in Prometheus native exporter documentation, but some ideas are:
haproxy_process_idle_time_percenthaproxy_frontend_current_sessionshaproxy_backend_current_queue
And to install:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack \
--set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false \
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
kubectl create namespace keda
helm install keda kedacore/keda --namespace keda
helm install mytest haproxytech/kubernetes-ingress -f mykeda.yaml
Installing on Amazon Elastic Kubernetes Service (EKS)
By default AWS LB does not support mixed protocols (TCP and UDP) on the same port yet, resulting in the following error on deploy:
Error syncing load balancer: failed to ensure load balancer: mixed protocol is not supported for LoadBalancer
This issue can be easily fixed by disabling QUIC support (requires udp/443 listener) with the following:
helm install my-ingress haproxytech/kubernetes-ingress \
--set controller.service.type=LoadBalancer \
--set controller.service.enablePorts.quic=false
Installing on Azure Managed Kubernetes Service (AKS)
By default Azure LB sends probe to / and expects HTTP status codes of 200-399 to consider Pod healthy, which means probes end up on default HTTP backend returning HTTP 404 status code. Since v1.20 AKS service annotation service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path can be used to override health probe behaviour and we recommend using the following annotation on AKS to target /healthz endpoint for health probes:
helm install ...
--set controller.service.type=LoadBalancer \
--set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz
Configuration
The full set of supported values is defined in values.yaml, which is also the canonical source of inline documentation (every value carries a ## comment block explaining its purpose and linking the relevant Kubernetes docs). At any time you can dump the effective defaults for the version of the chart you have installed with:
helm show values haproxytech/kubernetes-ingress
helm show readme haproxytech/kubernetes-ingress
To override defaults, either pass a values file with -f my-values.yaml (recommended for anything non-trivial) or use --set key=value for one-offs. The tables below summarise every top-level key and its default in this chart version; helm show values above prints the defaults of the version you have installed.
Global / cluster-wide
| Key | Description | Default |
|---|---|---|
rbac.create | Create the ClusterRole + ClusterRoleBinding required by the controller. | true |
namespace.create | Create the namespaceOverride namespace from the chart (do not combine with helm install --create-namespace). Requires namespaceOverride; the release namespace (helm install -n) must already exist, as Helm stores the release there. | false |
namespaceOverride | Override .Release.Namespace for all rendered resources (useful in umbrella/combined charts). | unset |
nameOverride | Replace the chart name in generated resource names. | unset |
fullnameOverride | Replace the full generated name (<release>-<chart>) of all resources. | unset |
|
Deploy kubernetes-ingress with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kubernetes-ingress 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 chartkubernetes-ingress is pinned at v1.57.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