Adding a custom HAProxy endpoint in TripleO
by Juan Antonio Osorio Robles
Typically, when you want to add a new service to TripleO, there’s a bunch of files you need to touch, both in tripleo-heat-templates and some puppet code too.
Unfortunately this has made it quite tedious to add new services to TripleO, as you need to modify puppet-tripleo’s haproxy manifest to add your service.
A while ago, I thought to add a clever nice trick, so you could do this dynamically via hieradata. This code stayed there for a while without a lot of people putting attention to it. And wrongly, I also didn’t document it. But what this gives you is that you now don’t need to touch puppet at all to enable a new endpoint in HAProxy.
So, in your service template’s service_config_settings
section, you’ll need
to add the following:
Here, service_config_settings
is used because we specifically want to add
this hieradata to nodes that deploy haproxy.
In this example, my_service_name
is the service_name
from the service
template. It has to match in order for the resource to properly fill the
ip_addresses
and service_names
parameters. Else, you’ll have to
manually set up the needed values to fill those parameters.
Also, it is important to know that, if you added your service to the
ServiceNetMap
(which you can add by passing your service via that parameter
in heat), there will be some hiera keys enabled for you. For instance, lets say
that you added a service entry as follows:
This would mean that you added your service to run on the internal API network
in TripleO. Thus, you’ll get a hiera key called my_service_name_vip
, which
will have the value of the Virtual IP associated to the internal API network.
To know and take better use of all the available options, I recommend reading the puppet resource’s code that actually creates the HAProxy endpoint.
It is also important to note that TripleO already fills up some defaults for your application:
From these, it is important to know that the certificates will be filled up for you, so you don’t need to add them.
Stein update
There are some services that need two or more endpoints, for these, it’s not
possible to make the endpoints’ names match the service_name
parameter. For
these cases, I added the base_service_name
parameter.
By setting base_service_name
to match the service_name
of the service
you want to load balance, the ip_addresses
and the server_names
parameters will be filled out auto-magically. This makes it easier to add
customized endpoints to load balance your service.
Lets take an example from the following patch, which adds
HAProxy endpoints to load balance OpenShift’s infra endpoints. This adds two
endpoints in HAProxy, which will listen on specific ports, and forward the
traffic towards the nodes that contain the openshift_infra
service.
tags: tripleo - openstack