Installation
Installation on Ubuntu
HAProxy is available in most Linux distributions, but default package versions are often outdated.
Fortunately, the HAProxy team maintains an official package repository that provides up-to-date and supported versions for easy installation on Ubuntu.
Install the PPA by running the following commands:
sudo apt-get install -y --no-install-recommends software-properties-common
sudo add-apt-repository -y ppa:vbernat/haproxy-3.2
Install the haproxy package:
sudo apt-get install -y haproxy
Configuration
By default, HAProxy loads its configuration from a single file at /etc/haproxy/haproxy.cfg.
While this works well for simple setups, it's often a good idea to separate configurations for better organization and maintainability.
Fortunately, HAProxy makes this easy with a small configuration change:
echo 'CONFIG="/etc/haproxy"' | sudo tee -a /etc/default/haproxy
This configures the HAProxy service to load all .cfg files from the /etc/haproxy directory.
You can now start the service:
sudo systemctl enable --now haproxy
Other installation methods
As mentioned earlier, HAProxy is included in most Linux distributions, making it easy to install using the default package manager.
However, there are several other installation methods available. Let's take a quick look at some of them.
Container image
Of course, HAProxy is also available as an official container image:
docker run --rm haproxy
💡 Unlike Linux distribution packages, the official container image doesn't include a default configuration file.
You'll need to mount your own at /usr/local/etc/haproxy/haproxy.cfg.
Be sure to check the official documentation for additional configuration options and usage details.
NixOS
HAProxy is available on NixOS:
{
services.haproxy = {
enable = true;
config = ''
listen my_service
bind :80
server server-01 server-01:80 check
'';
};
}
See the NixOS option reference for more details and configuration options.
Kubernetes
HAProxy is available as an Ingress controller for Kubernetes and also supports the Gateway API, making it a powerful and flexible entry point for traffic into Kubernetes clusters.
Check out the official documentation to learn more about installation options.
- Previous lesson
- Introduction
- Next lesson
- Your First Load Balancer