Hosting Kentico applications in Azure is an excellent way a company can expand into Microsoft’s cloud platform and keep hosting costs to a minimum. Kentico applications hosted in Azure run just as well as on-premise (if not better), while taking advantage of a Microsoft-maintained environment and redundant SQL server. While this is a great start for companies, they will immediately need to address costs when they deploy more than one application. A separate instance for each application will quickly increase hosting /usage fees. This article details how to leverage “multi-tenant” Windows Azure roles which will allow companies to “stack” applications within a single instance.
There are a number of projects/concepts you will need to obtain in order to stack multiple Kentico installations in a single Azure instance. This article will detail all the steps needed to successfully deploy the applications. There are documented methods for “stacking” sites in a single instance; however, Windows Azure has an inherent issue with the number of files within Kentico which prevent it from deploying correctly.
Azure Toolkit
The Azure Toolkit is an open source project on CodePlex. It is derived from code from
Steve Marx and creates a “deployment manager” application that runs on the Windows Azure instance. The role’s main functionality is to “watch” an Azure storage account for zip files. Once the role sees a zip file, it will download it locally, unzip it, and create a web site on the instance for the files.
Nathan Totten also has a great blog on the utility and it's usage.
Kentico Azure Deployment Kit
Kentico has prepared a Kentico Azure Deployment kit that contains all source files needed to run Kentico in Azure. The main parts are modifications Kentico has made to the source to access a storage account for file storage (for SmartSearch, WebAnalytics, and Media libraries).
Nuget Package Manager
The Nuget Package Manager is a Visual Studio 2010 extension which allows quick deployment of open source packages from Nuget.
To use the deployment manager role and web applications:
1. Convert the Kentico set to a web application
I have created a step by step
blog of deploying a Kentico site to Azure. It contains a number of tips to help the process succeed.
2. Download the Azure Toolkit
The Azure Toolkit contains a number of open source components that assist developers with a variety of functions within Azure. Included with these is the “multi-tenant web role.” The easiest way to obtain this is to use the Nuget package manager within Visual Studio. The Nuget package manager is a Visual Studio 2010 extension that allows you to connect to Nuget and obtain open source packages.
Nuget Package Manager
3. Configure the multi-tenant web role
To install and configure the role, create a cloud service application with a blank web role. From there, use the Nuget Package Manager with the “
install-package multitenantwebrole” command to install the package in your solution. Included in the package is a “ReadMe” file that will assist you with the configuration of your webrole/settings.
Web Role
If the application will need to use the file system (for SmartSearch/WebAnalytics/Media libraries), modify the webrole.cs file as follows:
public override bool OnStart()
{
RoleEnvironment.Changing += RoleEnvironmentChanging;
// Get credentials
string storageName = "[STORAGE ACCOUNT NAME]";
string sharedKey = "[STORAGE ACCOUNT KEY]";
StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(storageName, sharedKey);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, false);
// Initialize instance cache
LocalResource localCache = RoleEnvironment.GetLocalResource("InstanceDriveCache");
CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);
// Create container if not exist
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
blobClient.GetContainerReference("kenticodrives").CreateIfNotExist();
// Create cloud drive
myCloudDrive = storageAccount.CreateCloudDrive(
blobClient
.GetContainerReference("kenticodrives")
.GetPageBlobReference("kenticodrive.vhd")
.Uri.ToString()
);
// Create drive
try
{
myCloudDrive.Create(localCache.MaximumSizeInMegabytes);
}
catch
{
// Drive can be already created
}
myCloudDrive.Mount(localCache.MaximumSizeInMegabytes, DriveMountOptions.Force);
// This must be called in the OnStart method
// of the WebRole
deploymentEngine.Start();
return base.OnStart();
}
4. Deploy the web role to your Azure account
Once you have the multi-tenant web role installed in your solution and configured, deploy your web role to Azure. Deploying the role is a standard process and is relatively quick, considering the small size of the deployed role. I modified the code in the global.asax of web application to properly setup the CloudDrive for Kentico to use for file system storage (SmartSearch, WebAnalytics, Media Libraries).
public void Application_AuthorizeRequest(object sender, EventArgs e)
{
//Set up drive information for Azure
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
try
{
if (d.VolumeLabel.ToLower() == "windowsazuredrive")
{
string strDrive = d.Name.Substring(0, 1);
SearchHelper.CustomSearchPath = strDrive + ":/" + CMSContext.CurrentSite.SiteName + "/SmartSearch/";
HitLogProvider.LogDirectory = strDrive + ":/" + CMSContext.CurrentSite.SiteName + "/WebAnalytics/";
MediaLibraryHelper.MediaLibraryCustomPath = strDrive + ":/" + CMSContext.CurrentSite.SiteName + "/MediaLibrary/";
}
}
catch (Exception)
{
}
}
RequestHelper.LogRequestOperation("AuthorizeRequest", null, 0);
DebugHelper.SetContext("AuthorizeRequest");
CMSRequest.BeforeAuthorizeRequest(sender, e);
TIP
You may need to modify the web role code to accommodate your specific needs. It is possible to modify the webdeployengine.cs file to set up additional host headers and other IIS configurations.
5. Package your web application
In order to use the multi-tenant functionality you will need to package your web application to work with the code. To do this, “publish” your web application to a local folder. One completed, create a folder named “site” and copy the entire deploy contents into it. Next, zip the “site” folder containing the files and name the zip file using this format: [URL].zip
Zip files
TIP
The web role is capable of setting up an SSL binding when a site is deployed. Nathan Totten details this in his
blog. Just be sure to name your files correctly!
6. Deploy the web application to the Azure storage account
Once your instance is deployed and running create a “sites” container within your storage account. Copy your zip file into the sites container.There are several tools available to access your storage account.
Neudesic
TIP
The zip files will remain in the storage account. If they are removed, the web role will delete the file form the instance and your site will be gone.
7. Confirm the web role access the storage account and sets up the application
Once the zip file is copied to the storage account, the web role will check every 30 seconds for any new files. Once it finds one, the web role will download the new file, unzip it locally, and create a new web site in the instance. After the process is complete, access the site via the URL you specified to confirm everything is working as expected.
Deployed sites
After having the above in place, you can quickly deploy additional web applications by following the “deploy/zip/copy to storage account” steps above. The site creation process takes less than 5 minutes for most sites and will simplify development. If an update to a site is needed, all that is required is to update the zip file.
TIP
As for capacity, I have successfully deployed 8 sites in a single “small” Azure instance, 7 of which are Kentico applications. The small instance has 1.75 GB RAM, of which the role uses 75-90% on average. Our deployed sites are not-high traffic and use minimal resources. I would recommend deploying 3-4 applications to a small instance to make sure your get adequate performance. You may find that you need a larger instance to accommodate your sites’ traffic.
NOTE
Another solution for companies is to host multiple sites in a single Kentico instance. This approach may be completely appropriate for a company and is the recommended approach for hosting multiple sites. If isolation of sites is a requirement, know that it is completely possible to stack the applications using the above method.
Another note is to the topic of billing. Stacking applications in a single instance will negate the ability for detailed billing for each application. All usage will be on the role level and not on the individual application.