This post is a continuation of Microservice Demo Application post where Node.js application is described:
The last part of this blog series will introduce you to Running the Application Inside OSv Unikernels On Kubernetes
Introduction
Application osv-microservice-demo serves for demonstration purposes of the improvements made to OSv and Capstan in the MIKELANGELO project. OSv is an operating system designed specifically for lightweight cloud workloads. It’s been developed initially by Cloudius Systems, now ScyllaDB. Capstan is a tool for rapidly composing applications into self-contained virtual machines ready to be deployed to various virtual machine monitors.
Getting Started with Unikernels
In the previous post we described a simple yet not trivial microservice application and run it locally using multiple terminal windows. In this post we demonstrate how to run the whole application using OSv unikernels - one unikernel for each service.The unikernels will be running on local QEMU/KVM hypervisor using Capstan tool.
The Microservice Demo Application already contains Capstan package descriptor and assumes you have Capstan tool already installed (if not, follow these instructions).
The package manifest is described in meta/package.yaml
file:
name
, title
and author
are used by Capstan mainly for displaying this information at various places. The require
lists all packages that need to be collected while composing target unikernel (target VM comprised of bootloader, OSv kerenel and your application). To get a list of packages available for download, use capstan package search
command. When looking for a specific package, add the name, for example:
$ capstan package search node
Name Description Version
eu.mikelangelo-project.app.hello-node NodeJS-4.4.5 4.4.5
eu.mikelangelo-project.app.node-4.2.6 NodeJS v0.24-300
eu.mikelangelo-project.app.node-4.4.5 NodeJS-4.4.5 4.4.5
Then just add the package name to the list of required packages. For example, if you’d like to add the CLI (Command Line Interface, a simple shell in OSv), add `eu.mikelangelo-project.osv.cli` to the list of required packages (to get the full name, we used capstan package search cli
).
Now that we have the basics covered (feel free to read through the documentation of Capstan project) we can continue preparing the unikernel. Let’s compose the virtual machine image:
$ capstan package compose node-micro/tutorial
Empty command line will be set for this image
Importing node-micro/tutorial...
Importing into /home/lemmy/.capstan/repository/node-micro/tutorial/tutorial.qemu
Uploading files to /home/lemmy/.capstan/repository/node-micro/tutorial/tutorial.qemu...
Setting cmdline: --norandom --nomount --noinit /tools/mkfs.so; /tools/cpiod.so --prefix /zfs/zfs; /zfs.so set compression=off osv
Uploading files 3016 / 3016 [================================================] 100.00 % 4s
All files uploaded
Command line set to: ''
That’s it. You now have a complete Node.js application ready to be executed inside lightweight virtual machine based on OSv. Check this out:
$ qemu-img info /home/lemmy/.capstan/repository/node-micro/tutorial/tutorial.qemu
image: /home/lemmy/.capstan/repository/node-micro/tutorial/tutorial.qemu
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 33M
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
Notice the disk size
? 33MB!
That’s all it takes to host a self-contained Node.js app inside OSv.
The Capstan tool is used to launch individual unikernels. The simplest way to start this image is to use the following command:
$ capstan run -e "/node keyvaluestore.js" node-micro/tutorial
Created instance: node-micro-tutorial
Setting cmdline: /node keyvaluestore.js
OSv v0.24-300-g33e3a36
eth0: 192.168.122.15
server is listening on 8000
This will use default values for various configuration options, launch a VM using QEMU/KVM hypervisor and start the application.
To be more useful in a local environment, we are going to use the following command:
$ sudo ~/dev/bin/capstan run \
-m 200M -c 1 -n vhost \
--mac="A2:13:15:00:80:01" \
-e "/node keyvaluestore.js" \
-i node-micro/tutorial \
node-micro-keyvaluestore
First note that the actual command to start the service as an OSv VM is quite the same as before /node keyvaluestore.js
. The other parts of the above command are explained next:
sudo
: only needed because we are usingvhost
networking~/dev/bin/capstan
: location of the capstan tool-m 200M
: the VM should only get 200 MB of RAM-c 1
: one virtual CPU-n vhost
: use vhost networking (check the QEMU network configuration when this mode is enabled)--mac="A2:13:15:00:80:01"
: specify a fixed MAC address so that we get the same IP on successive launches-e "/node keyvaluestore.js"
: the actual command we’d like to launch-i node-micro/tutorial
: the image to use when launcing this VM (it should be the same as it was used in thecapstan package compose
command above)node-micro-keyvaluestore
: name of the instance
Once the VM is created, output like the one below should be seen
Created instance: node-micro-keyvaluestore
Setting cmdline: /node keyvaluestore.js
OSv v0.24-300-g33e3a36
eth0: 10.211.55.178
server is listening on 8000
This means that the key-value store is accessible at http://10.211.55.178:8000/
. Now we are ready to start all other services (in separate terminals):
Database Service:
$ sudo ~/dev/bin/capstan run \
-c 1 -n vhost --mac="A2:13:15:00:80:02" \
-e "/node db.js 10.211.55.178:8000" \
-i node-micro/common \
node-micro-db
Created instance: node-micro-db
Setting cmdline: /node db.js 10.211.55.178:8000
OSv v0.24-300-g33e3a36
eth0: 10.211.55.181
Database endpoint registered
Database is listening on 8001
Storage Service:
$ sudo ~/dev/bin/capstan run \
-c 1 -n vhost --mac="A2:13:15:00:80:03" \
-e "/node storage.js 10.211.55.178:8000" \
-i node-micro/common \
node-micro-storage
Created instance: node-micro-storage
Setting cmdline: /node storage.js 10.211.55.178:8000
OSv v0.24-300-g33e3a36
eth0: 10.211.55.182
Storage endpoint registered
Storage is listening on 8002
Master Service
$ sudo ~/dev/bin/capstan run \
-c 1 -n vhost --mac="A2:13:15:00:80:04" \
-e "/node master.js 10.211.55.178:8000" \
-i node-micro/common \
node-micro-master
Created instance: node-micro-master
Setting cmdline: /node master.js 10.211.55.178:8000
OSv v0.24-300-g33e3a36
eth0: 10.211.55.183
Master endpoint registered
Master is listening on 8003
All set! Let’s upload a photo:
$ ./bin/upload_batch.sh 10.211.55.178:8000 /home/lemmy/dl/mike-team.png
Uploading to 10.211.55.183:8003
And now, start your worker:
$ sudo ~/dev/bin/capstan run \
-c 1 -n vhost \
-e '/node worker.js 10.211.55.178:8000' \
-i node-micro/tutorial \
node-micro-worker1
Created instance: node-micro-worker1
Setting cmdline: /node worker.js 10.211.55.178:8000
OSv v0.24-300-g33e3a36
eth0: 10.211.55.184
Working on task 0
processing //worker/0.png
done
Nothing to do at the moment
…
Start new workers, upload new photos, stop workers, stop services, play and enjoy :-).
Updating Virtual Machine Image
When you change your scripts, you can simply recompose the image using the same command as above:
$ capstan package compose node-micro/tutorial
However, this will rebuild entire VM, which means that besides your own scripts, it will upload all dependent NPM modules from node_modules
, Node runtime itself, etc. To speedup incremental VM builds, --update
flag can be passed to Capstan. This will cause Capstan to check for changes and only update those files that were actually changed:
$ capstan package compose --update node-micro/tutorial
The following video demonstrates the result of part 1 and this part.
Stay tuned for the final part of this blog series. For the impatient, we have made the tutorial available at the demo application’s GitHub project page.
Pingback: The Microservice Demo Application (Introduction) - Mikelangelo - Horizon 2020 Project on Virtualization, Cloud Computing, and HPC()
Pingback: The Microservice Demo Application (Running Inside OSv Unikernels On Kubernetes) - Mikelangelo - Horizon 2020 Project on Virtualization, Cloud Computing, and HPC()
Pingback: freshamateurs94371()
Pingback: latestvideo sirius102 abdu23na1684 abdu23na16()