Skip to content

Create a Microservices Application

This guide explains how to create microservices applications in AMD Accelerator Cloud (AAC). Read Create a Docker application first.

How Plexus manages microservices

Microservices use several containers. Plexus runs them on Kubernetes in the same pod, so all containers share a namespace and can communicate over localhost. Plexus also exposes the configured service ports publicly. See Create application below.

Public endpoint dependence

Often a service (e.g. a front end) must use the public endpoint of another service in the same application. Endpoints are allocated dynamically. Plexus lets you read the service public endpoints from inside the container via the file path in the $PLEXUS_WORKLOAD_ENDPOINTS environment variable. This variable is available in containers once interactive endpoints are open; a message also appears in the system logs.

PLEXUS_WORKLOAD_ENDPOINTS variable

Endpoint variables

$PLEXUS_WORKLOAD_ENDPOINTS contains variables for the public host name, port, and URL for each port configured on the application. Variable names are derived from the port names. Example:

Port named backend have the following variables:

  • PLEXUS_BACKEND_PORT
  • PLEXUS_BACKEND_URL

Port named ui has the following variables:

  • PLEXUS_UI_PORT
  • PLEXUS_UI_URL

The public host is always in PLEXUS_HOST.

Endpoint variables

Create application

After reading Create a Docker application, you can configure the application so services in the same workload communicate through the public endpoints.

General application as microservice

In general information, set Service to true and add the ports your application needs. In the example below, the application exposes backend and ui; the ui needs the backend endpoint to communicate with it. Click Next, skip Settings and click Next again to reach the containers step.

Ports configuration

Configure several containers

You can configure multiple containers, each with its own run script and resources.

Multiple containers

Container run scripts

Each container has its own scripts: pre-run script (before the main command), run script, and post-run script (post-run does not apply to service applications, only batch).

Containers that depend on another service's public endpoint must wait for it using the $PLEXUS_WORKLOAD_ENDPOINTS variable, typically in the pre-run script.

In this example, the ui container waits for the backend's public endpoint to be available before starting.

cd /workdir
while true
do

source $PLEXUS_WORKLOAD_ENDPOINTS > /dev/null 2>&1
if [[ $? -gt 0 ]]; then
    echo "Environment variables not ready"
elif [ -z "${PLEXUS_BACKEND_PORT}" ]; then
  echo "Environment variable PLEXUS_BACKEND_PORT is unset or empty."
else
  break
fi
sleep 15
done
echo "Environment variables READY"
export CODEGEN_BACKEND_SERVICE_PORT=$PLEXUS_BACKEND_PORT
export EXTERNAL_HOST_IP=$PLEXUS_HOST

export BASIC_URL=http://${EXTERNAL_HOST_IP}:${CODEGEN_BACKEND_SERVICE_PORT}/v1/codegen
export BACKEND_SERVICE_ENDPOINT=$BASIC_URL

Endpoint wait in run script

Review and create

After adding all containers, click Next. Review the application details and click Save. You can edit your applications later.