haproxy

by Helm

Helm chartv2.7.2App 2.7.3

A Helm chart for HAProxy which can be customized by a config map.

About this chart

haproxy

A Helm chart for HAProxy which can be customized by a config map.

Installation

helm repo add appuio https://charts.appuio.ch
helm install haproxy appuio/haproxy

Introduction

The Debian based image was choosen because it already contains the ca-certificates which makes it easy to use HAProxy as a reverse TLS Proxy.

Configuration

The configuration of HAProxy is derived through a configmap which in turn can be configured by adjusting the corresponding values in values.yaml. The present example is a configmap to configure HAProxy as a TLS reverse proxy to communicate with an LDAP backend. For different purposes you can create your own configmap and values.

General parameters

ParameterDescriptionDefault
replicaCountNumber of replicas for the proxy.1
image.registryRegistry of the imagedocker.io
image.repositoryRepository of the imagehaproxytech/haproxy-debian
image.tagTag of the image2.7.3
image.pullPolicyDetermines when the image is pulledIfNotPresent
ingress.enabledIf an ingress object should be createdfalse
ingress.annotationsAnnotations to set on the ingress object
ingress.hostsArray of host names which the ingress should resolve
ingress.tls.enabledIf TLS should be enabled on the ingress
ingress.tls.secretNameName of the secret containing the TLS certificate and key
service.portKubernetes Service port (haproxy)30636
service.typeKubernetes Service type (haproxy)ClusterIP
service.additionalPortsAdditional Ports to be added to the haproxy service (e.g. for sidecars)[]
sidecarContainersExtra sidecar containers to add to the deployment[]
affinityAffinity for pod assignment{} (evaluated as a template)
haproxy.frontendPortPort for the Proxy to listen on the frontend30636
haproxy.configSuffix of the used config-mapldap-tls
haproxy.check.existingSecret.nameUse existing secret with authentication credentials for check commands.
haproxy.check.existingSecret.keyKey in secret which contains the authentication credentials for the check commandauth-credentials
haproxy.securityContextSecurity context for the pod to be used{}
nodeSelectorPod node selector{}
tolerationsPod tolerations[]
affinityPod affinity rules{}
podDisruptionBudget.createIf true, create a pod disruption budget for pods.true
podDisruptionBudget.minAvailableMinimum number / percentage of pods that should remain schedulednil
podDisruptionBudget.maxUnavailableMaximum number / percentage of pods that may be made unavailable1
resourcesHAProxy resource requests/limits{ limits: { cpu: 100m, memory: 128Mi }, requests: { cpu: 100m, memory 128Mi } }

Metrics

ParameterDescriptionDefault
metrics.enabledEnables /stats and /metrics endpoint in haproxytrue
metrics.serviceMonitor.enabledIf true, creates a Prometheus Operator ServiceMonitor (also requires metrics.enabled to be true)false
metrics.serviceMonitor.namespaceOptional namespace which Prometheus is running in
metrics.serviceMonitor.intervalHow frequently to scrape metrics (use by default, falling back to Prometheus' default)
metrics.serviceMonitor.selectorDefault to kube-prometheus install (CoreOS recommended), but should be set according to Prometheus install{ prometheus: kube-prometheus }
metrics.serviceMonitor.relabelingsServiceMonitor relabelings. Value is evaluated as a template[]
metrics.serviceMonitor.metricRelabelingsServiceMonitor metricRelabelings. Value is evaluated as a template[]
metrics.service.typeKubernetes Service type (haproxy metrics)ClusterIP
metrics.service.annotationsAnnotations for the metrics service{}
metrics.service.labelsAdditional labels for the metrics service{}
metrics.service.loadBalancerIPLoadBalancer IP if haproxy metrics service type is LoadBalancer{}
metrics.prometheusRule.enabledSet this to true to create prometheusRules for Prometheus operatorfalse
metrics.prometheusRule.additionalLabelsAdditional labels that can be used so prometheusRules will be discovered by Prometheus{}
metrics.prometheusRule.namespaceNamespace where prometheusRules resource should be createdSame namespace as haproxy
metrics.prometheusRule.rulesRules to be created, check values for an example.[]

ldap-tls

Set haproxy.config to ldap-tls to use the LDAP TLS configuration (default).

ParameterDescriptionDefault
haproxy.ldapTls.backendService the proxy should connect to
haproxy.ldapTls.certificatePathPath to the corresponding root-certificate/etc/ssl/certs/ca-certificates.crt

galera

Set haproxy.config to galera to use the Galera configuration.

ParameterDescriptionDefault
haproxy.galera.balanceWhat balance mode HAProxy should usesource
haproxy.galera.timeout.connectSet the maximum time to wait for a connection attempt to a server to succeed.5s
haproxy.galera.timeout.clientThe inactivity timeout applies when the client is expected to acknowledge or send data10800s
haproxy.galera.timeout.serverThe inactivity timeout applies when the server is expected to acknowledge or send data10800s
haproxy.galera.check.enabledIf check should be enabledtrue
haproxy.galera.check.mysql.enabledIf mysql-check should be enabled (requires check.enabled)true
haproxy.galera.check.mysql.userThe database user to use for mysql-checkhaproxy
haproxy.galera.nodesList of Galera nodes[]
haproxy.galera.nodes.addressAddress of the Galera node
haproxy.galera.nodes.portPort of the Galera node3306
haproxy.galera.nodes.backupIf this node should be used as a backup nodetrue
haproxy.galera.metrics.enabledIf the metric endpoint of the Galera backends should be exposed in haproxyfalse
haproxy.galera.metrics.exposeLoadbalancerIf the metric endpoint of the Galera backends should be exposed in the haproxy servicetrue

To use mysql-check, configure a user haproxy in the database (see: http://cbonte.github.io/haproxy-dconv/1.9/configuration.html#4-option%20mysql-check for more information).

galerak8s

Set haproxy.config to galerak8s to use the Galera configuration with DNS service discovery. See https://www.haproxy.com/de/blog/dns-service-discovery-haproxy/

ParameterDescriptionDefault
haproxy.galerak8s.balanceWhat balance mode HAProxy should usefirst
haproxy.galerak8s.timeout.connectSet the maximum time to wait for a connection attempt to a server to succeed.5s
haproxy.galerak8s.timeout.clientThe inactivity timeout applies when the client is expected to acknowledge or send data10800s
haproxy.galerak8s.timeout.serverThe inactivity timeout applies when the server is expected to acknowledge or send data10800s
haproxy.galerak8s.check.enabledIf check should be enabledtrue
haproxy.galerak8s.check.mysql.enabledIf mysql-check should be enabled (requires check.enabled)true
haproxy.galerak8s.check.mysql.userThe database user to use for mysql-checkhaproxy
haproxy.galerak8s.dnsservicenameThe DNS Record for service discoverymycluster-mariadb-galera-headless
haproxy.galerak8s.nodeCountMax number of nodes in the backend3
haproxy.galerak8s.portPort of the Galera node3306
haproxy.galerak8s.metrics.enabledIf the metric endpoint of the Galera backends should be exposed in haproxyfalse
haproxy.galerak8s.metrics.exposeLoadbalancerIf the metric endpoint of the Galera backends should be exposed in the haproxy servicetrue

mariadbOperator

Set haproxy.config to mariadbOperator to use the mariadb-operator configuration with DNS service discovery. See https://www.haproxy.com/de/blog/dns-service-discovery-haproxy/

ParameterDescriptionDefault
haproxy.mariadbOperator.balanceWhat balance mode HAProxy should usefirst
haproxy.mariadbOperator.timeout.connectSet the maximum time to wait for a connection attempt to a server to succeed.5s
haproxy.mariadbOperator.timeout.clientThe inactivity timeout applies when the client is expected to acknowledge or send data10800s
haproxy.mariadbOperator.timeout.serverThe inactivity timeout applies when the server is expected to acknowledge or send data10800s
haproxy.mariadbOperator.check.enabledIf check should be enabledtrue
haproxy.mariadbOperator.check.mysql.enabledIf mysql-check should be enabled (requires check.enabled)true
haproxy.mariadbOperator.check.mysql.userThe database user to use for mysql-checkhaproxy
haproxy.mariadbOperator.dnsservicenameThe DNS Record for service discoverymycluster-mariadb-galera-headless
haproxy.mariadbOperator.nodeCountMax number of nodes in the backend3
haproxy.mariadbOperator.portPort of the Galera node3306
haproxy.mariadbOperator.metrics.enabledIf the metric endpoint of the Galera backends should be exposed in haproxyfalse

redisk8s

Set haproxy.config to redisk8s to use the Redis configuration with DNS service discovery. See https://www.haproxy.com/de/blog/dns-service-discovery-haproxy/

ParameterDescriptionDefault
haproxy.redisk8s.timeout.connectSet the maximum time to wait for a connection attempt to a server to succeed.5s
haproxy.redisk8s.timeout.clientThe inactivity timeout applies when the client is expected to acknowledge or send data60s
haproxy.redisk8s.timeout.serverThe inactivity timeout applies when the server is expected to acknowledge or send data60s
haproxy.redisk8s.check.enabledIf check should be enabledtrue
haproxy.redisk8s.check.redis.authAuthentication credentials for Redis. haproxy.check.existingSecret overwrites this
haproxy.redisk8s.dnsservicenameThe DNS Record for service discoveryredis-access-headless
haproxy.redisk8s.nodeCountMax number of nodes in the backend3
haproxy.redisk8s.portPort of the Galera node6379
haproxy.redisk8s.metrics.enabledIf the metric endpoint of the Redis backends should be exposed in haproxyfalse
haproxy.redisk8s.metrics.exposeLoadbalancerIf the metric endpoint of the Redis backends should be exposed in the haproxy servicetrue

filterproxy

ParameterDescriptionDefault
haproxy.filterproxy.enabledEnables exposing an exporter-filterproxy that will be filtered based on the namespacefalse
haproxy.filterproxy.urlThe URL of the exporter-filterproxy to expose""

Galera and Redis metrics

By setting the haproxy.galerak8s.metrics.enabled or haproxy.redisk8s.metrics.enabled parameters, you can expose the metrics of the backend pods.

For Galera the endpoints are either:

  • <haproxy_service_ip>:9090/mariadb/0
  • <haproxy_service_ip>:9090/mariadb/1
  • ...

Or:

  • mariadb-0.example.com:9090/metrics
  • mariadb-1.example.com:9090/metrics
  • ...

When mariadb-<nr>.example.com resolves to the haproxy service IP.

For Redis the endpoints are either:

  • <haproxy_service_ip>:9090/redis/0
  • <haproxy_service_ip>:9090/redis/1
  • ...

Or:

  • redis-0.example.com:9090/metrics
  • redis-1.example.com:9090/metrics
  • ...

When redis-<nr>.example.com resolves to the haproxy service IP.

Deploy haproxy with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has haproxy 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.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the charthaproxy is pinned at v2.7.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. 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