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:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/haproxy/
directory:
git clone https://github.com/kraftcloud/examplescd 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:
# Set Unikraft Cloud access tokenexport UKC_TOKEN=token# Set metro to Frankfurt, DEexport UKC_METRO=fra0
When done, invoke the following command to deploy this application on Unikraft Cloud:
kraft cloud deploy -p 443:8404 -M 256 .
The output shows the instance URL and other details:
[β] 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:
kraft cloud instance list
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIMEhaproxy-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:
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 argumentsDockerfile
: 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"]
FROM debian:bookworm AS build
RUN set -xe; \ echo "Your code here";
FROM scratch
# Copy your files here# COPY --from=build / /
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
kraft cloud --help
Or visit the CLI Reference.