Cloud Minute: Deploying ASP.NET apps on Google Compute Engine

In my previous post, I talked about how to deploy ASP.NET apps to Google Cloud. In this post, I want to point out a short Cloud Minute video that quickly shows how to deploy ASP.NET apps to Google Cloud. Enjoy!

 

 

Advertisements

Overview of .NET on Google Cloud Platform

I consider myself a Java developer first but during my time at Microsoft and Skype, I had the chance to learn about C# and .NET. Over time, I started liking the advanced features in C# (that Java just recently started having) and the great ecosystem and tooling around .NET. 

When I moved to Google and started working on Google Cloud Platform, I was naturally very happy to learn that Google Cloud Platform supports .NET applications.

In this blog post, I want to provide an overview of .NET support on Google Cloud Platform and talk about .NET client library. 

If you want more details, .NET on Google Cloud Platform is the best page to get started, it includes quickstarts, code samples, tutorials and more.

Windows Server and ASP.NET

First question you probably have is: What kind of .NET applications can I host on Google Cloud and how? You can host ASP.NET applications on Windows Server running on Compute Engine.

The easiest way to get started is to use Cloud Launcher ASP.NET Framework to deploy Windows Server 2012, Microsoft IIS, ASP.NET, and SQL Express on a Compute Engine instance.

Once the ASP.NET stack is installed, ASP.NET apps can be deployed from Visual Studio using the regular Web Deployer (no special plugin needed) to your Compute Engine instance.

.NET on Google Cloud Platform page includes a Hello World with .NET sample on details on how to deploy .NET apps on Google Cloud. There is also a How to get your ASP.NET app up on Google Cloud the easy way post on Google Cloud Platform blog that you might find useful.

.NET Library for Google Cloud Platform

Once you have your basic ASP.NET app running, you probably want to know what .NET APIs and libraries exist for which part of Google Cloud Platform. 

Currently, there are 2 different .NET libraries for Google Cloud Platform: Google API Client Library for .NET and Google Cloud Platform Client Libraries for .NET. The latter libraries are currently in Alpha and Beta stages, so I won’t talk about them in detail here but stay tuned for more details in a future post.

Google API Client Library for .NET is currently the official library for many Google services, including Google Cloud Platform. It includes .NET APIs for many Google Cloud services such as Cloud Storage, BigQuery, Pub/Sub, Dataflow and more. The full list is on their APIs page (search for “cloud” for Google Cloud related APIs).

Main APIs

I want to outline some of the main .NET APIs for storing data, messaging, BigQuery and point to their NuGet packages and source code for easy reference.

Structured Data

Every application needs some kind of structured data and you have 2 options to store structured application data:

  1. Google Cloud SQL can be used with regular Entity Framework (no special API needed).
  2. Google Cloud Datastore (NoSQL) can be used with Google Cloud Datastore API Client Library for .NET (NuGet | Source).

Binary Data

You can use Google Cloud Storage to store binary data with Cloud Storage JSON API Client Library for .NET (NuGet | Source).

Messaging

You can use Google Cloud Pub/Sub for publish/subscribe messaging with Google Cloud Pub/Sub API Client Library for .NET (NuGet | Source).

BigQuery

You can work with Google Cloud BigQuery with BigQuery API Client Library for .NET (NuGet | Source).

Other APIs

For the rest of Google Cloud Platform, you can find APIs on Google Compute Engine, Google DataFlow, Google Cloud Dataproc and many more under APIs section of Google API Client Library for .NET.

Code Samples

There is also a GitHub repository called dotnet-doc-samples where more and more samples are being added for .NET on Google Cloud Platform.

As you can see, .NET is a fully supported framework and it’s only going to get better, so I’m very excited to see how .NET support will evolve going forward on Google Cloud Platform.

 

Compute Engine Java API

googlejavaapiThe usual way of managing Compute Engine instances is from GCP Console.  However, if you need programmatic access to Compute Engine, there is a comprehensive REST API. There are also client libraries (that basically wrap the REST API) provided by Google and the community, for Java, .NET, Go, JavaScript, Ruby and more.

In this post, I want to take a look at the Java client libraries. There are 2 client libraries for Java:

  1. Apache JClouds: This is an open source library that allows one to use Java across multiple Cloud providers, including Compute Engine on Google Cloud. This is a good option if you want to work with multiple cloud vendors from the same API.
  2. Google API Client Library for Java: Provided by Google, this is a Java library for accessing all Google APIs (not just Google Cloud), including Compute Engine on Google Cloud.

A good starting point to explore Google API Client Library for Java is Compute Engine Cmdline Sample. This sample basically contains a single class ComputeEngineSample that lists all compute engine instances you have in your project from Java. Nothing earth-shattering but it shows how to authenticate with Google API and interact with Compute Engine.

There’s an instructions.html file that tells you how to setup and use the sample. One thing you’ll realize is that you need to grant API access to your Java app before you can run the sample but instructions.html is a little outdated on that. This is what you need to do to grant API access:

  1. Either create or go to your project from Developer Console.
  2. Open side-menu on top left and go to “API Manager”.
  3.  Under “API Manager”, click on “Credentials” -> “Create Credentials” -> “OAuth Client ID”.
  4. Now, you need to select the application type. In our case, select “Other” and give it a name.
  5. At this point, you’ll have a pop-up with client ID and secret. Copy these down as you’ll need them later.

Once that’s done, you can import the project into Eclipse (or your favorite IDE), fill client_secrets.json in resources folder with client ID and secret from step 5, and fill the following info in ComputeEngineSample:

  • APPLICATION_NAME: Optional but give it a name, so you don’t get warnings.

  • projectId: Your project id from Developers Console.

  • zoneName: Make sure to enter the right zone for your project. In my case, I chose europe-west1-c.

That’s it. Now, you can run ComputeEngineSample from Eclipse (or your favorite IDE) and you can get info about your Compute Engine instances right from Java:

================== Listing Compute Engine Instances ==================
{
"canIpForward" : false,
"creationTimestamp" : "2016-02-16T05:58:00.714-08:00",
"description" : "",
"disks" : [ {
"autoDelete" : true,
"boot" : true,
"deviceName" : "instance-1",
"index" : 0,
"kind" : "compute#attachedDisk",
"mode" : "READ_WRITE",
    ....

 

Google Compute Engine

google_compute_engine_logo

Intro

As I’m learning about different parts of Google Cloud Platform (GCP), I thought it’d be a good idea to share my notes. GCP documentation is great and it contains a lot of detailed information but sometimes I prefer cheat sheet style notes and that’s what I intend to provide here.

GCP is nicely divided into different sections: Compute, Storage, Networking, Big Data, Services, Management. I started looking into Compute layer and more specifically, Compute Engine. Here are my notes on Compute Engine.

What is Compute Engine?

  • Infrastructure as a Service (IaaS) offering of Google Cloud.
  • At its core, it’s 3 things: Virtual Machines, Disks, and Networking.
  • Additionally: Scaling, monitoring, regions & zones.
  • Access via web-based GCP console, Restful API & client libraries, and gcloud compute command-line tool.

Virtual Machines

  • Core component of Compute Engine.
  • Supports different machine types: Standard, high-CPU, high-memory, shared core (full list). You can even have custom machine types, if none of these meet your needs.
  • Supports different operating systems: Ubuntu, Debian, Windows and more. (full list).

Disks

  • Persistent Disk and Local SSD storage (more detail).
  • Persistent Disk has two flavors: standard (HDD) and solid-state (SSD).
  • Automatic encryption and redundancy against data corruption.

Networking

Scaling

Monitoring

Regions & Zones

  • Regions: Central US, Eastern US, East Asia, Western Europe (more detail).
  • Zones are sub-regions basically.

Management

These are different management options for Compute Engine:

  • GCP Console: Browser-based Google tool that to manage Compute Engine resources.
  • gcloud compute: command-line tool to manage Compute Engine, instead of the API.
  • Compute Engine API: HTTP/JSON based REST API for pretty much everything in Compute Engine.
  • Client libraries: Many community and Google supported client libraries for  Compute Engine API.

Resources