The goodness of Azure CLI Interactive shell


Off late I have been working a lot with terminal and command line interface (CLI) for things like Docker, Azure, Kubernetes etc. While working with these wonderful technologies they provide an easy way to auto-complete different commands. Without auto-completion its a nightmare to remember the syntax for each & every command. Even with auto-completion enabled sometimes it is really a pain to remember different parameters a command can take. Sometimes you have multiple options which can be assigned as a parameter value. Most of the times I find using the help feature with –h or –help option to know all these details about the command, its parameters and available options.

If you are starting new with some technology like Kubernetes or with cloud provider like Azure which has various services which can be managed using CLI it can be really difficult to get started. When it comes to Azure CLI there is an easy option called Interactive which simplifies things to a great extent. This short post is about my experience of using the Azure CLI interactive mode which I happened to discover by accident.

Azure CLI Interactive mode

First of all you need to install the latest version of Azure CLI 2.0. We need to execute the following command in our favorite terminal. I use zsh as my default terminal along with the oh-my-zsh plugin.

az interactive 

Once we enter the interactive mode, the terminal changes look & feel. Lets use some of the commands from our previous post on provision Kubernetes cluster in AKS.

Auto suggestion resource names

The moment I start typing, I can see auto suggestion for different resources that can be managed using Azure CLI. AZ autocomplete resource name

Lets choose aks as the resource we want to interact with using the command line. We will use the create command.

Command details

AZ command details

Once we have chosen the command, the bottom part of the screen is refreshed automatically or I should say magically to display relevant details of the command. We can find command description in the first pane. The next pane shows some examples how the command can be executed. In the above screenshot we can see 3 examples how the create command can be invoked with different parameters. At the bottom pane we can see the keyboard shortcut keys for layout(F1), default values (F2) etc. On the rightmost corner we can also see the current active subscription.

Parameter details with description

As soon as we finish writing create, we can see the auto suggestion popping up for the parameters along with the description of the parameter.

AZ parameters list with explanation

This is simply amazing. I get to know which are the required parameters and which are the optional parameters at one glance. I also get helpful description for each parameter with hints like in case of kubrnetes-version. Here is a quick example of the hint

AZ parameter suggestions with default help

I did not know that the default group can be configured using the command az configure –default group=<name>. I find it quite useful that such hints can help to learn the different commands quite fast.

Filter & Auto suggest existing resources

Another interesting feature I found out about the interactive shell was its capability to filter existing resources. Let me take an example once again. I have some resource groups already created. When I try to add the –resource-group parameter, I get an auto suggestion for all the available groups as shown below

AZ autocomplete existing resources

I no longer need to remember the lengthy names of different resources.


I touched just the tip of the iceberg during this post. I found it very useful and a huge productivity gain when I started using the interactive shell. I hope you can make good use of this when you are trying to familiarize yourself with different options related to managing numerous resources using Azure CLI. Playing around with Azure command line has never been so much fun before. Interactive command line makes the whole learning experience much more exciting. I am pretty sure that once you get used to the amazing az cli you would never want to go back to the –h –help option ever again. I wish other tools will also implement such features.

Until next time code with passion and strive for excellence.


Provision Kubernetes cluster using AKS


kubernetes control plane
This is the first part of the series on building highly scalable multi-container apps using AKS. As mentioned in the earlier post I will be building this series using Kubernetes as an Orchestrator for managing the cluster on which our Docker containers will be running. I assume that the readers have preliminary knowledge about Docker and containers in general.

Need for Orchestration

Lets try to understand the need for container orchestration. Docker containers are great at packaging the applications into self contained images. When we start running these images as containers in production, we need to address cross-cutting concerns like high availability, monitoring, resilience, scaling, disaster recovery etc. Containers on their own are not capable of addressing such requirements. This is where Container Orchestration comes into the picture. Think of it as an operating system for containers which also has many other advanced features apart from managing the lifecycle of containers.
Kubernetes originates from a Greek word which means pilot. Commonly referred to as k8s, it was originally designed by Google and now it is maintained by Cloud Native Computing Foundation (CNCF). Since its v1.0 release in July 2015, Kubernetes has been growing in popularity regularly. I found an excellent article from Deis called ‘The children’s illustrated guide to Kubernetes’, which explains some of the concepts related to Kubernetes in a very basic terms like a story teller.
Some of the salient features of Kubernetes include
  • Service Discovery
  • Load Balancing
  • Secrets / configuration / storage management
  • Heath checks
  • Auto scaling / restart / healing of containers and nodes
  • Zero-downtime deploys
We will cover these features in details as we go along this series. Lets start with the first step of our journey in familiarizing with Kubernetes. We will be performing following actions during this post
  1. Enable AKS preview for Azure subscription
  2. Provision managed Kubernetes cluster using Azure CLI
  3. Verify cluster resources using Kubernetes control plane


I will be using Azure CLI to perform different actions related to my Azure subscription. If you wish to follow along with me, Azure CLI can be installed using the instructions detailed here. I have Azure-cli version 2.0.27 installed on my Mac.
If you do not wish to install Azure CLI there is an alternative approach of using Azure Cloud shell which has Azure CLI preinstalled. I prefer to work inside terminal on my own laptop instead of using the cloud shell.
Kubernetes command line tool Kubectl can be installed in different ways. You can refer to the documentation for exact steps for your operating system. I will install it as part of the AKS setup.

Enable AKS preview for Azure subscription

We can provision Kubernetes cluster using Azure Container Service (ACS) or using the recently announced preview of the fully managed Kubernetes service using  Azure Container Service (AKS). As of this writing preview the service is available in eastus, westeurop, centralus, canadacentral and canadaeast regions.
The preview service is not enabled for the Azure subscription by default. We need to enable the preview. This can be done using the Azure CLI with command
az provider register -n Microsoft.ContainerService
It will take few minutes for the service to be activated. We can monitor the progress of registration using the command
az provider show -n Microsoft.ContainerService
After successful activation of the preview, we will see output similar to the screenshot.

Create shell variables

We will be repeatedly using some values for both the Azure CLI & kubectl. So I added these values as variables to the shell. Here are the list of variables I will be using
resourceGroupLocaltion="East US"

Provision managed Kubernetes cluster using Azure CLI

I chose to create all my Azure resources in East US region which is set to the resourceGroupLocation variable. We can create the managed Kubernetes cluster resources in an existing resource group or create a dedicated resource group for AKS specific resources. I will create a dedicated resource group named k8sResourceGroup. We create the group using Azure CLI command
az group create \
--name $resourceGroupName \
--location $resourceGroupLocaltion \
--output jsonc
We have specified the output format as jsonc which optputs the result in json formatted text in color codes form for easy readability. Successful completion of the resource group creation will show an output similar to the screenshot below.
Create Resource group
The next step is to provision the Kubernetes cluster using AKS. We will start with 2 worker nodes and Kubernetes version 1.8.1
az aks create \
--resource-group $resourceGroupName \
--name $clusterName \
--node-count 2 \
--kubernetes-version 1.8.1 \
--output jsonc
Creation of cluster resources will take few minutes. Once again we are formatting the output as colored json. We will get the list of resources as shown below after the successful completion.
We can verify the same by logging into the Azure portal and checking the resources associated with the newly created resource group. We will see the output similar to the screenshot.
AKS resources

Install Kubernetes CLI

In order to interact with the cluster using command line interface we need to install the Kubernetes CLI generally referred to as kubectl.
az aks install-cli
Once the kubectl is installed we can start interacting with the cluster. First we need to get the credentials to connect to the cluster.
az aks get-credentials \
--resource-group $resourceGroupName \
--name $clusterName
We are now set to begin our Kubernetes journey with kubectl. Lets first get the information about the cluster. The cluster-info command gives us details related to where the Kubernetes master and other services are running
kubectl cluster-info
kubectl cluster-info
We can get the information about worker node using get nodes command
kubectl get nodes
kubectl get nodes

Verify cluster resources using Kubernetes control plane

Kubernetes provides control plane to visualize the state of cluster resources. We can proxy from our local machine to the control plane using the command
az aks browse \
--resource-group $resourceGroupName \
--name $clusterName
This will open the webpage in the default browser and connect to the Overview section. The page shows the default services installed by Kubernetes.
kubernetes control plane
With this we have successfully provisioned a 2 node managed Kubernetes cluster using AKS in Azure. As can be seen from the screenshot, we can access all the resources like namespaces, pods, replica sets, secrets, volumes etc.


We have stared our journey with Kubernetes with this new cluster. It is quite easy to get started with Kubernetes using the Azure Kubernetes Service (AKS). As we saw during this post with 5-6 commands we can provision the fully managed cluster. One of the advantage of using the managed Kubernetes cluster is that we need not pay for the master node. Azure billing is applicable only for the number of agent nodes that we provision. We will start making use of this cluster from the next part of the series.

Update: As part of multipart video series on Kuberentes Based Event Driven Autoscaling (KEDA), the recording of the steps required to provision an AKS cluster is available in the following video Until next time, Code with Passion and Strive for Excellence.

Highly scalable multi-container apps using AKS


Earlier I had written a series of posts on how to build a Continuous Deployment pipeline along with Continuous Integration for multi-container application using Docker and Visual Studio Team System (VSTS). Today I begin a new series of posts about building highly scalable application using Docker. While the earlier series was using Docker Swarm as an Orchestration Engine running in Azure Container Service (ACS), this series will be based on the Azure Container Service (AKS). AKS provides Kubernetes as managed service in Azure.

One of the reason for moving away from Docker Swarm is based on the recent announcement from Microsoft that Kubernetes is available as a new managed service. Kubernetes is becoming a de facto standard for container orchestration. Although Azure will support existing Docker Swam & DC OS cluster deployments, the future seems to be moving in the direction of Kubernetes.


I will be building this demo on top of the previous codebase. The pre-requisites mentioned in the earlier series are applicable here as well like VSTS account for Continuous Integration, Github as source code management tool, DockerHub account for storing Docker images. In fact I will be reusing the CI pipeline built in the earlier series to push images to DockerHub. The major change is the Azure subscription with the right privileges to create Kubernetes cluster.

What to expect during this series?

I will be focusing more on Azure Container Service features during this series. Some of the things I intend to cover include

For now the list seems quite long. I am sure as I go along more tools and concepts will be clear and I will share them along the way.

Quick overview of the application

Application overview

The demo application we will be using is built on ASP.NET Core framework and has a MVC front end and a basic web API. There is also SQL Server 2017 on Linux which acts as a persistent storage. All these 3 components are running inside Docker containers. As we go along we might add new features to the application which will help to showcase the power of Docker and Kubernetes along with key services provided by Azure.

I am excited to take this journey and hope the readers will also find it interesting. Get ready to play around with the Kubrnetes CLI using kubectl. Feel free to add any other related topic using the comments section and I will be happy to accommodate them during this series.

Until next time code with passion and strive for excellence.