Services
On Unikraft Cloud, all of your instances, when created, are given a private IP address and private FQDN, so you can immediately (inter)connect them. Connecting them to the Internet is done through a service: you simply create a service and attach your instance(s) to it.
A service is a description of how to reach a group of instances from the outside world. It describes a port mapping from the external FQDN port to an internal port common to all instances. The platform will load balance the incoming connections to the individual instances. As a result, always make sure not to place apps of different types/ports in the same service.
If you've used the kraft cloud deploy
command, you may have noticed that part of the output lists a service, e.g.:
Since kraft cloud deploy
is a single command to have a service deployed, it automatically creates a service and attaches the instance just created to it.
The rest of this guide shows how to create a service first, and then use kraft cloud deploy
to create and attach instances to it.
First, let's start by creating a new service; we can do so by using the kraft cloud service
command:
Here we created a new service called my-service
listening on port 443.
Unikraft Cloud will terminate TLS and send HTTP to port 8080, i.e., this example will assume that the app will open port 8080.
Now let's use kraft cloud deploy
with the --service
flag to ask kraft
to attach the instance to our my-service
service.
For example, if we take the Go web server guide (see all guides here):
This will create a new Go web server instance and immediately attach it to the my-service
service.
The output shows the instance URL and other details:
In this case, the instance name is http-go121-fkt1x
and the URL is https://my-service-rrtckyyi.fra0.kraft.host
.
They are different for each run.
Use curl
to query the Go web server from the Internet:
If you use the -p
option and specify a port when using kraft cloud deploy
the command will automatically create a service for you.
The difference between this and creating it explicitly via kraft cloud service
is that in the former (with deploy
) the service will automatically be deleted when the instance is deleted (and you cannot define the service's name).
That's it!
In the end, if you want to remove a service, use:
Learn More
- The
kraft cloud
CLI reference, and in particular the services sub-command - Unikraft Cloud's REST API reference, and in particular the section on services