Kubernetes Service (AKS) cluster on Azure,using Azure CLI

We are going to deploy Kubernetes in Azure using Azure CLI

Make sure you have Azure CLI installed (version 2.0.27 or later) on the machine (Windows/macOS/Linux), here is how to install it.

Start the Command Line, Powershell (in my case) or the terminal (on macOS/Linux) and login into Azure

PS> az login

If the user has multiple subscriptions check by running

PS> az account list --output table

The output will be similar to the one below

az_account_list

To change the active subscription globally,  use az account set along with either the subscription ID or subscription name

PS> az account set --subscription xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx

To use a specific subscription for a command, just use the –subscription argument. This argument takes either a subscription ID or subscription name

PS> az group create --subscription xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx --location westeurope --name MyK8SRG

For this demo, the default subscription will be set globally

PS> az account set --subscription xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx

Then create a new resource group

PS> az group create --location westeurope --name MyK8SRG

Create Kubernetes Cluster with 3 nodes (default VM size is Standard_DS1_v2)

PS> az aks create --resource-group MyK8SRG --name MyK8SCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys

It will take a few minutes …

When it’s done, configure kubectl to connect to your Kubernetes cluster, use the az aks get-credentials command. This step downloads credentials and configures the Kubernetes CLI to use them.

PS> az aks get-credentials --resource-group MyK8SRG --name MyK8SCluster

If not install, install kubectl (Kubernetes command line interface)

PS> az aks install-cli

use kubectl to check the nodes

PS> kubectl get nodes

you should get something like this

kubectl_get_nodes

The cluster is ready for applications to be deployed

the demo by Kubernetes.io is a stateless app (Guestbook), the deployment will be done using YAML files:

  • frontend-deployment.yaml: the guestbook frontend deployment
  • frontend-service.yaml: the guestbook frontend service
  • redis-master-deployment.yaml: Redis master deployment
  • redis-master-service.yaml: Redis master service
  • redis-slave-deployment.yaml: Redis workers deployment
  • redis-slave-service.yaml: Redis workers service

Apply the Redis Master Deployment from the redis-master-deployment.yaml file:

PS> kubectl apply -f https://k8s.io/examples/application/guestbook/redis-master-deployment.yaml

Apply the Redis Master Service from the following redis-master-service.yaml file:

PS> kubectl apply -f https://k8s.io/examples/application/guestbook/redis-master-service.yaml

Apply the Redis Slave Deployment from the redis-slave-deployment.yaml file:

PS> kubectl apply -f https://k8s.io/examples/application/guestbook/redis-slave-deployment.yaml

Apply the Redis Slave Service from the following redis-slave-service.yaml file:

PS> kubectl apply -f https://k8s.io/examples/application/guestbook/redis-slave-service.yaml

Apply the frontend Deployment from the frontend-deployment.yaml file:

PS> kubectl apply -f https://k8s.io/examples/application/guestbook/frontend-deployment.yaml

Apply the frontend Service from the sj-frontend-service.yaml file (modified version):

The file (https://k8s.io/examples/application/guestbook/frontend-service.yaml) will not be used as it uses NodePort not LoadBalancer, the file (https://raw.githubusercontent.com/Data-Base/sharedwork/master/kubernetes/guestbook/sj-frontend-service.yaml) will be used instead

PS> kubectl apply -f https://raw.githubusercontent.com/Data-Base/sharedwork/master/kubernetes/guestbook/sj-frontend-service.yaml

Check the external IP

PS> kubectl get service frontend

if EXTERNAL-IP is  <pending> (wait, it may take few minutes around 5 minutes in my case)

To scale the number of nodes in the cluster

PS> az aks scale --node-count 5 --resource-group MyK8SRG --name MyK8SCluster

To scale the deployments in Kubernetes first get the deployment

PS> kubectl get deployment

Then scale the deployment (in our example: redis-master)

PS> kubectl scale deployment redis-master --replicas=1
PS> kubectl autoscale deployment redis-master --cpu-percent=50 --min=2 --max=10

To reach the Kubernetes’ web-based dashboard

PS> az aks browse --resource-group MyK8SRG --name MyK8SCluster

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.