Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Latest commit

 

History

History
83 lines (46 loc) · 5.35 KB

lab.adoc

File metadata and controls

83 lines (46 loc) · 5.35 KB

Lab 5 - Deploying a .NET Application

With the release of Pivotal Cloud Foundry 1.6, it is now possible to deploy and manage .NET applications within your PCF environment.

In the this lab, we will deploy a .NET application backed by a SQL Server instance. There are two versions of the Contoso application in this repo: V1 has a black background on the home page, and V2 has a green background: this is to show a 'Blue-Green' deployment scenario.

Prerequisites

  1. A working PCF 1.6 or 1.5 + Diego Beta deployment. This PCF deployment must have a Windows cell installed and operational — see the Diego Windows release notes for additional details on setup of a Windows cell if your PCF environment needs one.

  2. A SQL Server 2012 or 2014 instance with a database created. This SQL Server database must be accessible (routeable) from your PCF environment. For demonstration purposes, we created a VM running SQL Server 2012 Express on vSphere with 2 vCPUs, 8GB RAM, and 50GB disk using Windows 2012R2. If you are creating a new SQL Server instance on your own IaaS / hardware, follow this guide to install from Microsoft’s download website. As an alternative option, you can create and utilize a SQL Server instance in the cloud using Microsoft Azure. As of October 2015, Microsoft is offering a free one month trial of Azure.

  3. Submodules initiated and fetched for this workshop git repository. After cloning this repository, issue this command to download the .NET code used by this lab.

    $ cd PCF-Workshop-101/
    $ git submodule init && git submodule update

Create the User Provided Service

The Contoso .NET application depends on a SQL Server instance and optionally a queue. For this demo, we will create two services however only use the SQL Server service instance. This will be made available to the .NET application via a User Provided Service binding in Cloud Foundry.

  1. The first service is a connection to an SQL server:

    $ cf cups contoso-demo-sql -p 'connectionString'
  2. Enter your SQL Server connection string (the SQL Server database can be hosted anywhere, e.g. on Azure). Replace the following parameters with the appropriate values: YOUR_IP, YOUR_USERID, YOUR_PASSWORD, YOUR_DATABASE

    Data Source=YOUR_IP;Integrated Security=False;User ID=YOUR_USERID;Password=YOUR_PASSWORD;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Initial Catalog=YOUR_DATABASE
  3. The second service is to an Azure Service Bus queue:

    $ cf cups contoso-demo-queue -p 'queueConnectionString'
  4. The command line will then prompt you for the queue connection string with the prompt queueConnectionString:, and you can enter the information as follows. Replace the following parameters with the appropriate values: YOUR_QUEUE_HOST, YOUR_QUEUE_NAME, YOUR_QUEUE_KEY. For the demo, you can use placeholder values as we will not utilize this.

    Endpoint=sb://YOUR_QUEUE_HOST;SharedAccessKeyName=YOUR_QUEUE_NAME;SharedAccessKey=YOUR_QUEUE_KEY

Deploy the .NET Application

Use the following commands to deploy to Pivotal Cloud Foundry after you have created the User Provided Servies in the previous step.

  1. Go to the directory containing the .NET app

    $ cd cf-dotnetcontoso
  2. Edit the file contoso-university-v1/demo.bat and replace YOUR_DOMAIN with the domain in use by application in your instance of Cloud Foundry.

  3. Deploy

    1. On Linux:

      $ cd contoso-university-v1
      $ bash demo1.bat
      $ cd ../contoso-university-v2
      $ bash demo2.bat
    2. On Windows:

      $ cd contoso-university-v1
      $ demo1.bat
      $ cd ../contoso-university-v2
      $ demo2.bat

View the Two Versions of the Application

  1. Pull up the Application Manager dashboard.

  2. Click on the contoso-demo-v1 URL. This is the Blue deploy and has a black background on the homepage. Note that it has also been mapped to a second route named 'contoso.YOUR_DOMAIN' Feel free to add some Students, Instructors, etc.

  3. Click on the contoso-demo-v2 URL. This is the Green deploy and has a green background on the homepage. It utilizes the same SQL Server database (via the User Provided Service binding) so note that all of the values you entered in the previous step show up here too - very cool!

Blue-Green Deploy

Cloud Foundry makes it very simple to perform Blue-Green deployments. Simply map the same route to a different version of your applicaiton which has been deployed. Cloud Foundry will automatically load balance between the two different applications, enabling zero-downtime and allowing for a seamless transition between application versions. Replace YOUR_DOMAIN with the appropriate value below to map the second version of Contoso (the green background) to the same route as the first version of Contoso (the black background). Voila!

$ cf map-route contoso-demo-v2 YOUR_DOMAIN -n contoso

Make sure you open the Contoso application in a Chrome incognito window so that sticky sessions do not cause any issues. Then, refresh and note the color changing. Also browse the various tabs and see that V2 of the application is using the same SQL Server database that V1 utilized.