### FastCGI config-sections example Source: https://haproxy-ingress.github.io/docs/configuration/keys Example of configuring multiple fcgi-app sections via the global config-sections key. Each section defines a FastCGI application with log-stderr, docroot, and index settings. ```yaml config-sections: | fcgi-app app1 log-stderr global docroot /var/www/app1 index index.php fcgi-app app2 log-stderr global docroot /var/www/app2 index index.php ... (other custom haproxy sections) ``` -------------------------------- ### Install kube-prometheus-stack with Helm Source: https://haproxy-ingress.github.io/docs/examples/metrics Installs the kube-prometheus-stack chart in the monitoring namespace, using the custom values file. The backslash line continuation is part of the command. ```bash helm upgrade prometheus prometheus-community/kube-prometheus-stack\ --install\ --create-namespace --namespace monitoring\ -f prometheus-operator-values.yaml ``` -------------------------------- ### Install or upgrade HAProxy Ingress with values file Source: https://haproxy-ingress.github.io/docs/examples/external-haproxy Installs or upgrades HAProxy Ingress in the ingress-controller namespace using the haproxy-ingress-values.yaml parameters. ```bash $ helm upgrade haproxy-ingress haproxy-ingress/haproxy-ingress\ --install --create-namespace --namespace=ingress-controller\ -f haproxy-ingress-values.yaml ``` -------------------------------- ### Install or upgrade HAProxy Ingress Helm chart Source: https://haproxy-ingress.github.io/docs/examples/metrics Run this command to install or upgrade the HAProxy Ingress chart with the provided values file. It creates the ingress-controller namespace if needed and uses the haproxy-ingress-values.yaml file. ```bash helm upgrade haproxy-ingress haproxy-ingress/haproxy-ingress\ --install\ --create-namespace --namespace ingress-controller\ -f haproxy-ingress-values.yaml ``` -------------------------------- ### ConfigMap: config-peers example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to the Peers section. ```yaml config-peers: | log stdout format raw local0 ``` -------------------------------- ### ConfigMap: config-frontend-early example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to the HTTP and HTTPS frontend sections, before any builtin logic. ```yaml config-frontend-early: | tcp-request connection reject if !{ src 10.0.0.0/8 } ``` -------------------------------- ### Annotation: config-backend-early example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to a HAProxy backend section, before any builtin logic. ```yaml annotations: haproxy-ingress.github.io/config-backend-early: | stick-table type ip size 100k expire 1m store http_req_rate(10s) http-request track-sc1 src http-request deny if { sc1_http_req_rate gt 100 } # average of 10rps per source IP, over the last 10s ``` -------------------------------- ### ConfigMap: config-tcp example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to the ConfigMap based TCP sections. ```yaml config-tcp: | tcp-request content reject if !{ src 10.0.0.0/8 } ``` -------------------------------- ### Deploy redis deployment and service Source: https://haproxy-ingress.github.io/docs/configuration/gateway-api Creates the redis deployment and service for the TCP workload example. ```bash $ kubectl --namespace default create deployment redis --image docker.io/redis $ kubectl --namespace default expose deployment redis --port=6379 ``` -------------------------------- ### ConfigMap: config-frontend-late example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to the HTTP and HTTPS frontend sections, same as config-frontend. ```yaml config-frontend-late: | capture request header X-User-Id len 32 ``` -------------------------------- ### Create a service with selector run=bluegreen Source: https://haproxy-ingress.github.io/docs/examples/blue-green Exposes a deployment named 'blue' as a service named 'bluegreen' with selector 'run=bluegreen'. The output shows the service was created and the selector is set to 'map[run:bluegreen]'. ```bash $ kubectl expose deploy blue --name bluegreen --selector=run=bluegreen service "bluegreen" exposed $ kubectl get svc bluegreen -otemplate --template '{{.spec.selector}}' map[run:bluegreen] ``` -------------------------------- ### Install HAProxy Ingress with Helm Source: https://haproxy-ingress.github.io/docs/getting-started Installs or upgrades HAProxy Ingress using the release name haproxy-ingress and the custom values file. The --install flag creates a new deployment if missing, or performs a rolling update if already installed. The --version flag ensures a specific version is installed. ```bash $ helm upgrade haproxy-ingress haproxy-ingress/haproxy-ingress\ --install\ --create-namespace --namespace ingress-controller\ --version 0.16.1\ -f haproxy-ingress-values.yaml ``` -------------------------------- ### Run `hareq` with balance blue=1, green=2 Source: https://haproxy-ingress.github.io/docs/examples/blue-green Executes `hareq` after setting the balance to blue=1, green=2. With BG Mode `deploy`, the output shows 33 blue and 67 green responses. ```bash $ hareq Running 100 requests... 33 blue 67 green ``` -------------------------------- ### Check app pods Source: https://haproxy-ingress.github.io/docs/examples/metrics Watch the pods of the demo application to confirm they are running. ```bash kubectl --namespace default get pod -lapp=dory -w ``` -------------------------------- ### Install Gateway API CRDs Source: https://haproxy-ingress.github.io/docs/configuration/gateway-api Manually installs the Gateway API CRDs using kubectl apply. Required before HAProxy Ingress can manage Gateway API resources. ```bash $ kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/experimental-install.yaml ``` -------------------------------- ### Install Gateway API CRDs Source: https://haproxy-ingress.github.io/docs/configuration/gateway-api Install the Gateway API CRDs from the experimental channel using kubectl. v1.0.0 is a reference for a fresh deployment; Gateway API v0.4.0 or newer is supported. ```bash kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/experimental-install.yaml ``` -------------------------------- ### Run `hareq` after scaling green to 3 replicas in pod mode Source: https://haproxy-ingress.github.io/docs/examples/blue-green Executes `hareq` after scaling green to 3 replicas. With BG Mode `pod` and balance blue=1, green=1, the output shows 25 blue and 75 green responses. ```bash $ hareq Running 100 requests... 25 blue 75 green ``` -------------------------------- ### Run `hareq` with pod mode and blue=1, green=1 Source: https://haproxy-ingress.github.io/docs/examples/blue-green Executes the `hareq` alias to send 100 requests. With BG Mode `pod` and balance blue=1, green=1, the output shows 50 blue and 50 green responses. ```bash $ hareq Running 100 requests... 50 blue 50 green ``` -------------------------------- ### HAProxy Ingress headers annotation example Source: https://haproxy-ingress.github.io/docs/configuration/keys Example of configuring the 'headers' backend key via an annotation. The value is a multi-line string with header name and value separated by a colon. Variables like %[service] and %[namespace] can be used in the value. ```yaml annotations: haproxy-ingress.github.io/headers: | x-path: / host: %[service].%[namespace].svc.cluster.local ``` -------------------------------- ### Deploy demo application and certificate Source: https://haproxy-ingress.github.io/docs/examples/metrics Commands to generate a self-signed certificate, create a TLS secret, deploy a demo app, scale it, expose it, and create an ingress with the HAProxy class. ```bash openssl req -x509 -subj "/CN=dory.localdomain" -nodes -days 30 -newkey rsa:2048 -keyout /tmp/h.key -out /tmp/h.crt kubectl --namespace default create secret tls dory --cert /tmp/h.crt --key /tmp/h.key rm -fv /tmp/h.crt /tmp/h.key kubectl --namespace default create deploy dory --image jcmoraisjr/dory kubectl --namespace default scale deploy dory --replicas=4 kubectl --namespace default expose deploy dory --port 8000 kubectl --namespace default create ingress dory\ --class=haproxy\ --annotation haproxy-ingress.github.io/ssl-redirect=false\ --rule="dory.localdomain/*=dory:8000,tls=dory" ``` -------------------------------- ### tcp-services-configmap example: ConfigMap data with TCP service definitions Source: https://haproxy-ingress.github.io/docs/configuration/command-line Example ConfigMap data for the --tcp-services-configmap argument. Each key is the HAProxy port, and the value is a colon-separated list: /::::::. Optional fields can be skipped using consecutive colons. The example shows seven port mappings with various configurations, including PROXY protocol settings, SSL offload, and check intervals. ```yaml ... data: "3306": "default/mysql:3306::::-" "5432": "default/pgsql:5432::::1s" "8000": "system-prod/http:8000::PROXY-V1" "9900": "system-prod/admin:9900:PROXY::system-prod/tcp-9900" "9990": "system-prod/admin:9999::PROXY-V2" "9995": "system-prod/admin:9900:::system-prod/tcp-9995::system-prod/tcp-9995-ca" "9999": "system-prod/admin:9999:PROXY:PROXY" ``` -------------------------------- ### Start external HAProxy with master socket and config file Source: https://haproxy-ingress.github.io/docs/configuration/command-line Required flags to start the external HAProxy: -S /var/run/haproxy/master.sock,mode,600 (mode 600 recommended but not mandatory) and -f /etc/haproxy. These flags are part of the prerequisites for using --master-socket. ```bash -S /var/run/haproxy/master.sock,mode,600 ``` ```bash -f /etc/haproxy ``` -------------------------------- ### Set up IP and alias `hareq` for blue/green test Source: https://haproxy-ingress.github.io/docs/examples/blue-green Sets the HAProxy Ingress controller IP and defines a shell alias `hareq` that sends 100 requests to the `bluegreen.example.com` host and counts the responses by the first field (blue or green). Change `IP` to your controller's IP address. ```bash $ IP=192.168.100.99 $ alias hareq='echo Running 100 requests...; for i in `seq 1 100`; do curl -fsS $IP -H "Host: bluegreen.example.com" | cut -d- -f1 done | sort | uniq -c' ``` -------------------------------- ### Annotation: config-tcp-service example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to a TCP service section. ```yaml annotations: haproxy-ingress.github.io/config-tcp-service: | timeout client 1m timeout connect 15s ``` -------------------------------- ### ConfigMap example for global configuration Source: https://haproxy-ingress.github.io/docs/configuration/keys Shows a ConfigMap with global configuration keys. Keys are used verbatim as ConfigMap key names. Values must be strings; numbers and booleans are converted by HAProxy Ingress. ```yaml apiVersion: v1 data: balance-algorithm: leastconn max-connections: "10000" ssl-redirect: "true" kind: ConfigMap metadata: name: haproxy-ingress namespace: ingress-controller ``` -------------------------------- ### Annotation: config-backend-late example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to a HAProxy backend section, same as config-backend. ```yaml annotations: haproxy-ingress.github.io/config-backend-late: | http-request deny if { path /internal } ``` -------------------------------- ### ConfigMap: config-defaults example Source: https://haproxy-ingress.github.io/docs/configuration/keys Adds a configuration snippet to the end of the HAProxy defaults section. ```yaml config-defaults: | option redispatch ```