Skip to content

Connect your App to the Outside World

On KraftCloud, 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 service groups: you simply create a service group an attach your instance(s) to it, as shown in this diagram:

Service groups in KraftCloud

If you’ve used the kraft cloud deploy command, you may have noticed that part of the output lists a service group, e.g.:

Terminal window
service group: frosty-sky-vz8kwsm

Since kraft cloud deploy is a single command to have a service deployed, it automatically creates a service group and attaches the instance just created to it. The rest of this guide shows how to create a service group first, and then use kraft cloud deploy to create and attach instances to it.

First, let’s start by creating a new service group; we can do so by using the kraft cloud service command:

Terminal window
kraft cloud service create --name my-service 443:8080/http+tls

Here we created a new service group called my-service listening on port 443. KraftCloud 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-group flag to ask kraft to attach the instance to our my-service service group. For example, if we take the Go web server guide (see all guides here):

Terminal window
git clone https://github.com/kraftcloud/examples
cd examples/http-go1.21/
kraft cloud deploy --service-group my-service .

This wiill create a new Go web server instance and immeidately attach it to the my-service service group. The output shows the instance URL and other details:

Terminal window
[] Deployed successfully!
────────── name: http-go121-fkt1x
────────── uuid: 858da707-1851-46cb-9667-05b951471222
───────── state: running
─────────── url: https://my-service-rrtckyyi.fra0.kraft.host
───────── image: http-go121@sha256:4d536236d226781874c3ad930dbc936c4f407aa3483a1f8e961ba63a7a72c78d
───── boot time: 17.14 ms
──────── memory: 128 MiB
service group: my-service
── private fqdn: http-go121-fkt1x.internal
──── private ip: 172.16.6.6
────────── args: /server

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:

Terminal window
curl https://my-service-rrtckyyi.fra0.kraft.host
hello, world!

That’s it!

In the end, if you want to remove a service, use:

Terminal window
kraft cloud service remove my-service

Learn More

  • The kraft cloud CLI reference, and in particular the services sub-command.
  • KraftCloud’s REST API reference, and in particular the section on service groups.