Zudoku
Guides

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:

TerminalCode
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:

TerminalCode
# 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:

TerminalCode
kraft cloud deploy -p 443:8404 -M 256 .

The output shows the instance URL and other details:

TerminalCode
[โ—] 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:

TerminalCode
kraft cloud instance list
Code
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:

TerminalCode
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

Learn More

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

TerminalCode
kraft cloud --help

Or visit the CLI Reference.

Last modified on