This article is the last in a 2 part series regarding Azure Kubernetes Service (AKS) clusters. Part 1 showed you how to create an AKS cluster and connect to it via the cloud shell. It also showed you how to connect to the Kubernetes dashboard.
Part 2 (this one) will show you how to deploy a simple application, test the application, monitor the health and logs, and delete the cluster.
So let’s get right too it.
Deploy an application
For this example, we are going to use a simple Kubernetes manifest file. This manifest file will define a desired state for the cluster we created in part 1. The below manifest file will create a Microsoft example application called Azure vote. The manifest file includes two Kubernetes deployments, one for the front end and the other for a Redis instance. It also includes two Kubernetes services, an internal service for the Redis instance and an external service so you can access the Azure Vote application.
Open cloud shell from within the Azure portal and make sure you’re in Bash and then type nano. You will now be in the nano text editor.

Copy the below yaml code to the nano window.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
apiVersion: apps/v1 kind: Deployment metadata: name: azure-vote-back spec: replicas: 1 selector: matchLabels: app: azure-vote-back template: metadata: labels: app: azure-vote-back spec: containers: - name: azure-vote-back image: redis resources: requests: cpu: 100m memory: 128Mi limits: cpu: 250m memory: 256Mi ports: - containerPort: 6379 name: redis --- apiVersion: v1 kind: Service metadata: name: azure-vote-back spec: ports: - port: 6379 selector: app: azure-vote-back --- apiVersion: apps/v1 kind: Deployment metadata: name: azure-vote-front spec: replicas: 1 selector: matchLabels: app: azure-vote-front template: metadata: labels: app: azure-vote-front spec: containers: - name: azure-vote-front image: microsoft/azure-vote-front:v1 resources: requests: cpu: 100m memory: 128Mi limits: cpu: 250m memory: 256Mi ports: - containerPort: 80 env: - name: REDIS value: "azure-vote-back" --- apiVersion: v1 kind: Service metadata: name: azure-vote-front spec: type: LoadBalancer ports: - port: 80 selector: app: azure-vote-front |

Now press Ctrl+O to save the file. Make sure you call it azure-vote.yaml. Once saved press Ctrl+X to exit nano.

To run the application you can use kubectl
1 |
kubectl create -f azure-vote.yaml |

Now for the Test
In a few moments, the application will start to spin up and become ready. You can check the progress by using the following command.
1 |
kubectl get service azure-vote-front --watch |
If it says pending then it is still deploying. Once you get an external IP address you know you are good to go.

Press Ctrl+C to drop back to the Bash prompt.
In a new tab enter the external IP address you got from the above command.

There you have it your app running in AKS.
What about Monitoring?
By default, when you create the cluster, container insights monitoring is enabled. This monitoring provides you access to health metrics for both the AKS cluster and all of your pods running on it.
Navigate to your Cluster resource in the Azure Portal and click on Insights on the left.

The first screen you see is related to the actual cluster. Above you can see that I increased the node count to 2. To view the pod’s health you need to click on Containers at the top.

To view the container logs you need to click on the container you want to see logs for. In the new blade that has popped up click on View Container Logs.

You will now be in the familiar Logs window. You can now use KQL to query the logs further.
Time to clean-up everything
Now that you have tested everything its a good idea to clean-up everything you have created to save you some money. To do this use the following command in Cloud Shell, but change the Resource Group and Cluster name to match yours.
1 |
az aks delete --resource-group PixelContainers --name PixelCluster --no-wait |

After a while you cluster will be gone.
Unfortunately, the command above will not clean-up the Azure Active Directory service principal used by the AKS cluster. To delete the service principal you can use the
1 2 |
az ad app list --query "[?displayName=='PixelClusterSP-20180915160014'].{Name:displayName,Id:appId}" --output table az ad app delete --id d377ee48-111f-4249-84c3-4e9a5bd0c718 |

There you have it, after following both parts you have created an AKS cluster, deployed an app, monitored it and then cleaned up everything. I hope you found this article helpful. If you have any questions please reach out in the usual methods.
0 Comments