Deploy ASP.NET Core With Pivotal Cloud Foundry

Brad Jolicoeur

07/24/2018

I've been experimenting with Pivotal Cloud Foundry recently and put this quick tutorial together for deploying an ASP.NET Core application using PCF. I was amazed at how easy this was and I'm sure you will be too.

As a developer I love how PCF takes care of the cloud resource configuration for me, based on the requirements I give it and what it knows about the type of application I am deploying. Note that this tutorial is just a simple 'Hello World' style tutorial and does not show the full power of PCF. 

The prerequisites for this project are

Resources:

For this tutorial, I will be creating a new ASP.Net Core MVC application, creating a PCF manifest and then pushing the application to the Pivotal cloud. The real magic here is that PCF is going to take my manifest, compare it to my application and provision the server resources it requires automatically. 

To get started, create a new ASP.NET Core Web Application using Visual Studio 2017


I chose to use the MVC template.



Once the project was created, I added a Manifest.yml file to the root of the project. I haven't seen the best practices on where this file should be placed in the project, but this seems to work out. 



The Manifest.yml includes the instructions for PCF to build an environment for my application. This manifest is the minimum information PCF needs for creating the environment. I could add more details if I choose, and PCF will figure out the rest. 



Once I have the manifest set, I will open an command prompt (I've already installed CF CLI) and change to the root directory of my web project. This is the same directory that contains the Manifest.yml file.

Then login using cf cli using the command: cf login -api.run.pivotal.io

CF will ask for the email and password you used to create your free pivotal web services account.



After authenticating you are ready to push your application with the command: cf push



When push command executes you will see a lot of output showing everything PCF is doing to package your application and provision the server resources necessary. At the end it will show your application's state, in this image the service is now running.



You can now log into Pivotal Web Services web UI to see your application running. To the far right (not in image) you will see the URL for your application.

You are done, your app is up and running in the cloud and you didn't need to think about configuring web servers. If you wanted to target Azure or AWS, the process is essentially the same. 

My next area of exploration is configuration. PCF has a clever way to manage configuration variables using Git or other sources that has my interest.