Journey into Kubernetes - Azure: AKS


3 min read

In the past few articles, we did a lot of required prep work prior to creating the K8s cluster. We have a container registry, a Service Principal and have the appId/password for that SP written down somewhere safe. Finally, it's time to create our cluster!

The next few commands use the az aks command, so if you're interested, feel free to az aks --help to learn more about it. Otherwise... onwards with cluster creation!

az aks create -n CoolKubernetesCluster `
              -g CoolResourceGroup `
              --node-count 2 `
              --generate-ssh-keys `
              --service-principal <appIdOfServicePrincipal> `
              --client-secret <passwordOfServicePrincipal>

This will create a new cluster with 2 nodes (VMs), include your SSH keys in the cluster so you can run kubectl commands against it (it will create new keys in your OS if you don't have any), and use the SP we created in the previous article.

The az aks create command is pretty loaded. There are lots of flags you can use to customize your deployment, so I encourage you to use the aforementioned --help flag to check it out. For example, you can add the -s Standard_D2_v2 to create a smaller than default nodes. For a list of available VM sizes, I found this (now somewhat outdated) article. There's no way to get this list from the Azure CLI that I know of.

Keep in mind that once you create the cluster with this command, Azure will provision 2 VMs the size you selected and add them to something called a nodepool. All machines in the nodepool must be the same size, so if you provision the default size - Standard_DS2_v2 - and later want to scale your cluster, you will only be able to scale OUT in that nodepool. You can create a new nodepool though which will have larger size VMs and scale UP there.

Creating the cluster will take a few minutes. Once complete, you can check out your nodepool:

az aks nodepool list -g CoolResourceGroup --cluster-name CoolKubernetesCluster

Some things of interest in that object:

  • count: 2
  • enableAutoScaling: null
  • maxPods: 110
  • vmSize: Standard_DS2_v2

Count represents the number of nodes in this nodepool. Autoscaling is something you can enable, set some rules, and watch your nodepool scale out automatically when traffic gets heavy. MaxPods I believe is the maximum number of pods (container instances) a single node can handle. VmSize of course is the size of the VM.

One more step to merge AKS credentials into your local kube config. This sets the current kubectl context to point to the new cluster you created. Contexts are clusters. You may have a local cluster running in minicube and a remote cluster, so setting the context for kubectl is a good idea to make sure you're running commands against the correct cluster.

az aks get-credentials -n CoolKubernetesCluster -g CoolResourceGroup

This will merge the credentials into your .kube/config file and change the context. You should see this:

Merged "CoolKubernetesCluster" as current context in C:\Users\<yourusername>\.kube\config

If you already have kubectl installed, you can type in:

kubectl get nodes

This will show you all your nodes in the nodepool. Finally, we're interacting with the cluster!

If you don't have kubectl installed, you can do so via this command:

az aks install-cli

You'll have to follow instructions to add it to PATH environment variable.

That's it, you have a cluster! In the next article we're going to start building it out by creating some namespaces.

Did you find this article valuable?

Support Paul K by becoming a sponsor. Any amount is appreciated!