.Net in the cloud with OCI
Just over a month ago, I joined Oracle, specifically OCI, as a Master Principal Cloud Architect. While Oracle products such as E-Business Suite, Java, and Oracle databases are ubiquitous in the corporate world, Oracle Cloud Infrastructure or OCI is less so.
Ok, so you might be thinking… Oracle is the home of Java… so can you even run .NET in OCI? The answer is an unreserved YES! I mean.. why else would I be here?
OCI is all about choice
OCI’s mission is to give you the tools that you need to run the applications you need the way you need to run them. There are billions of .NET applications out there, from commercial software to internal applications, that keep the lights on for every kind of business imaginable.
Of course, one of the first things I did when I started at Oracle was to dive in and figure out how to run .NET Applications on OCI as quickly as possible. There was, of course, a learning curve as I adapted to the new technologies. Let's face it: when you open up the console of a new provider, you are simultaneously faced with two thoughts.
Oh my god, this is overwhelming…
I’m a kid in a toy store; where do I start playing?
OCI is no exception, with a wide range of services designed to address the core needs of every business. I am only just starting to scratch the surface of the developer tools.
Building my first .NET App for OCI
Disclaimer: Oracle did not hire me for my artistic talent. So clearly my first web site is going to be similar to the test apps I have built a dozen times before… The default .NET MVC application that comes with the starter kit…
The sample app includes retrieving the hostname and IP address for the machine it is being run on to help illustrate the handling of load balancers. Note: as of the date of publishing this article, there is a bug in the .NET appl that retrieves the 127.0.0.1 address for both deployed instances.
As always, I have included the source code for the application and the files I will use to deploy the solution on GitHub so you can download them and experiment on your own. Here
Infrastructure as Code (IaC)
Now, of course, if we are going to be deploying something into the cloud, we should be using IaC and my sample application is no exception. There was a fair bit of learning to do on my part to get to understand all of the new OCI tech, which meant trying new things, deploying them, then destroying the stack and trying again… without IaC, this would have been much more time-consuming and difficult.
Getting the files
There are two ways that you can get the files for this sample. First, and easiest, you can simply download the zip file from GitHub and use that directly. This method is extremely easy, you don’t even have to unzip the files.
The other alternative is to clone the repo and get access to all the source files and go from there.
Once you have the files, log into your OCI tenancy as normal.
Resource Manager
You can find the IaC management tool “Resource Manager” under development tools.
From the resource manager, choose Stacks.
And from there, select the compartment you want to deploy the stack into, and then click on Create stack.
Deploying the stack
Depending on if you choose to clone the directory or download the zip file, you will either drag and drop the ZIP file onto the resource manager screen or drag and drop the tf_project folder from the repo onto the web application.
It doesn’t matter whether you use the zip file or the folder; the rest of the deployment will be the same.
From there, click Next, and Next again to get to the last page of the install wizard. The only change you should make from the default install is on the final page where you enable the Run apply option before clicking Create.
The deployment will take a few minutes, giving us time to look at the solution.
Quick start code
The quick start is broken up into several sections.
img - These are the images from the GitHub readme file. Ignore these
resources - This contains an architecture diagram for the deployment
ociTestASPNET - This contains the source code for the ASP .NET Core application that gets deployed to the virtual machines. You don’t need this code as the application is already built and stored as App.zip in the Github Repo as a release.
scripts - This contains copies of the install scripts that are used to configure the instances
tf_project - This contains all of the Terraform files that are used to deploy the solution
Out of all the files in the repo, the tf_files folder will be the most interesting to look at as it contains the Terraform files used for the actual deployment and the installation script that gets passed in as the CloudInit script.
Once deployed, you will have a structure deployed into your compartment that looks like this:
The Terraform scripts deploy two Ubuntu servers into a VCN and a public subnet. The instances are attached to a load balancer and have the necessary Netywork Security Groups to allow traffic to them.
Finishing up
If all goes well, your deployment will be complete. Scroll down the log window to the bottom for your deployment, and you can get the IP addresses of the instances and the load balancer that has been deployed.
You can copy the IP address for the load balancer and put it into your web browser to see the ASP .NET application deployed into your infrastructure.
Next Steps
This application and deployment is obviously extremely basic and lacks a lot of features. As I continue to dive into the developer-centric tools on OCI, I’ll publish more blog posts and videos to show how well OCI is at hosting your .NET applications. Stay tuned for more .NET on OCI content.
Cleanup
If you use this test deployment in your account, make sure to delete the resources so that you don’t end up with a surprise bill. The cleanup has two steps, destroying the stack and then deleting the stack. These two steps must be completed in the correct order or you will have to go through your account and delete the resources manually.
Destroy the stack
Destroying a stack tells the resource manager service to go through the resources that were created and delete them from your account. This action does not remove the actual stack definition but clears out all the resources that were created as part of applying the stack.
Inside of the resource manager stacks view, clock on your stack.
Inside the stack definition, click Destroy to delete all of the resources created as part of the stack.
The destroy process will take a few minutes to complete.
Once the destroy process has been completed, you can return to the stack definition and delete the stack.
Deleting the stack will be complete almost instantly, as all it has to do is delete the stack definition, not the resources.