Zudoku
Guides

HAProxy

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

To run this example, follow these steps:

  1. Install the kraft CLI tool and a container runtime engine, for example Docker.

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

Code(bash)
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. This guide uses fra (Frankfurt, ๐Ÿ‡ฉ๐Ÿ‡ช):

Code(bash)
# Set Unikraft Cloud access token export UKC_TOKEN=token # Set metro to Frankfurt, DE export UKC_METRO=fra

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

Code(bash)
kraft cloud deploy -p 443:8404 -M 256 .

The output shows the instance address and other details:

Code(ansi)
[โ—] Deployed successfully! โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ name: haproxy-rfx6z โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ uuid: 09bd081e-e082-4f73-8ba8-531123a39e2e โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ state: running โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ url: https://cool-paper-svzzr3qq.fra.unikraft.app โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 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 address is https://cool-paper-svzzr3qq.fra.unikraft.app. They're different for each run.

To test, point your browser at the /stats endpoint (for example, https://cool-paper-svzzr3qq.fra.unikraft.app/stats).

You can list information about the instance by running:

Code(bash)
kraft cloud instance list
Code(text)
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIME haproxy-rfx6z cool-paper-svzzr3qq.fra.unikraft.app running 1 minute ago haproxy@sha256:32296847231c1515... 256 MiB /usr/bin/haproxy -f /etc/hapro... 26596us

When done, you can remove the instance:

Code(bash)
kraft cloud instance remove haproxy-rfx6z

Customize your app

To customize the app, 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:

Code(bash)
kraft cloud --help

Or visit the CLI Reference.

Last modified on