Azure Cloud Service: Practice

Overview

Let’s try to rump up Azure Cloud Service with Worker Role. We will need to:

  1. Create Cloud Service environment in Azure.
  2. Create a Project in Visual Studio. It will be Cloud Service with Worker Role.
  3. Run the project in Visual Studio.
  4. Deploy Cloud Service instances to Azure.
  5. Observe the results.

Step 1: Create Cloud Service Resource in Azure

  • Log in to Azure Portal
  • Navigate to New and start typing “Cloud Service”

  • Choose Cloud Service and click Create
  • Fill fields
    • Choose your Subscription
    • Choose existing or create a new Resource group
    • DNS name will be appended with .cloudapp.net That will create your own DNS namespace. In the example it is called roses. That means that I will be able to access my cloud service withroses.cloudapp.net
    • Choose Region that is closest to you

  • Choose Review + create
  • Your service will start Deployment process

  • You will see a notification that your service is successfully deployed and you will be suggested to enter your Cloud Service. If you follow the link you will find out that you have nothing deployed but you have your environment prepared.

  • Now, Let’s deploy something to our cloud service.

Step 2: Create Cloud Service in Visual Studio

  • Open Visual Studio
  • Choose Create a new project
  • Start typing Azure
  • Choose Azure Cloud Service (classic)
  • Configure your new Project and click Create
    • Choose Project Name
    • Location
    • Framework

  • Choose Worker Role, rename it if you’d like
  • Click OK
  • You will find a created project with Worker Role and predefined cloud service project template

Step 3: Run your Visual Studio Project

  • Right click on the cloud project -> Set Up as Startup Project

  • Click Start
  • You will see how Azure Emulator is loading

  • See Output to understand that your services successfully started and running

Step 4: Deploy your Cloud Service to Azure

  • Right click on your cloud service and choose Publish

  • Sign in to your Azure Account
  • Complete Publish Settings
    • Cloud Service: to deploy your service to the environment you created in the Step 1, put the same Cloud Service name and location that you chose in the Step 1 (in my example, DNS Name = roses, Region=East US)
    • Environment: you can choose Staging as I did or Production.
    • Build configuration: Release or Debug
    • Service configuration: Cloud

  • Click Publish

Step 5: Observe the results

  • In Visual Studio you will see Activity Logs that show the progress of your service deployment

  • Go to Azure Portal and navigate to your Cloud Service. Choose Staging on the top left side if you chose to deploy to Staging. You will see that your service is Busy, that means that it is in process to start the instances. In our case we have configured only one instance of the service, but you can later configure as many as you need to handle the traffic.

  • After a couple of minutes you will see ‘Running’ indicator next to your Worker role. Congratulations! You deployed your Cloud Service to Azure.

 

Continue Reading

Azure Cloud Service: Theory

Cloud Service

Cloud service gives you one of the possible ways to run your code in Azure. Another ways would be VMs, Websites, Azure App Service, Azure Fabric, Azure Functions and others.

  • You can obtain Cloud Service in Azure Cloud
  • Cloud service provides you with virtual machines (instances) that are managed by Azure. For example, if you’d like to use your own VMs, you need to provision those VMs first and install necessary software there. Also, this is you who is responsible for administrating (updating, patching, managing) your VMs. In case of Cloud Services all this work is done by Azure.
  • You can run: Websites (as Web Roles) and other code (as Worker Roles) in Cloud Services

Cloud Service Application Roles

Application Role is a container for running your application code on virtual machines. It has two different types:

  • Web Role – used to run websites with web interface. Web Role VM has: Windows server, .NET Framework, Native Code, IIS support, CGI support, PHP support
  • Worker Role – used to run background processes (e.g. database updates or processing messages from event hubs). Worker Role VM has: Windows Server, .NET Framework, Native code

Responsibilities

Your responsibility:

  • Create code logic (website or other code)
  • Define for Azure how it should create a virtual machine, define the characteristics like: CPU, memory, hard drive space, how many instances you need (how many VMs)

Azure Responsibility:

  • Azure Fabric will manage your Cloud Service according to cloud service definition you provided. It will monitor instances health, run your code, scale the service out upon your guidelines etc.

Configuration files

Azure will manipulate and manage your Cloud Service according to your guidelines that you have to provide in 2 types of configuration files.

Service Definition file

Extension: .csdef

Service Definition provides Azure with information about your service model telling how your application will look like from Azure perspective. You can provide such information as:

  • VM size
  • External (e.g. for web application to let customers reach the web out) and Internal Endpoints
  • Certificates
  • Site name, Bindings, protocol, ports
  • Environment variables
  • Configuration settings names

Example from ‘Azure Cloud Service: Practice‘:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="RosesInCloud" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
  <WorkerRole name="RoseWorkerRole" vmsize="Standard_D1_v2">
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
      <Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" />
    </ConfigurationSettings>
  </WorkerRole>
</ServiceDefinition>

Service Configuration file

Extension: .cscfg file

Defines the configuration for particular servces:

  • Operating System
  • Instance count
  • Values for configuration settings given in Service Definition file
  • Certificate thumbprints

Example from ‘Azure Cloud Service: Practice‘:

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="RosesInCloud" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6">
   <Role name="RoseWorkerRole">
      <Instances count="1" />
      <ConfigurationSettings>
         <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=roses;AccountKey=MY_ROSES_KEY" />
         <Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" value="f0331000-0000-0000-0000-000394f5f72a" />
      </ConfigurationSettings>
   </Role>
</ServiceConfiguration>
Continue Reading