Exercise 3: Deploying a Windows Azure Application

In this exercise, you deploy the application created in the previous exercise to Windows Azure using the Management Portal. First, you provision the required service components, upload the application package to the staging area and configure it. You then execute the application in the staging area to verify its operation. Finally, you promote the application to production.

Note:
In order to complete this exercise, you need to sign up for a Windows Azure account and purchase a subscription.

For a description of the provisioning process, see Provisioning Windows Azure.

Task 1 – Creating a Storage Account and a Hosted Service Component

The application you deploy in this exercise requires both compute and storage services. In this task, you create a new Windows Azure storage account to allow the application to persist its data. In addition, you define a hosted service component to execute application code.

  1. Navigate to https://windows.azure.com using a Web browser and sign in using the Windows Live ID associated with your Windows Azure account.

    Figure 27

    Signing in to the Windows Azure Platform Management Portal

  2. First, you create the storage account that the application will use to store its data. In the Windows Azure ribbon, click New Storage Account.

    Figure 28

    Creating a new storage account

  3. In the Create a New Storage Account dialog, pick your subscription in the drop down list labeled Choose a subscription.

    Figure 29

    Choosing a subscription to host the storage account

  4. In the textbox labeled Enter a URL, enter the name for your storage account, for example, <yourname>guestbook, where <yourname> is a unique name. Windows Azure uses this value to generate the endpoint URLs for the storage account services.

    Figure 30

    Choosing the URL of the new storage account

    Note:
    The portal ensures that the name is valid by verifying that the name complies with the naming rules and is currently available. A validation error will be shown if you enter a name that does not satisfy the rules.

  5. Select the option labeled Create or choose an affinity group and then pick Create a new affinity group from the drop down list.

    Figure 31

    Creating a new affinity group

    Note:
    The reason that you are creating a new affinity group is to deploy both the hosted service and storage account to the same location, thus ensuring high bandwidth and low latency between the application and the data it depends on.

  6. In the Create a New Affinity Group dialog, enter an Affinity Group Name, select its Location in the drop down list, and then click OK.

    Figure 32

    Creating a new affinity group

  7. Back in the Create a New Storage Account dialog, click Create to register your new storage account. Wait until the account provisioning process completes and updates the Storage Accounts tree view. Notice that the Properties pane shows the URL assigned to each service in the storage account. Record the public storage account name—this is the first segment of the URL assigned to your endpoints.

    Figure 33

    Storage account successfully created

  8. Now, click the View button next to Primary access key in the Properties pane. In the View Storage Access Keys dialog, click Copy to Clipboard next to the Primary Access Key. You will use this value later on to configure the application.

    Figure 34

    Retrieving the storage access keys

    Note:
    The Primary Access Key and Secondary Access Key both provide a shared secret that you can use to access storage. The secondary key gives the same access as the primary key and is used for backup purposes. You can regenerate each key independently in case either one is compromised.

  9. Next, create the compute component that executes the application code. Click Hosted Services on the left pane. Click on New Hosted Service button on the ribbon.

    Figure 35

    Creating a new hosted service

  10. In the Create a new Hosted Service dialog, select the subscription where you wish to create the service from the drop down list labeled Choose a subscription.

    Figure 36

    Choosing your subscription

  11. Enter a service name in the textbox labeled Enter a name for your service and choose its URL by entering a prefix in the textbox labeled Enter a URL prefix for your service, for example, <yourname>guestbook, where <yourname> is a unique name. Windows Azure uses this value to generate the endpoint URLs for the hosted service.

    Figure 37

    Choosing a service name and URL

    Note:
    If possible, choose the same name for both the storage account and hosted service. However, you may need to choose a different name if the one you select is unavailable.

    Note:
    The portal ensures that the name is valid by verifying that the name complies with the naming rules and is currently available. A validation error will be shown if you enter name that does not satisfy the rules.

  12. Select the option labeled Create or choose an affinity group and then pick the guestbook affinity group from the drop down list—this is the same affinity group that you defined earlier, when you created the storage account.

    Figure 38

    Choosing an affinity group

    Note:
    By choosing guestbook as the affinity group, you ensure that the hosted service is deployed to the same location as the storage account that you provisioned earlier.

  13. Select the option labeled Do not Deploy.

    Note:
    While you can create and deploy your service to Windows Azure in a single operation by completing the Deployment Options section, for this hands-on lab, you will defer the deployment step until the next task.

  14. Click OK to create the hosted service and then wait until the provisioning process completes.

    Figure 39

    Hosted service successfully created

  15. Do not close the browser window. You will use the portal for the next task.

Task 2 – Deploying the Application to the Windows Azure Platform Management Portal

There are several alternatives for deploying applications to Windows Azure. The Windows Azure Tools for Visual Studio allow you to both create and deploy the service package to the Windows Azure environment directly from Visual Studio. Another deployment option is the Windows Azure Service Management PowerShell Cmdlets that enable a scripted deployment of your application. Lastly, the Windows Azure Platform Management Portal provides the means to deploy and manage your service using only your browser. For more information about deployment, see the Windows Azure Deployment lab in this training kit.

In this task, you deploy the application to the staging environment using the Management Portal but first, you generate the service package using Visual Studio.

  1. If it is not already open, launch Visual Studio as administrator from Start | All Programs | Microsoft Visual Studio 2010 by right clicking the Microsoft Visual Studio 2010 shortcut and choosing Run as administrator.
  2. If the User Account Control dialog appears, click Continue.
  3. In the File menu, choose Open and then Project/Solution. In the Open Project dialog, browse to Ex3-WindowsAzureDeployment in the Source folder of the lab and choose the folder for the language of your preference (Visual C# or Visual Basic). Select Begin.sln in the Begin folder and click Open. Alternatively, you may continue with the solution that you obtained after completing the previous exercise.
  4. To configure the storage before deploying the service, open ServiceConfiguration.cscfg file located in GuestBook service. Replace the placeholder labeled [YOUR_ACCOUNT_NAME] with the Storage Account Name that you chose when you configured the storage account in Task 1. If you followed the recommendation, the name should follow the pattern <yourname>guestbook, where <yourname> is a unique name. Make sure to replace both instances of the placeholder, one for the DataConnectionString and the second one for the Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString.
  5. Next, replace the placeholder labeled [YOUR_ACCOUNT_KEY] with the Primary Access Key value that you recorded earlier, when you created the storage account in Task 1. Again, replace both instances of the placeholder, one for each connection string.

    Figure 40

    Configuring the storage account connection strings

  6. Generate the package to deploy to the cloud. To do this, right-click the GuestBook cloud project and select Publish. In the Deploy Windows Azure project dialog, select the option labeled Create Service Package Only and then click OK.

    After Visual Studio builds the project and generates the service package, Windows Explorer opens with the current folder set to the location where the generated package is stored.

    Figure 41

    Creating a service package in Visual Studio

    Note:
    Although the procedure is not shown here, the Publish Cloud Service feature in the Windows Azure Tools enables deployment of your service package directly from Visual Studio. To use this feature, you need to configure a set of credentials that you use to authenticate access to the management service using a self-issued certificate that you upload to the Management Portal.

  7. Now, switch back to the browser window and the Management Portal.
  8. At the portal, select the hosted service that you created in the previous step and then click New Staging Deployment on the ribbon.

    Note:
    A hosted service is a service that runs your code in the Windows Azure environment. It has two separate deployment slots: staging and production. The staging deployment slot allows you to test your service in the Windows Azure environment before you deploy it to production.

    Figure 42

    Hosted service summary page

  9. In the Create a new Deployment dialog, to select a Package location, click Browse Locally, navigate to the folder where Visual Studio generated the package in Step 4 and then select GuestBook.cspkg.
  10. Now, to choose the Configuration File, click Browse Locally and select ServiceConfiguration.cscfg in the same folder that you used in the previous step.
  11. Note:
    The .cscfg file contains configuration settings for the application, including the instance count that you will update later in the exercise.

  12. Finally, for the Deployment name, enter a label to identify the deployment; for example, use v1.0.

    Note:
    The portal displays the label in its user interface for staging and production, allowing you to identify the version currently deployed in each environment.

    Figure 43

    Configuring the service package deployment

  13. Click OK to start the deployment. Notice that the portal displays a warning message when you do this. Click See more details to review and understand the message.

    Figure 44

    Reviewing the warnings

    Note:
    In this particular case, the warning indicates that only a single instance is being deployed for at least one of the roles. This is not recommended because it does not guarantee the service’s availability. In the next task, you will increase the number of instances to overcome this issue.

  14. Click Yes to override and submit the deployment request. Notice that the package begins to upload and that the portal shows the status of the deployment to indicate its progress.

    Figure 45

    Uploading a service package to the Windows Azure Platform Management Portal

  15. Wait until the deployment process finishes, which may take several minutes. At this point, you have already uploaded the package and it is in a Ready state. Notice that the portal assigned a DNS name to the deployment that includes a unique identifier. Shortly, you will access this URL to test the application and determine whether it operates correctly in the Windows Azure environment, but first you need to configure it.

    Note:
    During deployment, Windows Azure analyzes the configuration file and copies the service to the correct number of machines, and starts all the instances. Load balancers, network devices and monitoring are also configured during this time.

    Figure 46

    Package successfully deployed and ready

Task 3 – Configuring the Application to Increase the Number of Instances

Before you can test the deployed application, you need to configure it. In this task, you define the storage account settings for the application.

  1. In Hosted Services, select your GuestBook service and click Configure on the ribbon.

    Figure 47

    Configuring application settings

  2. In the Configure Deployment dialog, select the option labeled Edit current configuration, locate the Instances element inside the GuestBook_WebRole configuration and change its count attribute to 2. Do the same for the GuestBook_WorkerRoleconfiguration to also increase its instance count to 2.

    Figure 48

    Configuring the Instances count

    Note:
    The configuration is simply an XML document that contains the value of the settings declared in the service definition file. Its initial content is determined by the ServiceConfiguration.cscfg file that you uploaded earlier, when you deployed the package in Task 2.

    Note:
    The Instances setting controls the number of roles that Windows Azure starts and is used to scale the service. For a token-based subscription—currently only available in countries that are not provisioned for billing—this number is limited to a maximum of two instances. However, in the commercial offering, you can change it to any number that you are willing to pay for.

  3. Click OK to update the configuration and wait for the hosted service to apply the new settings.

    Figure 49

    Updating the number of role instances

    Note:
    The portal displays a legend "Updating deployment..." while the settings are applied.

Task 4 – Testing the Application in the Staging Environment

In this task, you run the application in the staging environment and access its public endpoint to test that it operates correctly.

  1. In Hosted Services, select your GuestBook service and then click the link located in the right pane under DNS name.

    Figure 50

    Running the application in the staging environment

    Note:
    The link shown for DNS name has the form <guid>.cloudapp.net, where <guid> is some random identifier. This is different from the address where the application will run once it is in production. Although the application executes in a staging area that is separate from the production environment, there is no actual physical difference between staging and production – it is simply a matter of where the load balancer is connected.

  2. If you wish, you may test the application by signing the guest book and uploading an image.

    Figure 51

    Application running in the staging environment

Task 5 – Promoting the Application to Production

Now that you have verified that the service is working correctly in the staging environment, you are ready to promote it to final production. When you deploy the application to production, Windows Azure reconfigures its load balancers so that the application is available at its production URL.

  1. In Hosted Services, select your GuestBook service and then click Swap VIP on the ribbon.

    Figure 52

    Promoting the application to the production slot

  2. On the Swap VIPs dialog, click OK to swap the deployments between staging and production.

    Figure 53

    Promoting the application to the production deployment

  3. Wait for the promotion process to complete, which typically takes a few seconds.

    Figure 54

    Application successfully deployed to production

  4. Click the DNS name link to open the production site in a browser window and notice the URL in the address bar.

    Figure 55

    Application running in the production environment

    Note:
    If you visit the production site shortly after its promotion, the DNS name might not be ready. If you encounter a DNS error (404), wait a few minutes and try again. Keep in mind that Windows Azure creates DNS name entries dynamically and that the changes might take few minutes to propagate.

  5. Even when a deployment is in a suspended state, Windows Azure still needs to allocate a virtual machine (VM) for each instance and charge you for it. Once you have completed testing the application, you need to remove the deployment from Windows Azure to avoid an unnecessary expense. To remove a running deployment, go to Hosted Services, select the deployment slot where the service is currently hosted, staging or production, and then click Stop on the ribbon. Once the service has stopped, click Delete on the ribbon to remove it.