Tutorial: Update an application in AKS enabled by Azure Arc
Applies to: AKS on Azure Stack HCI 22H2, AKS on Windows Server
After you deploy an application in Kubernetes using AKS enabled by Arc, you can update it by specifying a new container image or image version. You should stage an update so that only a portion of the deployment is updated at the same time. This staged update enables the application to keep running during the update. It also provides a rollback mechanism if a deployment failure occurs.
This tutorial, part six of seven, describes how to update the sample Azure Vote app. You will learn how to:
- Update the front-end application code
- Create an updated container image
- Push the container image to Azure Container Registry
- Deploy the updated container image
Before you begin
In previous tutorials you learned how to:
- Package an application into a container image and upload the image to Azure Container Registry.
- Create a Kubernetes cluster on Azure Local and deploy the application to the cluster.
- Clone an application repository that includes the application source code and a pre-created Docker Compose file you can use in this tutorial.
Verify that you created a clone of the repo, and changed directories into the cloned directory. If you haven't completed these steps, start with Tutorial 1 - Create container images.
This tutorial requires that you run 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 an application
This section describes how to make a change to the sample application, and then update the version already deployed to your AKS cluster. Make sure that you're in the cloned azure-voting-app-redis directory. The sample application source code can then be found inside the azure-vote directory. Open the config_file.cfg file with an editor, such as Notepad:
notepad azure-vote/azure-vote/config_file.cfg
Change the values for VOTE1VALUE
and VOTE2VALUE
to different values, such as colors. The following example shows the updated values:
# UI Configurations
TITLE = 'Azure Voting App'
VOTE1VALUE = 'Blue'
VOTE2VALUE = 'Purple'
SHOWHOST = 'false'
Save and close the file.
Update the container image
To re-create the front-end image and test the updated application, use docker-compose. The --build
argument is used to re-create the application image:
docker-compose up --build -d
Test the application locally
To verify that the updated container image shows your changes, open a local web browser to http://localhost:8080
.
The updated values provided in config_file.cfg are displayed in your running application.
Tag and push the image
To correctly use the updated image, tag the azure-vote-front image with the login server name of your Azure Container Registry instance. Get the login server name with the az acr list command:
az acr list --resource-group myResourceGroup --query "[].{acrLoginServer:loginServer}" --output table
Use docker tag to tag the image. Replace <acrLoginServer>
with your container registry login server name or public registry hostname, and update the image version to v2, as follows:
docker tag mcr.microsoft.com/azuredocs/azure-vote-front:v1 <acrLoginServer>/azure-vote-front:v2
Now use docker push to upload the image to your registry. Replace <acrLoginServer>
with your Azure Container Registry login server name.
Note
If you experience issues pushing to your container registry, make sure that you are still logged in. Run the az acr login command using the name of your Azure Container Registry that you created in the Create an Azure Container Registry step. For example, az acr login --name <azure container registry name>
.
docker push <acrLoginServer>/azure-vote-front:v2
Deploy the updated application
To provide maximum uptime, you must run multiple instances of the application pod. Verify the number of running front-end instances with the kubectl get pods command:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
azure-vote-back-217588096-5w632 1/1 Running 0 10m
azure-vote-front-233282510-b5pkz 1/1 Running 0 10m
azure-vote-front-233282510-dhrtr 1/1 Running 0 10m
azure-vote-front-233282510-pqbfk 1/1 Running 0 10m
If you don't have multiple front-end pods, scale the azure-vote-front deployment as follows:
kubectl scale --replicas=3 deployment/azure-vote-front
To update the application, use the kubectl set command. Update <acrLoginServer>
with the login server or host name of your container registry, and specify the v2 application version:
kubectl set image deployment azure-vote-front azure-vote-front=<acrLoginServer>/azure-vote-front:v2
To monitor the deployment, use the kubectl get pod command. As the updated application is deployed, your pods are terminated and re-created with the new container image:
kubectl get pods
The following example output shows pods terminating and new instances running as the deployment progresses:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
azure-vote-back-2978095810-gq9g0 1/1 Running 0 5m
azure-vote-front-1297194256-tpjlg 1/1 Running 0 1m
azure-vote-front-1297194256-tptnx 1/1 Running 0 5m
azure-vote-front-1297194256-zktw9 1/1 Terminating 0 1m
Test the updated application
To view the update application, first get the external IP address of the azure-vote-front
service:
kubectl get service azure-vote-front
Next, open a web browser to the IP address of your service:
Next steps
In this tutorial, you updated an application and rolled out this update to your Kubernetes cluster. You learned how to:
- Update the front-end application code
- Create an updated container image
- Push the container image to Azure Container Registry
- Deploy the updated container image
Advance to the next tutorial to learn how to upgrade a cluster to a new version of Kubernetes.