Over a million developers have joined DZone.

Unikernel on Google Compute Engine – Part 1 ,  Running an OSv Unikernel Tomcat Server

DZone's Guide to

Unikernel on Google Compute Engine – Part 1 ,  Running an OSv Unikernel Tomcat Server

Learn how you can start harnessing the power of unikernels in the Java ecosystem with this practical tutorial.

· Cloud Zone
Free Resource

MongoDB Atlas is a database as a service that makes it easy to deploy, manage, and scale MongoDB. So you can focus on innovation, not operations. Brought to you in partnership with MongoDB.

This is a short guide to running a unikernel on Google Compute Engine. It is also a good primer on why you should care about unikernels. I used the OSv unikernel because it supports Java and Java is my language of choice. Moreover, the OSv’s image build tool, Capstan, feels similar to Docker so I felt I could get started quickly.

You may have seen the Running OSv on Google Compute Engine guide, but the instructions seem outdated (see issue). The Capstan tool, currently, has issues when building images for Google Compute Engine (see issue). Therefore, the experience wasn’t as straightforward as I hoped, but I was determined to make it work.

Running the OSv Tomcat Image on Google Compute Engine

The following instructions use the Google Cloud SDK command line tool. You can do the same thing directly within the Developer Console UI (find details in the appendix at the very end). To reduce the number of command line arguments, start by setting the default project and default zone (you can pick and choose a zone that works for you).

$ gcloud config set core/project YOUR_PROJECT_ID
$ gcloud config set compute/zone us-central1-c

First, register the public OSv Tomcat image in your Google Cloud Platform project:

$ gcloud compute images create osv-v0–23-tomcat \
    --source-uri gs://osv/v0.23/osv-tomcat.gce.tar.gz

Next, create a VM instance using that image:

$ gcloud compute instances create osv-tomcat --image osv-v0–23-tomcat

That was pretty fast, right? Note the External IP address of the newly created instance. That’s important!

Remember, this unikernel runs only Tomcat and nothing else. Hence, you won’t be able to SSH into it. To see what’s going on inside of the instance, you need to look at the serial port output:

$ gcloud compute instances get-serial-port-output osv-tomcat
Example serial port output

It’s up and running! From the serial port output, we can see that the Tomcat instance is listening on port 8081. By default, Google Cloud Platform blocks inbound traffic on this port. You can enable the port by updating the firewall rules configuration:

$ gcloud compute firewall-rules create allow-8081 — allow tcp:8081

Finally, refer to the External IP of the instance you created, and in your browser navigate to http://EXTERNAL_IP:8081/. You should see the default Tomcat page!

Tomcat’s default home page that you should see

What’s Next?

In the next part in this series, I’ll use Capstan to build a custom OSv unikernel image and deploy it onto Google Compute Engine (with workarounds).

Appendix — Do Everything In a Browser

You can do everything from a browser using the Developer Console too.

First, navigate to Compute Engine > Images, and click New Image to register the image:

Then, navigate to Compute Engine > VM instances, and click Create instance (or New instance) to create a new VM instance with the image. Make sure to click Boot disk > Change to specify the OSv boot disk image:

Once the instance is created, you can also access the serial port output directly from the Developer Console. Click the VM name osv-tomcat, then scroll all the way down and click Serial console output:

To enable port 8081, navigate to Networking > default Network, and click Add firewall rule:

And that’s it!

(Original post on Medium)

MongoDB Atlas is the best way to run MongoDB on AWS — highly secure by default, highly available, and fully elastic. Get started free. Brought to you in partnership with MongoDB.

cloud ,java ,tomcat ,unikernel ,google compute engine ,osv

Published at DZone with permission of Ray Tsang. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}