Deploying Rancher Hosts via an Azure Resource Manager Template

Introduction

In Azure there are two “generations” (so to speak) ;

  • “Service Management” : the backend of the “old” portal
  • “Resource Manager” : the backend of the “new” portal

The technology underneath differs quite a bit…Though the “Azure Resource Manager” (or “ARM”) has the possibility to work with templates for deployments.

arm_templates

In the last blog post, I showed you how you can deploy nodes in Azure from your Rancher host. Today we’ll do it the other way around… We’ll deploy hosts using an “ARM”-template and will connect back to our Rancher host in one quick move!

 

Prep

First thing to do is go to your Rancher host and select “Add host”. Browse to “Custom” and note the api URL shown in step #4.

2016-01-18 14_42_26-Start

For Example

http://rancher.westeurope.cloudapp.azure.com:8080/v1/scripts/1AAA1224A123A1AAA1AA:1111122000000:aaa0AaaaaaaA0aaa5a1a4aAaa

Note this one down, as we’ll be needing it in a bit…

 

Depoying via an ARM-template

Getting the API link was the “hard” part, and now comes the easy stuff! Browse to the following BitBucket repository ; https://bitbucket.org/kvaes/azure-rancher

This contains the deployment template(s). To make it real easy, I created a link in the readme markdown so that you just have to click it.

2016-01-18 14_47_03-Start

After clicking on the “Deploy to Azure”, you’ll be redirected to the “new portal” and asked to provide the parameters you want to use for this deployment…

2016-01-18 14_48_21-New notification

The following parameters are available (source for the paranoia ones) ;

  • newstorageaccountname ; the name of the newly created storage account that will host all the new hosts
  • admin username & password ; the credentials to login to your host
  • dnsnameforpublicip ; the name of the public ip
  • rancherapi ; here you enter the URL we just copied from the Rancher host!
  • ranchernodename ; the prefix hostname for all the hosts you’ll be deploying
  • ranchercount ; the amount of hosts your want to deploy

Enter all the information… Select a region & subscription. Create / select a resource group. Accept the legal mumbo jumbo and press Create. Now wait a while…Feel free to follow up on the deployment.

2016-01-18 14_54_14-Microsoft Edge

And the nodes will pop up in Rancher!

2016-01-18 14_53_24-Microsoft Edge

 

The Cool Stuff

For the deployment of the Rancher agent, I’m relying on the native DockerExtension of Azure!

{
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "[concat(parameters('rancherNodeName'), copyIndex(),'/', variables('extensionName'))]",
      "apiVersion": "2015-06-15",
      "location": "[resourceGroup().location]",
	  "copy": {
        "name": "extLoopNode",
        "count": "[parameters('rancherCount')]"
      },
      "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', parameters('rancherNodeName'), copyIndex())]"
      ],
      "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "DockerExtension",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "docker": {
            "port": "2375"
          },
          "compose": {
            "rancheragent": {
              "image": "rancher/agent:v0.8.2",
              "restart": "always",
			  "privileged": true,
			  "volumes": [
                "/var/run/docker.sock:/var/run/docker.sock"
              ],
              "command": "[parameters('rancherApi')]"
            }
          }
        }
      }

 

Hostname Fix!

I forgot to add the index number to the computername. So the Rancher screenshot shows four hosts with the same name, where the update of the script has fixed that.

 

TL;DR

  • We used ARM to deploy Docker hosts
  • We used the Azure DockerExtension to deploy our Rancher agent
  • We learned that ARM templates can be used in an easy manner too!

One thought on “Deploying Rancher Hosts via an Azure Resource Manager Template

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.