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.
MacOS
Debian
Ubuntu
Fedora
Centos
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.
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
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/