Deploy Kubernetes with Azure Kubernetes Service: Part 1

Azure Kubernetes Service Workshop

C.J. Shields
4 min readAug 3, 2020

In this workshop, I’m going through tasks to deploy a multicontainer application to Kubernetes on Azure Kubernetes Service (AKS). This lab requires a full pay as you go subscription from Microsoft to complete.

This is a 9 part project, part 2 coming shortly.

First step I took into this lab was create my variables and resource group. I used eastus as my region for this.

REGION_NAME=eastus
RESOURCE_GROUP=aksworkshop
SUBNET_NAME=aks-subnet
VNET_NAME=aks-vnet

Create my resource group

az group create \
— name $RESOURCE_GROUP \
— location $REGION_NAME

Configure Networking

Next I’ll need to create my virtual network. The pods deployed in my cluster will receive and IP address from this subnet. Run this command to create our virtual network

az network vnet create \
— resource-group $RESOURCE_GROUP \
— location $REGION_NAME \
— name $VNET_NAME \
— address-prefixes 10.0.0.0/8 \
— subnet-name $SUBNET_NAME \
— subnet-prefixes 10.240.0.0/16

Next I stored the VNET name in a BASH varible below”

SUBNET_ID=$(az network vnet subnet show \
— resource-group $RESOURCE_GROUP \
— vnet-name $VNET_NAME \
— name $SUBNET_NAME \
— query id -o tsv)

Create the AKS cluster

The command below stores the value that returns from the az aks get-versions command to the bash variable VERSION

VERSION=$(az aks get-versions \
— location $REGION_NAME \
— query ‘orchestrators[?!isPreview] | [-1].orchestratorVersion’ \
— output tsv)

To create a unique cluster name I ran the following command:

AKS_CLUSTER_NAME=aksworkshop-$RANDOM

To get the name of my cluster name, I used the following echo command:

echo $AKS_CLUSTER_NAME

This next command will take a minute to run. I used the az aks create command to create my Kubernetes cluster with the latest version

az aks create \
— resource-group $RESOURCE_GROUP \
— name $AKS_CLUSTER_NAME \
— vm-set-type VirtualMachineScaleSets \
— node-count 2 \
— load-balancer-sku standard \
— location $REGION_NAME \
— kubernetes-version $VERSION \
— network-plugin azure \
— vnet-subnet-id $SUBNET_ID \
— service-cidr 10.2.0.0/24 \
— dns-service-ip 10.2.0.10 \
— docker-bridge-address 172.17.0.1/16 \
— generate-ssh-keys

Test cluster connectivity by using kubectl

I will use the az aks get-credentials command to configure my instance of kubectl

az aks get-credentials \
— resource-group $RESOURCE_GROUP \
— name $AKS_CLUSTER_NAME

The kubectl get nodes command will show you what was deployed by listing all of the nodes in my cluster. Below is the list of nodes.

kubectl get nodes

Create a Kubernetes namespace for the application

A namespace in Kubernetes creates a logical isolation boundary. Names of resources must be unique within a namespace but not across namespaces. If you don’t specify the namespace when you work with Kubernetes resources, the default namespace is implied

kubectl get namespace

Next Ill use the following command to name our namespace

kubectl create namespace ratingsapp

--

--