Skip to content

Latest commit

Β 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

README.md

Rust HTTP Server

This guide explains how to create and deploy a Rust app. To run this example, follow these steps:

  1. Install the CLI. Use the unikraft CLI or the legacy kraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the quick start.

    Note: The unikraft CLI is the current standard, while kraft is the legacy version. Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.

  2. Clone the examples repository and cd into the examples/httpserver-rust1.91 directory:

    git clone https://github.com/unikraft-cloud/examples
    cd examples/httpserver-rust1.91/

Make sure to log into Unikraft Cloud and pick a metro close to you. This guide uses fra (Frankfurt, πŸ‡©πŸ‡ͺ):

Using the unikraft CLI (Recommended)

unikraft login

or

Using the legacy kraft CLI

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

Using the unikraft CLI (Recommended)

unikraft build . --output <my-org>/httpserver-rust191:latest
unikraft run --metro fra \
  -m 384M \
  -p 443:8080/tls+http \
  --scale-to-zero policy=on,cooldown-time=1000 \
  --image <my-org>/httpserver-rust191:latest

or

Using the legacy kraft CLI

kraft cloud deploy \
  -M 384Mi \
  -p 443:8080/tls+http \
  --scale-to-zero on \
  --scale-to-zero-cooldown 1s \
  .

The output shows the instance address and other details:

Using the unikraft CLI (Recommended)

metro:        fra
name:         httpserver-rust191-pinzf
uuid:         8acb3d35-38ba-4929-81de-950340662c14
state:        starting
image:        <my-org>/httpserver-rust191
resources:
  memory:     384MiB
  vcpus:      1
service:
  uuid:       3bf42986-3032-1ff2-fe4d-2041db03b628
  name:       snowy-feather-k4pfgl8t
  domains:
  - fqdn:     snowy-feather-k4pfgl8t.fra.unikraft.app
networks:
- uuid:       d64344f4-e159-c7c3-7f1b-ba10bcc60f67
  private-ip: 10.0.2.53
  mac:        12:b0:1d:12:0e:46
timestamps:
  created:    just now

or

Using the legacy kraft CLI

[●] Deployed successfully!
 β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ name: httpserver-rust191-pinzf
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ uuid: 8acb3d35-38ba-4929-81de-950340662c14
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ metro: https://api.fra.unikraft.cloud/v1
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ state: starting
 β”œβ”€β”€β”€β”€β”€β”€β”€ domain: https://snowy-feather-k4pfgl8t.fra.unikraft.app
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ image: oci://unikraft.io/<my-org>/httpserver-rust191@sha256:7725556f4db01037438c08d5f934eabe89f33c172b4ae6c7424b3286351619e9
 β”œβ”€β”€β”€β”€β”€β”€β”€ memory: 384 MiB
 β”œβ”€β”€β”€β”€β”€β”€ service: snowy-feather-k4pfgl8t
 β”œβ”€ private fqdn: httpserver-rust191-pinzf.internal
 └─── private ip: 10.0.2.53

In this case, the instance name is httpserver-rust191-pinzf and the address is snowy-feather-k4pfgl8t.fra.unikraft.app. They're different for each run.

Use curl to query the Unikraft Cloud instance:

curl https://snowy-feather-k4pfgl8t.fra.unikraft.app
Hello, World!

You can list information about the instance by running:

Using the unikraft CLI (Recommended)

unikraft instances list
METRO  NAME                      STATE    IMAGE                        ARGS  MEMORY  VCPUS  FQDN                                     CREATED
fra    httpserver-rust191-pinzf  standby  <my-org>/httpserver-rust191        384MiB  1      snowy-feather-k4pfgl8t.fra.unikraft.app  2 minutes ago

or

Using the legacy kraft CLI

kraft cloud instance list
NAME                      FQDN                                     STATE    STATUS   IMAGE                                                     MEMORY   VCPUS  ARGS  BOOT TIME
httpserver-rust191-pinzf  snowy-feather-k4pfgl8t.fra.unikraft.app  standby  standby  oci://unikraft.io/<my-org>/httpserver-rust191@sha256:...  384 MiB  1            11.67 ms

When done, you can remove the instance:

Using the unikraft CLI (Recommended)

unikraft instances delete httpserver-rust191-pinzf

or

Using the legacy kraft CLI

kraft cloud instance remove httpserver-rust191-pinzf

Learn more

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

Using the unikraft CLI (Recommended)

unikraft --help

or

Using the legacy kraft CLI

kraft cloud --help

Or visit the CLI Reference or the legacy CLI Reference.