Skip to content

Deploy HAProxy

This guides shows you how to use HAProxy, a free and open source software that provides a high availability load balancer and reverse proxy for TCP and HTTP-based applications that spreads requests across multiple servers.

To run this example, follow these steps:

  1. Install the kraft CLI tool and a container runtime engine, e.g. Docker.

  2. Clone the examples repository and cd into the examples/haproxy/ directory:

Terminal window
git clone https://github.com/kraftcloud/examples
cd examples/haproxy/

Make sure to log into Unikraft Cloud by setting your token and a metro close to you. We use fra0 (Frankfurt, πŸ‡©πŸ‡ͺ) in this guide:

Terminal window
# Set Unikraft Cloud access token
export UKC_TOKEN=token
# Set metro to Frankfurt, DE
export UKC_METRO=fra0

When done, invoke the following command to deploy this application on Unikraft Cloud:

Terminal window
kraft cloud deploy -p 443:8404 -M 256 .

The output shows the instance URL and other details:

Terminal window
[●] Deployed successfully!
β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ name: haproxy-rfx6z
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ uuid: 09bd081e-e082-4f73-8ba8-531123a39e2e
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ state: running
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ url: https://cool-paper-svzzr3qq.fra0.kraft.host
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ image: haproxy@sha256:32296847231c151506820ec4914c1d7416e5b7200caf07c1e40eaa3ea5033d21
β”œβ”€β”€β”€β”€β”€ boot time: 26.60 ms
β”œβ”€β”€β”€β”€β”€β”€β”€β”€ memory: 256 MiB
β”œβ”€β”€β”€β”€β”€β”€β”€ service: cool-paper-svzzr3qq
β”œβ”€β”€ private fqdn: haproxy-rfx6z.internal
β”œβ”€β”€β”€β”€ private ip: 172.16.6.5
└────────── args: /usr/bin/haproxy -f /etc/haproxy/haproxy.conf

In this case, the instance name is haproxy-rfx6z and the URL is https://cool-paper-svzzr3qq.fra0.kraft.host. They are different for each run.

To test, point your browser at the /stats endpoint (e.g., https://cool-paper-svzzr3qq.fra0.kraft.host/stats).

At any point in time, you can list information about the instance:

Terminal window
kraft cloud instance list
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIME
haproxy-rfx6z cool-paper-svzzr3qq.fra0.kraft... running 1 minute ago haproxy@sha256:32296847231c1515... 256 MiB /usr/bin/haproxy -f /etc/hapro... 26596us

When done, you can remove the instance:

Terminal window
kraft cloud instance remove haproxy-rfx6z

Customize your Application

To customize the application, update the files in the repository, listed below:

  • Kraftfile: the Unikraft Cloud specification, including command-line arguments
  • Dockerfile: In case you need to add files to your instance’s rootfs
spec: v0.6
runtime: haproxy:latest
rootfs: ./Dockerfile
cmd: ["/usr/bin/haproxy", "-f", "/etc/haproxy/haproxy.conf"]

Learn More

Use the --help option for detailed information on using Unikraft Cloud:

Terminal window
kraft cloud --help

Or visit the CLI Reference.