Deploying Nex Services

There are a number of ways to deploy a service with Nex. For this guide we’ll cover the easiest option, devrun, which makes a number of assumptions about the fact that you’re running in a development environment. For all of the full production options, take a look at the reference section or read through the CLI’s extended help text.

Make sure that your node is still up and running by making sure that it’s still discoverable via nex:

  1. $ nex node ls
  2. ╭─────────────────────────────────────────────────────────────────────────────────────────╮
  3. NATS Execution Nodes
  4. ├──────────────────────────────────────────────────────────┬─────────┬────────┬───────────┤
  5. ID Version Uptime Workloads
  6. ├──────────────────────────────────────────────────────────┼─────────┼────────┼───────────┤
  7. NCOBPU3MCEA7LF6XADFD4P74CHW2OL6GQZYPPRRNPDSBNQ5BJPFHHQB5 0.0.1 10m15s 0
  8. ╰──────────────────────────────────────────────────────────┴─────────┴────────┴───────────╯

Sending a Deployment Request

We start services by issuing a deployment (which ends up being equivalent to “run” for services) request to a specific node. When we use the devrun command, the CLI makes it easy on us by choosing the first discovered node as the target.

The next thing we need on hand when calling devrun is the statically linked binary. Deploying workloads also requires a publisher key and an encryption xkey, but devrun will create both of those if you haven’t done so already.

As you saw, the echo service we built requires the NATS_URL environment variable. To start the echo service on the first available Nex node and supply an environment variable, issue the following command (your path to the echoservice file may differ):

  1. $ nex devrun ../examples/echoservice/echoservice nats_url=nats://192.168.127.1:4222
  2. Reusing existing issuer account key: /home/kevin/.nex/issuer.nk
  3. Reusing existing publisher xkey: /home/kevin/.nex/publisher.xk
  4. 🚀 Workload 'echoservice' accepted. You can now refer to this workload with ID: cmji29n52omrb71g07a0 on node NBS3Y3NWXLTFNC73XMVD6USFJF2H5QXTLEJQNOPEBPYDUDVB5YYYZOGI

There’s a couple of important pieces of information here. The first is that we’ve reused some existing keys. If this is your first time running a workload, you’ll see those two keys get created. Next, we see that we got an acknowledgement from the target node that included the machine/workload ID.

The address 192.168.127.1 is the IP address of the host (the network on which nex is running), as seen by any code running inside the firecracker VM (guest). We use this as a default because it makes things easy during development, but keep in mind that if you supply your own custom CNI configurations, the IP address that works in your environment may be different.

Let’s run the same commands we ran before to test out our service.

  1. $ nats micro ls
  2. ╭──────────────────────────────────────────────────────────────╮
  3. All Micro Services
  4. ├─────────────┬─────────┬────────────────────────┬─────────────┤
  5. Name Version ID Description
  6. ├─────────────┼─────────┼────────────────────────┼─────────────┤
  7. EchoService 1.0.0 NsMaTbN7u5ZPUNN47bSEI6
  8. ╰─────────────┴─────────┴────────────────────────┴─────────────╯

And we can test this service out the same way we did before:

  1. nats req svc.echo 'hey'
  2. 19:40:22 Sending request on "svc.echo"
  3. 19:40:22 Received with rtt 446.27µs
  4. hey

Now let’s interrogate a single execution node to see the workload there (again note that your node ID will differ from the one below):

  1. $ nex node info NBS3Y3NWXLTFNC73XMVD6USFJF2H5QXTLEJQNOPEBPYDUDVB5YYYZOGI
  2. NEX Node Information
  3. Node: NBS3Y3NWXLTFNC73XMVD6USFJF2H5QXTLEJQNOPEBPYDUDVB5YYYZOGI
  4. Xkey: XASQSWNSIKHM5MDKDOGPSPGBA3V6JMETMIJK2YTXKAJZNMAFKXER5RUK
  5. Version: 0.0.1
  6. Uptime: 8m47s
  7. Tags: nex.arch=amd64, nex.cpucount=8, nex.os=linux, simple=true
  8. Memory in kB:
  9. Free: 33,545,884
  10. Available: 56,529,644
  11. Total: 63,883,232
  12. Workloads:
  13. Id: cmji29n52omrb71g07a0
  14. Healthy: true
  15. Runtime: 8m47s
  16. Name: echoservice
  17. Description: Workload published in devmode

And just to prove that we’re not interfering with the way the workload executes at all, we can get the service stats and see that it is indeed still keeping track of request counts:

  1. $ nats micro info EchoService
  2. Service Information
  3. Service: EchoService (NsMaTbN7u5ZPUNN47bSEI6)
  4. Description:
  5. Version: 1.0.0
  6. Endpoints:
  7. Name: default
  8. Subject: svc.echo
  9. Queue Group: q
  10. Statistics for 1 Endpoint(s):
  11. default Endpoint Statistics:
  12. Requests: 1 in group q
  13. Processing Time: 15µs (average 15µs)
  14. Started: 2024-01-16 19:40:09 (7m46s ago)
  15. Errors: 0

That’s it! Congratulations, you’ve got a running Nex node that is ready and willing to accept and run any kind of workload you can throw at it! In the next section of this guide, we’ll create, deploy, and manage functions. To keep things easy, you should keep your Nex node running throughout the rest of this guide.