Azure Cloud Shell vs Azure CLI

At a local community event, after my presentation I was answering some questions and one of the attendee ask me if Azure Cloud Shell is the same tool as Azure CLI.

So here is, Azure Cloud Shell is a containerized based shell running in the Azure Portal (or in the browser), using either a Linux (Bash) or Windows (PowerShell) base containers. Both containers are supported by Azure CLI, as well as the Windows based containers supporting Azure PowerShell. For more information How to use Azure Cloud Shell, visit the previous post (here).

As far as I know, Microsoft updates the CLI and the PowerShell version on a regular basis to whatever is the most stable and updated version. The update is applied to the respective container (Bash to the Linux container, and PowerShell to the Windows container (Windows Server 2016)), so everyone is always running the latest version on Azure Cloud Shell.

Is that mean that when we enable the Azure Cloud Shell, we are creating 2 containers? Yes. If you see the previous post, about how to use Azure Cloud Shell (see link above), you will see that on creation of the resources needed, beside the Resource Groups, Storage Accounts and File Shares, you are also creating the containers. Although, those are on the fly. That means every time you open the Azure Cloud Shell, you are connecting to the respective container.

Bash and PowerShell with possibility to run CLI?

You have the choice to run a Windows based cloud shell or a Linux based one. On the Windows one, comes with Azure PowerShell and also Azure CLI (on Bash on Windows). On the Linux one, comes with Bash and Azure CLI. In future, it will also support Azure PowerShell on Linux.

The Azure Cloud Shell comes with preinstalled open source PowerShell in both, Windows- and Linux-based Cloud Shell. I want to clarify that on Windows based cloud shell, Azure CLI runs directly in cmd.exe (Bash on Windows is not enabled in cloud shell yet).

Cheers,

Marcos Nogueira
Azure MVP

azurecentric.com
Twitter: @mdnoga

How to use Azure Cloud Shell

Since when they announce the Azure Cloud Shell (see post here), I’ve been waiting to use the PowerShell on the Azure Cloud Shell. I’m still growing my learning how to use the Azure CLI, but PowerShell I’ve been using for years, and I feel way more comfortable with it.

So, how I can use Azure Cloud Shell? Just open the Azure Portal, and on the top bar, between the Notifications and the Settings you will find the Azure Cloud Shell icon   .

When you click on the icon, it will ask you to configure the Azure Cloud Shell. The process will provision machines, where you can run the shells (Azure CLI and Azure PowerShell). It’s a fairly simple process. Just follow the steps below.

  1. Choose what is your Shell of choice. It doesn’t matter if you choose Bash or PowerShell. You can always switch back and forward after the initial setup.
  2. Choose what is the subscriptions that you want to use. Then you have the simple option of creating the storage or click in Show advanced setting. In this case I opt for the advanced settings.
  3. On the Advanced setting, you can specify the Resource Group, Storage Account and File Share names that you want to use.

    NOTE: Just remember that you have to follow the requirements how to create storage account and file shares (small caps and alphanumeric characters).
  4. In this case I select the Bash. After I click create, starting to provision the machines. First create all the resources from the previous step.
  5. After the creation of the resources, it’s connecting to the Bash terminal.
  6. And that is the end! Now you can start to use the Azure CLI on the Azure Portal.

Changing to PowerShell (or Shell)

After you create the Azure Cloud Shell, you can switch from Bash to PowerShell and vice versa. To do that, just follow the steps:

  1. Click on the Shell that you are using. In this case I was using Bash. When you click the drop box, you will see the other Shell.
  2. Select the Shell that you want. In this case PowerShell, then click Restart.

  3. After that, the Azure Cloud Shell is shutdown the previous Shell and it will restart on the new Shell (even if you never use it before).
  4. Now it’s creating all the resources required for the first use.
  5. After the creating of all the resources, it will connect to the terminal.
  6. Finished! Now you can you use the PowerShell on Azure portal.

Because you are login at the Azure Portal, you don’t need to run the PowerShell command Login-AzureRm. You can start from there.

Cheers,

Marcos Nogueira
Azure MVP

azurecentric.com
Twitter: @mdnoga

Azure Cloud Shell Everywhere

WOW! Microsoft did it again! If you didn’t saw the announcements at the Microsoft Build 2017 Conference, you should!

They announce a lot of new things, but regarding Azure one of may favorite is the application for IOS specific!

I see this App, as a savior in so many ways! Those times that you have a problem and you need immediately access to run a PowerShell script or that an action like restart a virtual machine or even something else, now you have the right tools at your reach! Be able to access Azure subscription through my mobile phone is amazing!

From what I was able to see and play with is basically your azure portal but on a IOS App! I’ve been setting up and playing on Azure with this app and it’s is really good.

Here are some of the screenshots from the Azure IOS App.

 

As you have on the Azure Portal, you can select what you want to see, by choosing your favorite. This is the shortcut view of what is the most interesting to you.

When you select the resource the information and the tasks that you can do are really like what is available on the Azure Portal.

Even the notification that you have in the Azure Portal is available here. So you can track what is going on your Azure tenant.

When you select, the Virtual Machine is really good to see a lot of information. Usually on Apps for smartphones you have a subset of capabilities of the main too (in this case the Azure Portal), but with this Apps you can do >80% of your daily basic tasks through this App.

And as you expected, Azure Cloud Shell will be available on the Azure App as well. Although it’s not available yet. At least for me (see picture bellow).

But this is probably the serious reason why I will use this app a lot. I store a lot of my scripts in my OneNote and be able to copy/paste into this PowerShell window and setup a S2S vpn, for example, while you are waiting for your food arrived is something that every “Azure Geek”/”Azure Centric Nerd” dream of, Right? The possibilities are unlimited!

 

 

Cheers,

Marcos Nogueira
azurecentric.com
Twitter: @mdnoga

 

Virtual Machine Scalability in Azure – Part 1

You can provide automatic scalability for Azure VMs by using Azure VM scale sets. A VM scale set consists of a group of automatically provisioned Windows or Linux virtual machines that share identical configuration and deliver the same functionality to support a service or application. With a VM scale set, the number of virtual machines can increase or decrease, adjusting dynamically to changes in demand for its workload. The workload should be stateless to efficiently handle deprovisioning of VMs when scaling in. To implement autoscaling, you should leverage capabilities of the Microsoft.Insights resource provider.

VM scale sets integrate with Azure load balancers to efficiently handle dynamic distribution of network traffic across multiple virtual machines. They also support network address translation (NAT) rules, allowing for connectivity to individual virtual machines in the same scale set. VMs in the same scale set are automatically distributed across five fault domains and five update domains.

From a storage perspective, you can configure VM scale sets with both managed and unmanaged disks. Using managed disks offers additional scalability benefits. In particular, with managed disks, when using an Azure Marketplace image to provision a VM scale set, you can scale out up to 1000 VMs. With unmanaged disks, the upper limit is 100 VMs per scale set.

When using custom images, managed disks allow you to scale out up to 100 VMs. With unmanaged disks, you should limit your deployment to 20 VMs. You can increase this number to 40 if you set the overprovision property of the VM scale set to false. This way, you ensure that the aggregate Input/Output Operations Per Second (IOPS) of virtual disks in the VM scale set stays below the 20,000 IOPS limit of a single Standard Azure storage account.

Note: VM scale sets are available only when using the Azure Resource Manager deployment model.

This solution differs from the classic VM horizontal scaling approach, which required you to preprovision each VM that you wanted to bring online, to accommodate increased demand.

Implementing VM scale sets

To provision a VM scale set, you can use the Azure portal, Azure PowerShell, Azure Command Line-Interface (Azure CLI), or Azure Resource Manager templates. When using templates, you should reference the Microsoft.Compute/virtualMachineScaleSets resource type. This resource type implements a number of properties, including:

  • tier. The size of the virtual machines in the VM scale set.
  • capacity. The number of virtual machine instances that the scale set will auto-provision.
  • virtualMachineProfile. The disk, operating system, and network settings of the virtual machines in the scale set.

To configure Autoscale, reference the Microsoft.Insights/autoscaleSettings resource type in an Azure Resource Manager template. Some of the more relevant properties that this resource type implements include:

  • metricName. The name of the performance metric that determines whether to trigger horizontal scaling (for example, Percentage CPU).
  • metricResourceUri. The resource identifier designating the virtual machine scale set to monitor.
  • timeGrain. The frequency with which performance metrics are collected (between 1 minute and 12 hours).
  • Statistic. The method of calculating aggregate metrics from multiple virtual machines (Average, Minimum, Maximum).
  • timeWindow. Range of time for metrics calculation (between 5 minutes and 12 hours).
  • timeAggregation. The method of calculating aggregate metrics over time (Average, Minimum, Maximum, Last, Total, Count).
  • Threshold. The value that triggers the scale action. For example, if you set it to 50 when using the Percentage CPU metricName, the number of virtual machines in the set would increase when the CPU usage exceeds 50 percent (specifics would depend on other parameters, such as statistics, timeWindow, or timeAggregation).
  • Operator. The criterion that determines the method of comparing collected metrics and the threshold (Equals, NotEquals, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual).
  • Direction. The type of horizontal scaling invoked as the result of reaching the threshold (increase or decrease, representing, respectively, scaling out or scaling in).
  • Value. The number of virtual machines added to or removed from the scale set (one or more).
  • Cooldown. The amount of time to wait since the most recent scaling event before the next action occurs (from 1 minute to 1 week).

To understand how Azure scale regarding the virtual machines, I recommend to watch this video from Mark Russinovich about Virtual Machine Scale Sets.

Why and when to use Azure CLI

I have been a heavy Windows user for many years, but lately I have been using another OS to increase my vision and experience. But the issue is, PowerShell is a Windows OS based, and usually is not available on Non-Windows OS (as far as I know). So, I need to evolve to another command line tool. The natural progression is Azure CLI. Ok, you probably get the picture, but what is Azure CLI? How Azure CLI can help us managing Azure from a Non-Windows OS devices?

The Azure CLI provides a command-line, shell-based interface that you can use to interact with your Azure subscriptions. Although for the most part, the Azure CLI offers the same set of features as the Azure PowerShell modules, two primary differences exist between them:

  • You can install and run the Azure CLI not only on the Windows operating system but also on Linux and OS X.
  • Because of its ability to run on Linux, it is straightforward to integrate the Azure CLI with several traditional shell-scripting tools, such as grep, awk, sed, xargs, and cut, thereby allowing Linux admins to use their existing skills.

The installation process for the Azure CLI depends on the target operating system; however, the installers for all the supported operating systems are available directly from the Azure Downloads page (see here). Like the Azure PowerShell modules, the Azure CLI for the Windows operating system relies on Web PI. On the Linux and OS X operating systems, you can perform the installation by using an npm package.

On the Windows operating system, the installation modifies the path system environment variable. Effectively, after you launch a command prompt window, you can automatically run any of the Azure CLI commands.

Note: All commands start with the word azure. To learn more about the Azure CLI syntax, run the following command from the Windows command prompt:
azure help

After you install the Azure CLI, you can connect to the Azure subscriptions that you want to manage. Like the Azure PowerShell modules, to establish such a connection, you first need to authenticate by using either a Microsoft account or a work or school account that exists in the Azure AD tenant associated with the target subscription.

To initiate the authentication process, run the following command from the command prompt:
azure login

A message displays, prompting you to start a browser and browse to the Device Login page, where you need to  enter the code provided in the same message. This step verifies the Azure CLI as the application publisher and allows you to type your user credentials to authenticate to the Azure subscription.

Azure AD authentication is token-based, and after signing in, the user remains authenticated until the authentication token expires. The expiration time for an Azure AD token is 12 hours.

After you authenticate, you can use the azure account list command to view a list of subscriptions associated with your account. If you have multiple subscriptions, you can specify the one you want to manage by using the azure account set command and providing either the subscription name or its ID.

Note: You can identify the subscription name and ID by reviewing the output of the azure account list command.

Unlike the Azure PowerShell modules, the Azure CLI uses separate modes for working with the Azure Resource Manager deployment model and the Service Management deployment model. Both modes use the same set of commands, and to switch between them, you can use the azure config mode command.

To switch to the Azure Resource Manager mode, run the following command:
azure config mode arm

To switch to the classic deployment mode, run the following command:
azure config mode asm

At this point, you can also use Azure PowerShell cmdlets to view, provision, and manage Azure services and resources.