Az Lab 09c – Implement Azure Kubernetes Service

AZ-104-MicrosoftAzureAdministrator/LAB_09c-Implement_Azure_Kubernetes_Service.md at master · MicrosoftLearning/AZ-104-MicrosoftAzureAdministrator · GitHub

Task 1: Register the Microsoft.Kubernetes and Microsoft.KubernetesConfiguration resource providers.
Task 2: Deploy an Azure Kubernetes Service cluster
Task 3: Deploy pods into the Azure Kubernetes Service cluster
Task 4: Scale containerized workloads in the Azure Kubernetes service cluster

A Pod always runs on a Node.

A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the control plane

Task 1: Register the Microsoft.Kubernetes and Microsoft.KubernetesConfiguration resource providers.

From the Cloud Shell pane, run the following to register the Microsoft.Kubernetes and Microsoft.KubernetesConfiguration resource providers.

Register-AzResourceProvider -ProviderNamespace Microsoft.Kubernetes

Register-AzResourceProvider -ProviderNamespace Microsoft.KubernetesConfiguration


Task 2: Deploy an Azure Kubernetes Service cluster

In the Azure portal, search for locate Kubernetes services and then, on the Kubernetes services blade, click + Create, and then click + Create a Kubernetes cluster.

On the Basics tab of the Create Kubernetes cluster blade, specify the following settings (leave others with their default values):

Config

Scalling

Click Next: Node Pools > and, on the Node Pools tab of the Create Kubernetes cluster blade, specify the following settings (leave others with their default values):


Click Next: Access > and, on the Access tab of the Create Kubernetes cluster blade, leave settings with their default values:

Click Next: Networking > and, on the Networking tab of the Create Kubernetes cluster blade, specify the following settings (leave others with their default values):

Click Next: Integrations >, on the Integrations tab of the Create Kubernetes cluster blade, specify the following settings (leave others with their default values):

Click Review + create, ensure that the validation passed and click Create.

Note: In production scenarios, you would want to enable monitoring. Monitoring is disabled in this case since it is not covered in the lab.

Note: Wait for the deployment to complete. This should take about 10 minutes.

Task 3: Deploy pods into the Azure Kubernetes Service cluster

In this task, you will deploy a pod into the Azure Kubernetes Service cluster.

From the Cloud Shell pane, run the following to retrieve the credentials to access the AKS cluster:

RESOURCE_GROUP='az104-09c-rg1'

AKS_CLUSTER='az104-9c-aks1'

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

From the Cloud Shell pane, run the following to verify connectivity to the AKS cluster:

kubectl get nodes

# Verify that the one node which the cluster consists of at this point is reporting the Ready status.

NAME                                STATUS   ROLES   AGE     VERSION
aks-agentpool-37282351-vmss000000   Ready    agent   7m36s   v1.24.6

From the Cloud Shell pane, run the following to deploy the nginx image from the Docker Hub:

kubectl create deployment nginx-deployment --image=nginx

# Note: Make sure to use lower case letters when typing the name of the deployment (nginx-deployment)


From the Cloud Shell pane, run the following to verify that a Kubernetes pod has been created:

kubectl get pods

NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-85c6d5f6dd-xrbhp   1/1     Running   0          81s

From the Cloud Shell pane, run the following to identify the state of the deployment:

kubectl get deployment

From the Cloud Shell pane, run the following to make the pod available from Internet:

kubectl expose deployment nginx-deployment --port=80 --type=LoadBalancer

service/nginx-deployment exposed

From the Cloud Shell pane, run the following to identify whether a public IP address has been provisioned:

kubectl get service

NAME               TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
kubernetes         ClusterIP      10.0.0.1       <none>         443/TCP        17m
nginx-deployment   LoadBalancer   10.0.152.188   20.23.19.105   80:30137/TCP   39s

Re-run the command until the value in the EXTERNAL-IP column for the nginx-deployment entry changes from <pending> to a public IP address. Note the public IP address in the EXTERNAL-IP column for nginx-deployment.

Open a browser window and navigate to the IP address you obtained in the previous step. Verify that the browser page displays the Welcome to nginx! message.

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

Task 4: Scale containerized workloads in the Azure Kubernetes service cluster

In this task, you will scale horizontally the number of pods and then number of cluster nodes.

From the Cloud Shell pane, and run the following to scale the deployment by increasing of the number of pods to 2:

kubectl scale --replicas=2 deployment/nginx-deployment

From the Cloud Shell pane, run the following to verify the outcome of scaling the deployment:

kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-85c6d5f6dd-p4b29   1/1     Running   0          23s
nginx-deployment-85c6d5f6dd-xrbhp   1/1     Running   0          9m29s

From the Cloud Shell pane, run the following to scale out the cluster by increasing the number of nodes to 2:

RESOURCE_GROUP='az104-09c-rg1'

AKS_CLUSTER='az104-9c-aks1'

az aks scale --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER --node-count 2

From the Cloud Shell pane, run the following to verify the outcome of scaling the cluster:

kubectl get nodes

# Note: Review the output of the command and verify that the number of nodes increased to 2

NAME                                STATUS   ROLES   AGE     VERSION
aks-agentpool-37282351-vmss000000   Ready    agent   28m     v1.24.6
aks-agentpool-37282351-vmss000001   Ready    agent   2m58s   v1.24.6

From the Cloud Shell pane, run the following to scale the deployment:

kubectl scale --replicas=10 deployment/nginx-deployment

From the Cloud Shell pane, run the following to verify the outcome of scaling the deployment:

kubectl get pods

# Note: Review the output of the command and verify that the number of pods increased to 10.

NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-85c6d5f6dd-4d2f6   1/1     Running   0          26s
nginx-deployment-85c6d5f6dd-lqvdj   1/1     Running   0          26s
nginx-deployment-85c6d5f6dd-nrc9n   1/1     Running   0          26s
nginx-deployment-85c6d5f6dd-p4b29   1/1     Running   0          10m
nginx-deployment-85c6d5f6dd-pbxqk   1/1     Running   0          26s
nginx-deployment-85c6d5f6dd-prqw8   1/1     Running   0          26s
nginx-deployment-85c6d5f6dd-tcrjs   1/1     Running   0          26s
nginx-deployment-85c6d5f6dd-wmjn8   1/1     Running   0          26s
nginx-deployment-85c6d5f6dd-xrbhp   1/1     Running   0          19m
nginx-deployment-85c6d5f6dd-zxvgf   1/1     Running   0          26s

From the Cloud Shell pane, run the following to review the pods distribution across cluster nodes:

kubectl get pod -o=custom-columns=NODE:.spec.nodeName,POD:.metadata.name

# Note: Review the output of the command and verify that the pods are distributed across both nodes.

aks-agentpool-37282351-vmss000000   nginx-deployment-85c6d5f6dd-4d2f6
aks-agentpool-37282351-vmss000001   nginx-deployment-85c6d5f6dd-lqvdj
aks-agentpool-37282351-vmss000000   nginx-deployment-85c6d5f6dd-nrc9n
aks-agentpool-37282351-vmss000000   nginx-deployment-85c6d5f6dd-p4b29
aks-agentpool-37282351-vmss000001   nginx-deployment-85c6d5f6dd-pbxqk
aks-agentpool-37282351-vmss000001   nginx-deployment-85c6d5f6dd-prqw8
aks-agentpool-37282351-vmss000001   nginx-deployment-85c6d5f6dd-tcrjs
aks-agentpool-37282351-vmss000001   nginx-deployment-85c6d5f6dd-wmjn8
aks-agentpool-37282351-vmss000000   nginx-deployment-85c6d5f6dd-xrbhp
aks-agentpool-37282351-vmss000000   nginx-deployment-85c6d5f6dd-zxvgf

From the Cloud Shell pane, run the following to delete the deployment:

kubectl delete deployment nginx-deployment