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
- Enable AKS preview for Azure subscription
- Provision managed Kubernetes cluster using Azure CLI
- 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
resourceGroupName="k8sResourceGroup" resourceGroupLocaltion="East US" clusterName="coreDemoAKSCluster"
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.
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.
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
We can get the information about worker node using get nodes command
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.
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.
Until next time, Code with Passion and Strive for Excellence.