Quickly Stand Up Kubernetes with Azure Kubernetes Service
Getting started with Azure Kubernetes Service
Azure Kubernetes Service (AKS) is the managed Kubernetes distribution provided by Microsoft. It allows for seamless deployment of a managed Kubernetes cluster for containerized workloads. Microsoft has removed the headache of launching and configuring a cluster, while retaining the benefits of Kubernetes itself.
This post is a part of a series of posts outlining the ease of use of AKS; from launching your first cluster, deploying apps via Helm, and even CI/CD integration with Azure DevOps.
Related: What is Kubernetes?
The easiest way to learn how to work with AKS is to spin up a cluster of your own, so that's what we're going to do. There are several ways to launch your first cluster. For first time users, using the dashboard is probably the easiest method; however, this can be tedious to replicate.
Azure Resource Manager (ARM) templates can become complicated for those unfamiliar with its syntax and structure, though it does offer a great degree of portability and flexibility for resource creation.
az cli is a fantastic alternative, making the process scriptable and easy to understand. This is the method we will outline here, as it offers both the simplicity of the dashboard and the configurability of ARM templates. We'll be using it to build our AKS cluster, here are the installation instructions.
Azure and AKS CLI
az CLI tool to create a cluster is as simple as finding the correct configuration options to use.
az aks create --help will explain which items need to be supplied, as well provide several examples from we can work with. We will be going for simplicity here, there are more advanced options that will let us build a more complex cluster. These options will be enumerated in later posts.
You'll need to collect a few things before creating your cluster.
- Select a resource group for housing the cluster and related resources. You can use an existing one, or create one specifically for this cluster with the following command:
az group create --name myResourceGroup --location eastus
- Select an instance size for your nodes. I've selected the
Standard_D2s_v3for its smaller size.
The below code sample creates a three node AKS cluster using the default kubenet networking plugin.
az aks create --name "dev01" \ --resource-group "BoxBoatRG" \ --generate-ssh-keys \ --node-count "3" \ --node-vm-size "Standard_D2s_v3" \ --enable-vmss \ --enable-addons "monitoring"
From the command above, we can see that there are two additional options:
--enable-addons "monitoring". Using a Virtual Machine Scale Set (VMSS) allows for metrics-based autoscaling, while the monitoring addon creates a Logs Analytics workspace for storing system and container logs for the cluster. This is handled automatically by Azure.
We connect to this cluster by running a few more CLI commands:
az aks install-cli: Downloads the
az aks get-credentials -n dev01 -g boxboatrg --admin: Downloads the correct
kubectlconfig and loads it into the context. The
--adminoption sets up the current user with admin credentials. What this lets us do is run the
kubectlbinary to deploy our workloads.
Deploying a Sample App to Azure Kubernetes Service
Once we're connected, we can go ahead and deploy our application. We'll be using a simple hello world app (hello-boxboat) to test deploying to this cluster. The YAML spec (hello-aks.yaml) is posted below.
apiVersion: v1 kind: Service metadata: name: hello-aks spec: type: LoadBalancer ports: - port: 80 targetPort: 80 selector: app: hello-aks --- apiVersion: apps/v1 kind: Deployment metadata: name: hello-aks spec: replicas: 3 selector: matchLabels: app: hello-aks template: metadata: labels: app: hello-aks spec: containers: - name: hello-aks image: boxboat/hello-boxboat ports: - containerPort: 80
Simply copy and paste this YAML into a file called “hello-aks.yaml”, and deploy the application by executing
kubectl apply -f hello-aks.yaml.
This creates a Kubernetes Deployment object for our application, and a LoadBalancer Service exposed on port 80. Using
kubectl get svc hello-aks to find the public IP address and port, navigate to the endpoint to view the welcome page. Refreshing the page will allow for other hostnames to be displayed. And it's that simple! The app is up and running on our AKS cluster in seconds.
As a recap, let's take a look back at the commands we ran from start to finish, to get an idea of how easy the process was.
az aks create ...–> this created the AKS cluster
az aks install-cli–> this downloaded the
az aks get-credentials ...–> this downloaded credentials to remotely control the cluster
kubectl apply ...–> this deployed our application
As we can see, launching a Kubernetes cluster with AKS is extremely easy. There are of course ways to make it much more complicated, such as using existing virtual networks and subnets, backing cluster authentication with Azure Active Directory, or deploying apps through Helm charts. These topics and more will be covered in future posts.
Learn how to best introduce Kubernetes into your organization. Leave your name and email, and we'll get right back to you.
Get Hands on Training
Learn by doing. Step by step content created by professionals.Learn More