Getting Started with Azure Kubernetes Service (AKS)

While AKS has been gaining traction for a while now, many people are still confused about this new offering and what it means. In this blog post I’m going to cover some of the major questions around the Azure Kubernetes Service (AKS).

Does Azure support Kubernetes?

The quick answer to this question is Yes! Microsoft added a fully managed Kubernetes service in addition to their ACI (Azure Container Instances) service. Many enterprises want to adopt Kubernetes as their standard and it is fantastic that Microsoft allows you to standardize on Kubernetes while still gaining all the benefits of the Azure Cloud.

What is Kubernetes in Azure?

The easiest way to use Kubernetes in Azure is to use a service call Azure Kubernetes Service (AKS). This gives you a hosted Kubernetes cluster. What this means is Azure will host your master nodes for free with the option to upgrade to add an Uptime SLA for a small cost. This paid for option will give you a financially-backed uptime guarantee of 99.95% for the Kubernetes API, which is used to manage the cluster (e.g. kubectl). The 99.95% uptime guarantee includes the use of Azure Availability Zones. The uptime increases to 99.9% for clusters that do not use Azure Availability Zones.

Now, do not think that everything is free, you still have to pay for your nodes, but you only pay for what you use. When it comes to nodes, you have a few options. With AKS, you get something called node pools. These nodes are basically an Azure Virtual Machine Scale Sets (VMSS). With every AKS cluster, you need to have a Linux node pool. This node pool becomes the system node pool and will run all the system containers for the AKS cluster, DNS etc. Even though it is called the system node pool, you can still use it to schedule your own pods, but as you have all of the system pods running you do not get the full amount of CPU and Ram.

You can also add Windows node pools to AKS clusters now. This will allow you to run Windows containers in your AKS cluster. This is relatively new but so helpful. One down side from running Windows containers in AKS is scaling, Windows nodes can take a few minutes to create and get ready for scheduling, but as Windows node pools can never be a system node pool, they will never run the core Kubernetes pods, this means you get more CPU and Ram to use.

Make sure to always choose the right size nodes for your application.

What about Azure Container Instances?

The last option you have is to use Azure Container Instance https://azure.microsoft.com/en-us/services/container-instances/ to create virtual nodes. What this means is you can scale pods, or even run pods that are not part of your node pools (VMSS). This gives you very fast scaling and as ACI is per second billing it could work out cheaper for you. One downside currently is that it is for Linux only at the moment. So, for a lot of readers, this might not be a downside as Windows containers are not widely used

How do I use Azure Kubernetes service?

It is actually really easy to get up and running with AKS. You can actually deploy AKS using several different methods: the Portal, Azure CLI, Azure Resource Templates ARM templates and Terraform. For production workloads, I would recommend going with ARM templates or Terraform and look at creating them using DevOps practices. It is always good to think about your clusters as cattle and not pets. This means you need to be able to rebuild you cluster from scratch with minimal downtime. In the past, Microsoft would release a new feature, but it would only be available to new clusters. They are trying to make this not happen as much, but it is still going to help you out if you can rebuild a cluster quickly.

You can see my previous blog post on building an AKS cluster and go to the Next steps heading.

I know the question was “how do I use AKS” but I believe it is good to get the building stuff out of the way first. A solid foundation is always a win in my book. Until recently, you only had a couple of ways to use AKS, that was via the CLI or via the Azure Dashboard. I know what you are going to say, what about the third-party tools, well most of them use the cli in the backend. At the beginning of August, Microsoft released into preview a really cool feature that lets you manage your AKS resources via the Azure Portal. This is, in my opinion, a massive step forward in making the management of your container estate easier. You do not need to remember all the kubectl commands, you can easily delete resources via a mouse click, check what is currently running, the state of the pods and even edit yaml. It really is nice and perfect for beginners.

Now saying that, I still recommend that you get familiar with the Kubernetes CLI (kubectl). It is very powerful and will help you troubleshoot when something goes wrong, which it will, it always does when learning something new. Talking about the CLI lets show you a few simple commands to show you what is running in your cluster, looking at logs, deleting pods, etc. I am going to assume you have followed the guide from my previous blog post here, so you know how to connect to your AKS cluster.

To start with all the Kubernetes commands, start with kubectl. To list your pods (containers) you will use the following command

kubectl get pods --namespace default
kubectl get pods --namespace default command

By supplying the --namespace switch and the name of the namespace you will see all pods running in that namespace. As you can see, we only show the sample that we deployed in the last blog post. If you change the namespace to kube-system you will see all the system pods I spoke about earlier.

kubectl with --namespace command

Next let us look at deployments. You can use the following to do that. You will notice I have dropped the namespace now. This is because I am just using the default namespace which, as the name suggests, is the default namespace for all commands

kubectl get deployments
kubectl get deployments command

It does not show you much as we just have one deployment, but you can use the next command to go deeper. Sample is the name of the deployment.

kubectl describe deployment sample
kubectl describe deployment sample command

Here you can see a lot more information about the deployment.

Next, let us look at services you can use the following command to list all your services running.

kubectl get services
kubectl get services command

You can see the sample app from before with its external IP address. To get a bit more information, you can use the describe command.

kubectl describe service sample
kubectl describe service sample command

As you can see, you get a bit more information about the service.

That is a brief overview of the get and describe commands. Now if you wanted to delete the Kubernetes resources you can use the same command style as the get but swap the get to a delete. So, if I wanted to delete the sample pod, I would use the following (the pod name can be found by using the kubectl get pods command):

kubectl delete pod sample-64fdb99f87-rz284
kubectl delete pod command

You will see that pod is gone, but a new pod has taken its place due to it being in a deployment. That is a good way to restart a pod if needed.

The last thing I want to show is how to look at the pod logs. For this, you use the kubectl command again, but this time now get command. You can use the following:

kubectl logs -f sample-64fdb99f87-gxnb9
kubectl logs -f command

I highly recommend you have a look at the Kubernetes cheat sheet to learn more about the commands. https://kubernetes.io/docs/reference/kubectl/cheatsheet/

Can I use Azure to manage my on-premises Kubernetes Cluster?

This one is something new coming out of Microsoft and it is called Azure Arc. https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/overview It is still currently in preview, but it will let you manage any Kubernetes cluster from within the Azure portal. This means you can use Azure to put governance on top of your Kubernetes clusters (This is something to watch out for as it develops).

What is Kubernetes and Docker?

Interesting question. A lot of people seem to believe they are the same thing, but they are not. Docker is a container runtime, this basically means it is the program that runs your containers, where Kubernetes is the orchestrator.  What it does is it looks after your containers making sure they are scheduled (think deployed) on the nodes within your cluster. It helps make sure you are not over committing your nodes and using them for best value. It can also do a lot more, but that is a bit in-depth for this article. One thing to note is that AKS will be replacing Docker as it’s container runtime in favour of containers - everything should work the same, just always remember to test.

AKS diagram with Docker

Does AKS ever require updates?

The answer is a big, massive YES, and it is quite often. I would recommend you follow the GitHub repo for the releases. https://github.com/Azure/AKS/releases They also have a public roadmap that is worth looking at. You can find that at https://github.com/Azure/AKS/projects/1.

Round up

Hopefully, the above has answered some questions and made Kubernetes on Azure not feel as scary as it can feel. If you have any more questions, please reach out to me, I will do my best to answer any questions you may have. Let us know if you would like a video series on AKS. Also, if you want to see some more blog posts about AKS then why not check out my blog


Thanks for reading.

 
hooper.PNG

Richard Hooper

Richard Hooper is a Microsoft MVP with one of the top blogs at https://pixelrobots.co.uk . You can also find him on LinkedIn and Twitter

 
Previous
Previous

Azure AD Connect - Step by Step

Next
Next

Introduction to Azure Active Directory (AAD) and Azure AD Connect