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, a sample application is deployed into a Kubernetes cluster. You learn how to:

  • Update a Kubernetes manifest files
  • Run an application in Kubernetes
  • Test the application

In subsequent tutorials, this application is scaled out and updated.

This tutorial assumes a basic understanding of Kubernetes concepts, for detailed information on Kubernetes see the Kubernetes documentation.

Before you begin

In previous tutorials, an application was packaged into a container image, this image was uploaded to Azure Container Registry, and a Kubernetes cluster was created.

To complete this tutorial, you need the pre-created azure-vote-all-in-one-redis.yaml Kubernetes manifest file. This file was downloaded with the application source code in a previous tutorial. Verify that you have cloned the repo, and that you have changed directories into the cloned repo. If you have not done these steps, and would like to follow along, return to Tutorial 1 – Create container images.

This tutorial requires that you are running the Azure CLI version 2.0.44 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 as follows:

az acr list --resource-group myResourceGroup --query "[].{acrLoginServer:loginServer}" --output table

The sample manifest file from the git repo cloned in the first tutorial uses the login server name of microsoft. Open this manifest file with a text editor, such as vi:

vi azure-vote-all-in-one-redis.yaml

Replace microsoft with your ACR login server name. The image name is found on line 47 of the manifest file. The following example shows the default image name:

containers:
- name: azure-vote-front
  image: microsoft/azure-vote-front:v1

Provide your own ACR login server name so that your manifest file looks like the following example:

containers:
- name: azure-vote-front
  image: <acrName>.azurecr.io/azure-vote-front:v1

Save and close the file.

Deploy the application

To deploy your application, use the kubectl apply command. This command parses the manifest file and creates the defined Kubernetes objects. Specify the sample manifest file, as shown in the following example:

kubectl apply -f azure-vote-all-in-one-redis.yaml

The Kubernetes objects are created within the cluster, as shown in the following example:

$ 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

A Kubernetes service is created which exposes the application to the internet. This process can take a few minutes. To monitor progress, use the kubectl get service command with the --watch argument:

kubectl get service azure-vote-front --watch

The EXTERNAL-IP for the azure-vote-front service initially appears as pending, as shown in the following example:

azure-vote-front   10.0.34.242   <pending>     80:30676/TCP   7s

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 shows a public IP address is now assigned:

azure-vote-front   10.0.34.242   52.179.23.131   80:30676/TCP   2m

To see the application in action, open a web browser to the external IP address.

Image of Kubernetes cluster on Azure

If the application did not load, it might be due to an authorization problem with your image registry. To view the status of your containers, use the kubectl get pods command. If the container images cannot be pulled, see allow access to Container Registry with a Kubernetes secret.

Next steps

In this tutorial, the Azure vote application was deployed to a Kubernetes cluster in AKS. You learned how to:

  • Update a Kubernetes manifest files
  • Run an application in Kubernetes
  • Test the application

Advance to the next tutorial to learn how to scale a Kubernetes application and the underlying Kubernetes infrastructure.