New to Voyager? Please start here.

Using Custom HAProxy Templates

Since 3.2.0, Voyager can use custom templates provided by users to render HAProxy configuration. Voyager comes with a set of GO text/templates found here. These templates are mounted at /srv/voyager/templates. You can mount a ConfigMap with matching template names when installing Voyager operator to a different location and pass that to Voyager operator using --custom-templates flag. Voyager will load the built-in templates first and then load any custom templates if provided. As long as the custom templates have same name as the built-in templates, custom templates will be used render HAProxy config. You can overwrite any number of templates as you wish. Also note that templates are loaded when Voyager operator starts. So, if you want to reload custom templates, you need to restart the running Voyager operator pod (not HAProxy pods).

In this example, we are going to overwrite the defaults.cfg template which is used to render the defaults section of HAProxy config.

$ cat /tmp/defaults.cfg

defaults
	log global

	# my custom template
	# https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-option%20abortonclose
	option dontlog-normal
	log /dev/log local0 notice alert
	option dontlognull
	option http-server-close

	# Timeout values
	timeout client 5s
	timeout client-fin 5s
	timeout connect 5s
	timeout server 5s
	timeout tunnel 5s

	# default traffic mode is http
	# mode is overwritten in case of tcp services
	mode http

Now create a ConfigMap using the defaults.cfg as key and the file content as the value.

$ kubectl create configmap -n voyager voyager-templates --from-file=/tmp/defaults.cfg

Now, the ConfigMap voyager-templates has to be mounted in the voyager operator pod and --custom-templates flag has to be set. To do this, set templates.cfgmap value to Voyager operator chart.

$ helm install voyager oci://ghcr.io/appscode-charts/voyager \
  --version v2024.8.30 \
  --namespace voyager --create-namespace \
  --set cloudProvider=minikube \
  --set templates.cfgmap=voyager-templates \
  --wait --burst-limit=10000 --debug

installer

This will restart the Voyager operator pods. After start, Voyager pod will update any existing HAProxy configuration to the new templates.