Tutorial - Deploy an application to Azure Kubernetes Service (AKS)
Kubernetes provides a distributed platform for containerized applications. You build and deploy your own applications and services into a Kubernetes cluster and let the cluster manage the availability and connectivity.
In this tutorial, part four of seven, you deploy a sample application into a Kubernetes cluster. You learn how to:
- Update a Kubernetes manifest file.
- Run an application in Kubernetes.
- Test the application.
Tip
With AKS, you can use the following approaches for configuration management:
GitOps: Enables declarations of your cluster's state to automatically apply to the cluster. To learn how to use GitOps to deploy an application with an AKS cluster, see the [prerequisites for Azure Kubernetes Service clusters][gitops-flux-tutorial-aks] in the [GitOps with Flux v2][gitops-flux-tutorial] tutorial.
DevOps: Enables you to build, test, and deploy with continuous integration (CI) and continuous delivery (CD). To see examples of how to use DevOps to deploy an application with an AKS cluster, see Build and deploy to AKS with Azure Pipelines or GitHub Actions for deploying to Kubernetes.
Before you begin
In previous tutorials, you packaged an application into a container image, uploaded the image to Azure Container Registry, and created a Kubernetes cluster. To complete this tutorial, you need the precreated aks-store-quickstart.yaml
Kubernetes manifest file. This file was downloaded in the application source code from Tutorial 1 - Prepare application for AKS.
This tutorial requires Azure CLI version 2.0.53 or later. Check your version with az --version
. To install or upgrade, see Install Azure CLI.
Update the manifest file
In these tutorials, your Azure Container Registry (ACR) instance stores the container images for the sample application. To deploy the application, you must update the image names in the Kubernetes manifest file to include your ACR login server name.
Get your login server address using the
az acr list
command and query for your login server.az acr list --resource-group myResourceGroup --query "[].{acrLoginServer:loginServer}" --output table
Make sure you're in the cloned aks-store-demo directory, and then open the
aks-store-quickstart.yaml
manifest file with a text editor.Update the
image
property for the containers by replacing ghcr.io/azure-samples with your ACR login server name.containers: ... - name: order-service image: <acrName>.azurecr.cn/aks-store-demo/order-service:latest ... - name: product-service image: <acrName>.azurecr.cn/aks-store-demo/product-service:latest ... - name: store-front image: <acrName>.azurecr.cn/aks-store-demo/store-front:latest ...
Save and close the file.
Run the application
Deploy the application using the
kubectl apply
command, which parses the manifest file and creates the defined Kubernetes objects.kubectl apply -f aks-store-quickstart.yaml
The following example output shows the resources successfully created in the AKS cluster:
statefulset.apps/rabbitmq created configmap/rabbitmq-enabled-plugins created service/rabbitmq created deployment.apps/order-service created service/order-service created deployment.apps/product-service created service/product-service created deployment.apps/store-front created service/store-front created
Check the deployment is successful by viewing the pods with
kubectl
kubectl get pods
Test the application
When the application runs, a Kubernetes service exposes the application front end to the internet. This process can take a few minutes to complete.
Command Line
Monitor progress using the
kubectl get service
command with the--watch
argument.kubectl get service store-front --watch
Initially, the
EXTERNAL-IP
for thestore-front
service shows as<pending>
:store-front LoadBalancer 10.0.34.242 <pending> 80:30676/TCP 5s
When the
EXTERNAL-IP
address changes from<pending>
to a public IP address, useCTRL-C
to stop thekubectl
watch process.The following example output shows a valid public IP address assigned to the service:
store-front LoadBalancer 10.0.34.242 52.179.23.131 80:30676/TCP 67s
View the application in action by opening a web browser and navigating to the external IP address of your service:
http://<external-ip>
.
If the application doesn't load, it might be an authorization problem with your image registry. To view the status of your containers, use the kubectl get pods
command. If you can't pull the container images, see Authenticate with Azure Container Registry from Azure Kubernetes Service.
Azure portal
Navigate to the Azure portal to find your deployment information.
Navigate to your AKS cluster resource.
From the service menu, under Kubernetes Resources, select Services and ingresses.
Copy the External IP shown in the column for the
store-front
service.Paste the IP into your browser to visit your store page.
Clean up resources
Since you validated the application's functionality, you can now remove the cluster from the application. We will deploy the application again in the next tutorial.
Stop and remove the container instances and resources using the
kubectl delete
command.kubectl delete -f aks-store-quickstart.yaml
Check that all the application pods have been removed using the
kubectl get pods
command.kubectl get pods
Next steps
In this tutorial, you deployed a sample Azure application to a Kubernetes cluster in AKS. You learned how to:
- Update a Kubernetes manifest file.
- Run an application in Kubernetes.
- Test the application.
In the next tutorial, you learn how to use PaaS services for stateful workloads in Kubernetes.