Tutorial: Run applications in 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.
In later tutorials, you'll scale out and update your application.
This quickstart assumes you have a basic understanding of Kubernetes concepts. For more information, see Kubernetes core concepts for Azure Kubernetes Service (AKS).
Tip
AKS clusters can use GitOps for configuration management. GitOp enables declarations of your cluster's state, which are pushed to source control, to be applied to the cluster automatically. To learn how to use GitOps to deploy an application with an AKS cluster, see the prerequisites for Azure Kubernetes Service clusters in the GitOps with Flux v2 tutorial.
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 pre-created azure-vote-all-in-one-redis.yaml
Kubernetes manifest file. This file download was included with the application source code in a previous tutorial. Verify that you've cloned the repo and that you've changed directories into the cloned repo. If you haven't done these steps and would like to follow along, start with Tutorial 1: Prepare an application for AKS.
This tutorial requires that you're running the Azure CLI version 2.0.53 or later. Run az --version
to find the version. If you need to install or upgrade, see Install Azure CLI.
Update the manifest file
In these tutorials, an Azure Container Registry (ACR) instance stores the container image for the sample application. To deploy the application, you must update the image name in the Kubernetes manifest file to include the ACR login server name.
Get the ACR login server name using the az acr list command.
az acr list --resource-group myResourceGroup --query "[].{acrLoginServer:loginServer}" --output table
The sample manifest file from the git repo you cloned in the first tutorial uses the images from Microsoft Container Registry (mcr.microsoft.com). Make sure you're in the cloned azure-voting-app-redis directory, and then open the manifest file with a text editor, such as vi
:
vi azure-vote-all-in-one-redis.yaml
Replace mcr.microsoft.com with your ACR login server name. You can find the image name on line 60 of the manifest file. The following example shows the default image name:
containers:
- name: azure-vote-front
image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
Provide your own ACR login server name so your manifest file looks similar to the following example:
containers:
- name: azure-vote-front
image: <acrName>.azurecr.io/azure-vote-front:v1
Save and close the file. In vi
, use :wq
.
Deploy the application
To deploy your application, use the kubectl apply
command, specifying the sample manifest file. This command parses the manifest file and creates the defined Kubernetes objects.
kubectl apply -f azure-vote-all-in-one-redis.yaml
The following example output shows the resources successfully created in the AKS cluster:
$ kubectl apply -f azure-vote-all-in-one-redis.yaml
deployment "azure-vote-back" created
service "azure-vote-back" created
deployment "azure-vote-front" created
service "azure-vote-front" created
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.
To monitor progress, use the kubectl get service
command with the --watch
argument.
kubectl get service azure-vote-front --watch
Initially the EXTERNAL-IP for the azure-vote-front service shows as pending.
azure-vote-front LoadBalancer 10.0.34.242 <pending> 80:30676/TCP 5s
When the EXTERNAL-IP address changes from pending to an actual public IP address, use CTRL-C
to stop the kubectl
watch process. The following example output shows a valid public IP address assigned to the service:
azure-vote-front LoadBalancer 10.0.34.242 52.179.23.131 80:30676/TCP 67s
To see the application in action, open a web browser to the external IP address of your service.
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.
Next steps
In this tutorial, you deployed a sample Azure vote 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'll learn how to scale a Kubernetes application and the underlying Kubernetes infrastructure.
Tilbakemeldinger
Send inn og vis tilbakemelding for