Deploying Javascript Unikernels to Vultr With Ops

Updated on November 21, 2023
Deploying Javascript Unikernels to Vultr With Ops header image

Deploying Javascript Unikernels to Vultr

Unikernels are single-application operating systems. Unlike general-purpose operating systems like Linux, unikernels can't run multiple programs on the same server instance. Unikernels are built by compiling high-level languages into machine images that run directly on a hypervisor or bare metal. This tutorial deploys a simple "hello world" JavaScript webserver to Vultr.

Prerequisites

  1. A UNIX-like operating system, including:

    • MacOS
    • Debian
    • Ubuntu
    • Fedora
    • Centos
  2. A provisioned Vultr Object Storage location.

    • Make a note of your Object Storage hostname. The first portion is referred to as the zone in this tutorial. For example, if your hostname is ewr1.vultrobjects.com, your zone is ewr1. This tutorial uses the example zone ewr1.
  3. An active account API key. Make sure your API key allows access from your IP address.

Install Ops

Download and install Ops:

curl https://ops.city/get.sh -sSfL | sh

You can also build it from source, available at https://github.com/nanovms/ops.

  • You may need to reboot after installation for Ops to function properly.

Deploy Your First Unikernel

Create a working directory.

$ mkdir opstest
$ cd opstest

Create a Vultr Object Storage bucket. Use a unique name.

Create a file named config.json that specifies your Vultr Object Storage Bucket name and the zone ewr1.

{
  "CloudConfig" :{
    "Zone": "ewr1",
    "BucketName":"your_unique_bucket_name"
  }
}

Create file named hi.js. This simple application spawns a web server to listen on port 8083 and reply "Hello World".

var http = require('http');

console.log("I'm running on Vultr");

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(8083, "0.0.0.0");
console.log('Server running!');

Export the following environment variables.

export TOKEN=my_api_token 
export VULTR_ACCESS=my_vultr_object_storage_access_key 
export VULTR_SECRET=my_vultr_object_storage_secret_key 

Create the Unikernel Image

Next steps:

  • Bundle the node 13.6 package with the hi.js JavaScript application into a unikernel disk image.
  • Upload the .img disk image to Vultr Object Storage.
  • Import the disk image from Vultr Object Storage to a Vultr Cloud snapshot.

Run the following command to perform those steps in one action.

$ ops image create -t vultr -c config.json -z ewr1 -p node_v13.6.0 -a hi.js

List the image to find the image ID of the new snapshot.

$ ops image list -z ewr1 -t vultr

Use the image ID in the second column to create an instance from the snapshot.

$ ops instance create -z ewr1 -t vultr -i my_id

Verify the Vultr Cloud instance is running.

$ ops instance list -z ewr1 -t vultr

Navigate to your the URL for instance's IP address.

$ curl -XGET http://192.0.2.1:8083/
Hello World

You have deployed the "hello world" unikernel. More information about unikernels and Ops are available at: https://nanovms.gitbook.io/ops/vultr and https://ops.city/