Deleting an AKS resource

The simplest version is if you have everything in a dedicated resource group, in that case, delete the resource group then:

kubectl config delete-context aks-contoso-video

replace aks-contoso-video with whatever your app was called.

Example output:

deleted context aks-contoso-video from /home/user/.kube/config

Deploy to Azure Kubernetes Service Cluster (AKS)

This example is done using Azure Cloud Shell but you can just use azcli.

create deployment.yaml

# deployment.yaml
apiVersion: apps/v1 # api resource where this workload resides
kind: Deployment # kind of workload we are creating
metadata:
  name: contoso-website # name of deployment
spec:
  selector: # Define the wrapping strategy
    matchLabels: # Match all pods with the defined labels
      app: contoso-website # Labels follow the `name: value` template
  template: # This is the template of the pod inside the deployment
    metadata:
      labels: # allows deployments to find and group pods
        app: contoso-website
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers: # this is where we define all containers
        - image: mcr.microsoft.com/mslearn/samples/contoso-website
          name: contoso-website
          resources: # specify minimum and max resources app is allowed to use from cluster
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 250m
              memory: 256Mi
          ports:
            - containerPort: 80 # this container exposes port 80
              name: http

Apply the Manifest

kubectl apply -f ./deployment.yaml

Example output: deployment.apps/contoso-website created

Check if deployment succeeded

kubectl get deploy contoso-website

Example output:

NAME              READY   UP-TO-DATE   AVAILABLE   AGE
contoso-website   0/1     1            0           16s

Check if pod running

kubectl get pods

Example output:

NAME                               READY   STATUS    RESTARTS   AGE
contoso-website-7c58c5f699-r79mv   1/1     Running   0          63s

Creating an AKS cluster

using bash (Azure Cloud Shell)

export RESOURCE_GROUP=rg-contoso-video
export CLUSTER_NAME=aks-contoso-video
export LOCATION=canadaeast

Create Resource Group

az group create --name=$RESOURCE_GROUP --location=$LOCATION

Example Output:

{
  "id": "/subscriptions/5e6a8cc2-0f92-4949-8218-cfdb9092ba32/resourceGroups/rg-contoso-video",
  "location": "canadaeast",
  "managedBy": null,
  "name": "rg-contoso-video",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

Create the AKS cluster

az aks create \
    --resource-group $RESOURCE_GROUP \
    --name $CLUSTER_NAME \
    --node-count 2 \
    --generate-ssh-keys \
    --node-vm-size Standard_B2s \
    --network-plugin azure

Add another node pool (linux)

az aks nodepool add --resource-group $RESOURCE_GROUP --cluster-name $CLUSTER_NAME --name userpool --node-count 2 --node-vm-size Standard_B2s

Link with kubectl

az aks get-credentials --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP

This command adds an entry to your ~/.kube/config file, which holds all the information to access your clusters. Kubectl enables you to manage multiple clusters from a single command-line interface.

kubectl get nodes

example output:

NAME                                STATUS   ROLES   AGE    VERSION
aks-nodepool1-39269080-vmss000000   Ready    agent   36m    v1.28.9
aks-nodepool1-39269080-vmss000001   Ready    agent   36m    v1.28.9
aks-userpool-40567055-vmss000000    Ready    agent   2m7s   v1.28.9
aks-userpool-40567055-vmss000001    Ready    agent   2m8s   v1.28.9

First Previous 1 2