Kubernetes adoption in the cloud: Azure Edition

Ms. BMs. B
4 min read

The term "imperative" cluster management in Kubernetes describes a particular method of cluster configuration and administration that emphasizes explicit instructions that specify precisely what steps the system should do.

Imperative management of a Kubernetes cluster indicates:

  1. You're utilizing commands like "create this," "delete that," and "update this component" that explicitly outline the steps to be taken.

  2. You are more concerned with "how" things should be done than "what" the final result should be.

  3. Commands like kubectl run, kubectl create, kubectl edit, and kubectl delete are commonly used.

For example, with imperative commands, you might:

  • kubectl create deployment nginx --image=nginx

  • kubectl expose deployment nginx --port=80

  • kubectl scale deployment nginx --replicas=3

Pros and cons of the imperative approach

Advantages

  • Greater authority over the specifics of what occurs

  • easier for short-term, one-time jobs

  • Simple procedures don't require configuration files to be maintained.

Disadvantages

  • Commands are not automatically documented, which results in poor reproducibility.

  • More challenging to handle complicated configurations

  • difficult to monitor changes over time

  • Lack of integrated version control

Note that the imperative approach can be useful for learning, testing, or managing simple clusters but most production Kubernetes environments move toward declarative management (using YAML manifests with tools like kubectl apply) as clusters grow more complex.

AKS allows you to quickly deploy a production ready Kubernetes cluster in Azure.

Now that you have an understanding of what this tutorial is about, let’s get to it.

Prerequisites

Before starting, ensure you have:

  1. An Azure account

  2. Azure CLI installed (az command available)

  3. kubectl command-line tool installed

Step-by-Step Process

1. Install and Configure Azure CLI

If you haven't already installed the Azure CLI:

# For Windows (using PowerShell)
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi
Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'

# For macOS
brew update && brew install azure-cli

# For Ubuntu/Debian
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

2. Login to Azure

az login

  1. . Create a Resource Group

     az group create --name productionResourceGroup --location eastus
    
  2. Create a directory named .ssh. SSH stands for Secure Shell. After creating the directory, run the next command as seen in the image below. The command generates a key for the ssh.

  1. Create an AKS cluster
az aks create \
  --resource-group productionResourceGroup \
  --name myAKSCluster \
  --node-count 3 \
  --nodepool-name sysemp \
  --node-resource-group newnode_rg \
  --generate-ssh-keys \
  --ssh-key-value ~/.ssh/urban-ssh.pub \
  --network-plugin azure \
  --enable-cluster-autoscaler 
  --min-count 2 \
  --max-count 3 \ 
  --zone 1

If you get an error after running the above command like the image above, go to the Azure portal - Subscription - Your Subscription - Settings - Resource Provider - Microsoft.Container Service - Register. After doing this, run the command again.

You should get something like this;

6. Get Credentials for the Cluster

az aks get-credentials --resource-group myAKSResourceGroup --name myAKSCluster

7. View all the resource group in your subscription

8. Verify Cluster Connection

kubectl get nodes

I also ran some commands to create namespace as you can see from the diagram below.

9. Deploy a Sample Application

Create a deployment:

kubectl create deployment nginx-deployment --image=nginx:latest

From the image above, you would notice I replicated my deployment in 3 places.

Expose the deployment:

kubectl expose deployment nginx-deployment --name=nginx-service --type=LoadBalancer --port=80 --protocol=TCP -n your-namespace

Check service status:

kubectl get service

I had an error when I ran the above command. My deployment was not found. So, I ran the next command specifying the namespace I had created and where my deployment was located.

kubectl get services --all-namespaces

Clean-up

When you're done with the cluster:

az group delete --name productionResourceGroup --yes

This is a powerful and potentially destructive command because:

  1. It will permanently delete ALL resources inside the resource group (VMs, storage accounts, databases, AKS clusters, etc.)

  2. The deletion is irreversible once initiated.

  3. The --yes flag bypasses the normal confirmation prompt, so it will execute immediately without asking "Are you sure?"

This command is often used when you want to clean up an entire environment at once, such as after testing or when decommissioning a project. It's more efficient than deleting individual resources one by one.

⚠️ Warning: Be extremely careful when running this command, especially in production environments. Double-check the resource group name to ensure you're not accidentally deleting critical resources.

Please like, share, comment and stay tuned for my next post.

2
Subscribe to my newsletter

Read articles from Ms. B directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ms. B
Ms. B

Hi, I'm a tech enthusiast who has decided to document her cloud journey as the day goes by. Stay tuned and follow me through this journey which I believe would be a wonderful experience. I'm also a team player who loves collaborating with others to create innovative solutions.