Tutorial - Prepare an application for Azure Kubernetes Service (AKS)

In this tutorial, part one of seven, you prepare a multi-container application to use in Kubernetes. You use existing development tools like Docker Compose to locally build and test the application. You learn how to:

  • Clone a sample application source from GitHub.
  • Create a container image from the sample application source.
  • Test the multi-container application in a local Docker environment.

Once completed, the following application runs in your local development environment:

Screenshot showing the Azure Store Front App running locally opened in a local web browser.

In later tutorials, you upload the container image to an Azure Container Registry (ACR), and then deploy it into an AKS cluster.

Before you begin

This tutorial assumes a basic understanding of core Docker concepts such as containers, container images, and docker commands. For a primer on container basics, see Get started with Docker.

To complete this tutorial, you need a local Docker development environment running Linux containers. Docker provides packages that configure Docker on a Mac, Windows, or Linux system.

Note

Azure Cloud Shell doesn't include the Docker components required to complete every step in these tutorials. Therefore, we recommend using a full Docker development environment.


Get application code

The sample application used in this tutorial is a basic store front app including the following Kubernetes deployments and services:

Screenshot of Azure Store sample architecture.

  • Store front: Web application for customers to view products and place orders.
  • Product service: Shows product information.
  • Order service: Places orders.
  • Rabbit MQ: Message queue for an order queue.
  1. Use git to clone the sample application to your development environment.

    git clone https://github.com/Azure-Samples/aks-store-demo.git
    
  2. Change into the cloned directory.

    cd aks-store-demo
    

Review Docker Compose file

The sample application you create in this tutorial uses the docker-compose-quickstart YAML file from the repository you cloned.

version: "3.7"
services:
  rabbitmq:
    image: rabbitmq:3.11.17-management-alpine
    container_name: 'rabbitmq'
    restart: always
    environment:
      - "RABBITMQ_DEFAULT_USER=username"
      - "RABBITMQ_DEFAULT_PASS=password"
    ports:
      - 15672:15672
      - 5672:5672
    healthcheck:
      test: ["CMD", "rabbitmqctl", "status"]
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - ./rabbitmq_enabled_plugins:/etc/rabbitmq/enabled_plugins
    networks:
      - backend_services
  orderservice:
    build: src/order-service
    container_name: 'orderservice'
    restart: always
    ports:
      - 3000:3000
    healthcheck:
      test: ["CMD", "wget", "-O", "/dev/null", "-q", "http://orderservice:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 5
    environment:
      - ORDER_QUEUE_HOSTNAME=rabbitmq
      - ORDER_QUEUE_PORT=5672
      - ORDER_QUEUE_USERNAME=username
      - ORDER_QUEUE_PASSWORD=password
      - ORDER_QUEUE_NAME=orders
      - ORDER_QUEUE_RECONNECT_LIMIT=3
    networks:
      - backend_services
    depends_on:
      rabbitmq:
        condition: service_healthy
  productservice:
    build: src/product-service
    container_name: 'productservice'
    restart: always
    ports:
      - 3002:3002
    healthcheck:
      test: ["CMD", "wget", "-O", "/dev/null", "-q", "http://productservice:3002/health"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - backend_services
  storefront:
    build: src/store-front
    container_name: 'storefront'
    restart: always
    ports:
      - 8080:8080
    healthcheck:
      test: ["CMD", "wget", "-O", "/dev/null", "-q", "http://storefront:80/health"]
      interval: 30s
      timeout: 10s
      retries: 5
    environment:
      - VUE_APP_PRODUCT_SERVICE_URL=http://productservice:3002/
      - VUE_APP_ORDER_SERVICE_URL=http://orderservice:3000/
    networks:
      - backend_services
    depends_on:
      - productservice
      - orderservice
networks:
  backend_services:
    driver: bridge

Create container images and run application

You can use Docker Compose to automate building container images and the deployment of multi-container applications.

Docker

  1. Create the container image, download the RabbitMQ image, and start the application using the docker compose command:

    docker compose -f docker-compose-quickstart.yml up -d
    
  2. View the created images using the docker images command.

    docker images
    

    The following condensed example output shows the created images:

    REPOSITORY                       TAG                          IMAGE ID
    aks-store-demo-productservice    latest                       2b66a7e91eca
    aks-store-demo-orderservice      latest                       54ad5de546f9
    aks-store-demo-storefront        latest                       d9e3ac46a225
    rabbitmq                         3.11.17-management-alpine    79a570297657
    ...
    
  3. View the running containers using the docker ps command.

    docker ps
    

    The following condensed example output shows four running containers:

    CONTAINER ID        IMAGE
    21574cb38c1f        aks-store-demo-productservice
    c30a5ed8d86a        aks-store-demo-orderservice
    d10e5244f237        aks-store-demo-storefront
    94e00b50b86a        rabbitmq:3.11.17-management-alpine
    

Test application locally

To see your running application, navigate to http://localhost:8080 in a local web browser. The sample application loads, as shown in the following example:

Screenshot showing the Azure Store Front App opened in a local browser.

On this page, you can view products, add them to your cart, and then place an order.

Clean up resources

Since you validated the application's functionality, you can stop and remove the running containers. Do not delete the container images - you use them in the next tutorial.

  • Stop and remove the container instances and resources using the docker-compose down command.

    docker compose down
    

Next steps

In this tutorial, you created a sample application, created container images for the application, and then tested the application. You learned how to:

  • Clone a sample application source from GitHub.
  • Create a container image from the sample application source.
  • Test the multi-container application in a local Docker environment.

In the next tutorial, you learn how to store container images in an ACR.