1 out of 2 rated this helpful - Rate this topic

Create and Deploy the VM Role Service Model

Updated: April 6, 2011

[The VM Role feature of Windows Azure is being retired on May 15th, 2013. After the retirement date, VM role deployments will be deleted. To move forward with your existing applications, you can use Windows Azure Virtual Machines. For more information about using Virtual Machines for your application, see Moving from VM Role to Windows Azure Virtual Machines.

A VM Role is the same as the other roles in needing the service definition and service configuration files to be included in cloud service in Windows Azure. To create instances of a VM Role, you must deploy a service model package to Windows Azure. For more information about creating the service model files, see Cloud Services (Hosted Services).

For more information about the elements that are used in a service definition file for a VM Role, see VirtualMachineRole Schema. For more information about the elements that are used in a service configuration file for a VM Role, see Service Configuration Schema.

Before you complete this task, you must have completed Upload a VHD to Windows Azure.

You can use your favorite text editor to create the service model files. Complete the following steps to create the ServiceDefinition.csdef file:

  1. Open a text editor, such as Notepad.

  2. The .csdef file must have a ServiceDefinition element. The following code example shows the definition of this element:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
    </ServiceDefinition>
    
    
  3. You must add the VirtualMachineRole element to the ServiceDefinition element. The following example shows the addition of the VirtualMachineRole element:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
       <VirtualMachineRole name="MyVMRole" vmsize="Small">
       </VirtualMachineRole>
    </ServiceDefinition>
    
    

    Where name is the name of the VM Role that is displayed in the Management Portal, and vmsize is the size that Windows Azure assigns for the VM Role instances. The vmsize attribute is optional, if you do not specify the size, the default size of Small is used. If you specify the vmsize attribute, you must ensure that the size corresponds to the size that you chose for the base VHD. The following table lists the allowable sizes of VHDs in Windows Azure.

    ImportantImportant
    For dynamic disks, the sizes in the table are the maximum sizes that the VHD can grow to as additional space is required.

     

    Windows Azure VM size Maximum mounted VHD size

    Extra Small

    15 GB

    Small

    35 GB

    Medium, Large, or Extra Large

    65 GB

  4. (Optional) Import the modules for diagnostics, remote desktop connections, or Windows Azure Connect. The following example shows the addition of the Imports element with the Import elements:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
       <VirtualMachineRole name="MyVMRole" vmsize="Small">
       <Imports>
          <Import moduleName="Diagnostics" />
          <Import moduleName="RemoteAccess" />
          <Import moduleName="RemoteForwarder" />
          <Import moduleName="Connect" />
       </Imports>
       </VirtualMachineRole>
    </ServiceDefinition>
    
    

    For more information about using these modules, see:

  5. Add the endpoints that you need for your application. The following example shows the addition of the Endpoints element with an InputEndpoint defined for the http protocol on port 8080:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
       <VirtualMachineRole name="MyVMRole" vmsize="Small">
          <Imports>
             <Import moduleName="Diagnostics" />
             <Import moduleName="RemoteAccess" />
             <Import moduleName="RemoteForwarder" />
             <Import moduleName="Connect" />
          </Imports>
          <Endpoints>
             <InputEndpoint name="Endpoint1" protocol="http" port="8080" localPort="8080" />
          </Endpoints>
       </VirtualMachineRole>
    </ServiceDefinition>
    
  6. Save the file in the root folder of the application as ServiceDefinition.csdef.

  1. Open a text editor, such as Notepad.

  2. The .cscfg file must have a ServiceConfiguration element. The following code example shows the definition of this element:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
    </ServiceConfiguration>
    
  3. You must add the Role element to the ServiceConfiguration element. The following example shows the addition of the Role element:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
       </Role>
    </ServiceConfiguration>
    
    ImportantImportant
    The value for the name attribute must match the name that was defined for the VirtualMachineRole element that was defined in the service definition file.

  4. Define the number of instances that are needed for the VM Role. The following example shows the addition of the Instances element:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
          <Instances count="2" />
       </Role>
    </ServiceConfiguration>
    

    You should set the count value to at least 2 to ensure availability of your application.

  5. Specify the VHD file that you want to use to initialize VM Role instances. This can either be a base VHD or a differencing VHD. The following example shows the addition of the OsImage element:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
          <Instances count="2" />
          <OsImage href="base.vhd" />
       </Role>
    </ServiceConfiguration>
    

    For more information about creating the base VHD, see Create a Server Image for a VM Role in Windows Azure. For more information about using a differencing VHD, see Change the Server Image for a VM Role in Windows Azure.

  6. (Optional) If you added the Diagnostics module to the service definition file, define the configuration settings for the module. The following example shows the configuration settings for the Diagnostics module:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
          <Instances count="2" />
          <OsImage href="base.vhd" />
          <ConfigurationSettings>
             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"
                value="DefaultEndpointsProtocol=https;AccountName=AccountName;AccountKey=AccountKey" />
          </ConfigurationSettings>
       </Role>
    </ServiceConfiguration>
    
  7. (Optional) If you added the RemoteAccess and the RemoteForwarder modules, define the configuration settings for the modules. The following example shows the configuration settings for the RemoteAccess and RemoteForwarder modules:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
          <Instances count="2" />
          <OsImage href="base.vhd" />
          <ConfigurationSettings>
             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"
                value="DefaultEndpointsProtocol=https;AccountName=AccountName;AccountKey=AccountKey" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" 
                value="UserAccountName" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" 
                value="EncryptedPassword" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" 
                value="ExpirationDate" /> 
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
          </ConfigurationSettings>
       </Role>
    </ServiceConfiguration>
    

    AccountUserName is the name of a user account that is created when the VM Role instance is created. AccountEncryptedPassword is the encrypted password for the user account that is created. AccountExpiration is the date that the user account expires. For more information about configuring a remote desktop connection, see Set Up a Remote Desktop Connection for a Role in Windows Azure.

  8. (Optional) If you added the Connect module, define the configuration settings for the module. The following example shows the configuration settings for the Connect module:

    
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
          <Instances count="2" />
          <OsImage href="base.vhd" />
          <ConfigurationSettings>
             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"
                value="DefaultEndpointsProtocol=https;AccountName=AccountName;AccountKey=AccountKey" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" 
                value="UserAccountName" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" 
                value="EncryptedPassword" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" 
                value="ExpirationDate" /> 
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.ActivationToken" 
                value="ActivationToken"/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Refresh" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Diagnostics" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.WaitForConnectivity" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.EnableDomainJoin" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainFQDN" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainControllerFQDN" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainAccountName" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainPassword" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainOU" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DNSServers" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Administrators" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainSiteName" value=""/>
          </ConfigurationSettings>
       </Role>
    </ServiceConfiguration>
    

    ActivationToken is the token that you retrieved from the Management Portal. The remainder of the required and optional settings are used for joining role instances to a domain. For more information about configuring a VM Role for Windows Azure Connect, see Enable Windows Azure Connect for a VM Role.

  9. Add the configuration information for the certificates that are used by the cloud service. The following example shows the addition of the certificate for remote access:

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
          <Instances count="2" />
          <OsImage href="base.vhd" />
          <ConfigurationSettings>
             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"
                value="DefaultEndpointsProtocol=https;AccountName=AccountName;AccountKey=AccountKey" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" 
                value="UserAccountName" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" 
                value="EncryptedPassword" />
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" 
                value="ExpirationDate" /> 
             <Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.ActivationToken" 
                value="ActivationToken"/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Refresh" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Diagnostics" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.WaitForConnectivity" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.EnableDomainJoin" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainFQDN" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainControllerFQDN" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainAccountName" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainPassword" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainOU" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DNSServers" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Administrators" value=""/>
             <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainSiteName" value=""/>
          </ConfigurationSettings>
          <Certificates>
             <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" 
                thumbprint="CertificateThumbprint" thumbprintAlgorithm="sha1" />
          </Certificates>
       </Role>
       
    
    </ServiceConfiguration>
    

    For more information about creating and using certificates with a VM Role, see Use Certificates With a VM Role in Windows Azure.

  10. Save the file in the root folder of the application as ServiceConfiguration.cscfg.

noteNote
You must install the Windows Azure Tools for Visual Studio 2010 to complete the steps in this section. To download the tools, see Windows Azure Downloads.

  1. Open Visual Studio 2010 as an administrator.

  2. Create a new project by using the Windows Azure Project template.

  3. Specify a name for your project and proceed through the wizard without selecting a role template. By doing this, you will create a project that contains only a service definition file and a service configuration file.

  4. To add the VM Role elements, right-click Roles, click Add, and then click Add New Virtual Machine Role.

  5. You must enter the credentials that are used for the VM Role, which are the certificate thumbprint and the subscription identifier. You can find this information in the Properties pane of the Management Portal.

  6. After entering the credentials, you select the base VHD that you previously uploaded.

    At this point in the process, the service definition contains the following information for the VM Role:

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="MyServiceName"
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
       <VirtualMachineRole name="VMRole1" />
    </ServiceDefinition>
    
    

    And the service configuration contains the following information:

      
    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="MyServiceName" 
       xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
       <Role name="MyVMRole">
          <Instances count="1" />
       </Role>
    </ServiceConfiguration>
    
    
  7. Ensure that you set the instances count to at least 2 and that the appropriate VM size is selected. To do this:

    1. In Solution Explorer, right-click the role node, and then click Properties.

    2. On the Configuration page, change the Instance count to 2 and select the VM size. The following table lists the allowable sizes of VHDs in Windows Azure.

      ImportantImportant
      For dynamic disks, the sizes in the table are the maximum sizes that the VHD can grow to as additional space is required.

       

      Windows Azure VM size Maximum mounted VHD size

      Extra Small

      15 GB

      Small

      35 GB

      Medium, Large, or Extra Large

      65 GB

  8. (Optional) Enable Diagnostics. You can collect diagnostic data related to the running role instances.

    1. In Solution Explorer, right-click the role node, and then click Properties.

    2. On the Configuration page, select Enable Diagnostics.

      If you enable diagnostic data collection, you must provide the credentials for a storage account. The default is to use the local storage account, but for deploying to Windows Azure you must define the settings for a Windows Azure storage account.

  9. Add an input endpoint for communication with the role instance. To do this, on the Endpoints page, click Add Endpoint, enter the name for the endpoint, select the type and the protocol, and then specify the port number.

  10. (Optional) Enable Windows Azure Connect for the role instances.

    • In Solution Explorer, right-click the role, and then click Properties.

    • In the Properties sheet, select the Virtual Network tab.

    • Select the Activate Windows Azure Connect check box, and then paste the activation token in the text box.

      The following line is added to the service definition file for importing the Connect module:

      <Import moduleName="Connect" />
      
      The following information is also added to the service configuration file:

      
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.ActivationToken" value="ActivationToken"/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Refresh" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Diagnostics" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.WaitForConnectivity" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.EnableDomainJoin" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainFQDN" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainControllerFQDN" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainAccountName" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainPassword" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainOU" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DNSServers" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Administrators" value=""/>
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainSiteName" value=""/>
      
      The only setting value that is needed for a connection that is not domain joined is the ActivationToken. If you intend to join the VM Role instance to a domain, you must provide required and optional values for the remainder of the settings.

  11. (Optional) Configure the remote desktop connection while publishing the package. Right click the project, click Publish, and then click Configure Remote Desktop connections.

    1. Select Enable connections for all roles.

    2. Select the certificate that you added to the cloud service.

    3. Enter the name and password of the account that is used for the remote desktop connection.

      The service definition now looks like the following:

      
      <ServiceDefinition name="MyVMRole" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
         <VirtualMachineRole name="VMRole1" vmsize="Medium">
            <Imports>
               <Import moduleName="Diagnostics" />
               <Import moduleName="RemoteAccess" />
               <Import moduleName="RemoteForwarder" />
            </Imports>
            <Endpoints>
               <InputEndpoint name="Endpoint1" protocol="http" port="80" />
            </Endpoints>
         </VirtualMachineRole>
      </ServiceDefinition>
      
      
      And the service configuration looks like the following:

      
      <ServiceConfiguration serviceName="MyVMRole" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
         <Role name="VMRole1">
            <Instances count="2" />
            <OsImage href="base.vhd" />
            <ConfigurationSettings>
               <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" 
                        value=" DefaultEndpointsProtocol=https;AccountName=AccountName;AccountNumber=AcountNumber" />
               <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
               <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" 
                        value="AccountName" />
               <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" 
                        value="EncryptedPassword" />
               <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" 
                        value="ExpirationDate" />
               <Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
            </ConfigurationSettings>
            <Certificates>
               <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" 
                            thumbprint="CertThumbprint" thumbprintAlgorithm="sha1" />
            </Certificates>
         </Role>
      </ServiceConfiguration>
      
      
      noteNote
      When you deploy the package to Windows Azure and you have enabled diagnostics, you must ensure that valid Windows Storage account credentials are used for the diagnostics connection string.

  12. Click OK. You will see the VM Role instances start and the status move to Ready in the portal.

You can use the CSPack Command Line Tool to package a service model for a VM Role application and then deploy the package using the Management Portal. You can also use Visual Studio 2010 to package and deploy the application. Before you start the procedures in this section, you must ensure that you have created a cloud service and a storage account in Windows Azure.

To deploy an application that contains a VM Role to Windows Azure, you must first upload the VHD and then you must package and deploy the service model, which consists of the service definition file and the service configuration file. To package the service mode files, you use the CSPack Command-Line Tool. After you create the service model package, you deploy the package to Windows Azure by using the Windows Azure Management Portal.

  1. Click Start, point to All Programs, and then click Windows Azure SDK.

  2. Right-click Windows Azure SDK Command Prompt, and then click Run as administrator.

  3. In the Windows Azure SDK Command Prompt window, change the directory to where your application files are located.

  4. Type the following command:

    cspack ServiceDefinition.csdef
    

    Where ServiceDefinition is the name of your ServiceDefinition.csdef file.

  1. Open the Management Portal.

  2. Create a new cloud service if you do not already have one.

  3. You can deploy your application to the staging deployment environment or the production deployment environment. Click the cloud service in the center pane, and then click either New Staging Deployment, or New Production Deployment.

  4. On the Create a New Deployment page, enter the name of the new deployment, browse to and select the package file that you previously created, browse to and select the configuration file of the service model, and then click OK.

To deploy an application that contains a VM Role to Windows Azure, you must first upload the VHD and then you must package and deploy the service model, which consists of the service definition file and the service configuration file. You can use publish the service model from Visual Studio 2010.

  1. Open Visual Studio 2010 as an administrator, and then open Windows Azure Project that you previously created.

  2. In Solution Explorer, right-click the VM Role project, and then click Publish.

  3. In the Deploy Windows Azure Project dialog, click the Credentials drop-down and select <Add…> to add a new credential. In the Windows Azure Project Management Authentication dialog:

    1. Select the management certificate that you created and added to Windows Azure.

    2. Enter the subscription ID. You can copy and paste this value from the Properties pane of the Management Portal.

    3. Type a name that is used to identify the credentials, and then click OK.

  4. After the credentials are verified in Windows Azure, you select the Deployment environment to deploy to.

  5. Select the storage account to use for deployment.

  6. Type a name to identify the deployment in the Management Portal.

  7. Click OK.

See Also

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.