Muokkaa

Jaa


Tutorial: Integrate Admin for Spring with Eureka Server for Spring in Azure Container Apps

This tutorial guides you through the process of integrating a managed Admin for Spring with a Eureka Server for Spring within Azure Container Apps.

This article contains some content similar to the "Connect to a managed Admin for Spring in Azure Container Apps" tutorial, but with Eureka Server for Spring, you can bind Admin for Spring to Eureka Server for Spring, so that it can get application information through Eureka, instead of having to bind individual applications to Admin for Spring.

By following this guide, you set up a Eureka Server for service discovery and then create an Admin for Spring to manage and monitor your Spring applications registered with the Eureka Server. This setup ensures that other applications only need to bind to the Eureka Server, simplifying the management of your microservices.

In this tutorial, you learn to:

  1. Create a Eureka Server for Spring.
  2. Create an Admin for Spring and link it to the Eureka Server.
  3. Bind other applications to the Eureka Server for streamlined service discovery and management.

Prerequisites

Considerations

When running managed Java components in Azure Container Apps, be aware of the following details:

Item Explanation
Scope Components run in the same environment as the connected container app.
Scaling Component can’t scale. The scaling properties minReplicas and maxReplicas are both set to 1.
Resources The container resource allocation for components is fixed. The number of the CPU cores is 0.5, and the memory size is 1 Gi.
Pricing Component billing falls under consumption-based pricing. Resources consumed by managed components are billed at the active/idle rates. You can delete components that are no longer in use to stop billing.
Binding Container apps connect to a component via a binding. The bindings inject configurations into container app environment variables. After a binding is established, the container app can read the configuration values from environment variables and connect to the component.

Setup

Before you begin, create the necessary resources by executing the following commands.

  1. Create variables to support your application configuration. These values are provided for you for the purposes of this lesson.

    export LOCATION=eastus
    export RESOURCE_GROUP=my-services-resource-group
    export ENVIRONMENT=my-environment
    export EUREKA_COMPONENT_NAME=eureka
    export ADMIN_COMPONENT_NAME=admin
    export CLIENT_APP_NAME=sample-service-eureka-client
    export CLIENT_IMAGE="mcr.microsoft.com/javacomponents/samples/sample-admin-for-spring-client:latest"
    
    Variable Description
    LOCATION The Azure region location where you create your container app and Java components.
    RESOURCE_GROUP The Azure resource group name for your demo application.
    ENVIRONMENT The Azure Container Apps environment name for your demo application.
    EUREKA_COMPONENT_NAME The name of the Eureka Server Java component.
    ADMIN_COMPONENT_NAME The name of the Admin for Spring Java component.
    CLIENT_APP_NAME The name of the container app that binds to the Eureka Server.
    CLIENT_IMAGE The container image used in your Eureka Server container app.
  2. Log in to Azure with the Azure CLI.

    az login
    
  3. Create a resource group.

    az group create --name $RESOURCE_GROUP --location $LOCATION
    
  4. Create your container apps environment.

    az containerapp env create \
        --name $ENVIRONMENT \
        --resource-group $RESOURCE_GROUP \
        --location $LOCATION \
        --query "properties.provisioningState"
    

    Using the --query parameter filters the response down to a simple success or failure message.

Optional: Create the Eureka Server for Spring

If you don't have an existing Eureka Server for Spring, follow the command below to create the Eureka Server Java component. For more information, see Create the Eureka Server for Spring.

az containerapp env java-component eureka-server-for-spring create \
    --environment $ENVIRONMENT \
    --resource-group $RESOURCE_GROUP \
    --name $EUREKA_COMPONENT_NAME

Bind the components together

Create the Admin for Spring Java component.

az containerapp env java-component admin-for-spring create \
    --environment $ENVIRONMENT \
    --resource-group $RESOURCE_GROUP \
    --name $ADMIN_COMPONENT_NAME \
    --min-replicas 1 \
    --max-replicas 1 \
    --bind $EUREKA_COMPONENT_NAME

Bind other apps to the Eureka Server

With the Eureka Server set up, you can now bind other applications to it for service discovery. And you can also monitor and manage these applications in the dashboard of Admin for Spring. Use the following steps to create and bind a container app to the Eureka Server:

Create the container app and bind it to the Eureka Server.

az containerapp create \
    --name $CLIENT_APP_NAME \
    --resource-group $RESOURCE_GROUP \
    --environment $ENVIRONMENT \
    --image $CLIENT_IMAGE \
    --min-replicas 1 \
    --max-replicas 1 \
    --ingress external \
    --target-port 8080 \
    --bind $EUREKA_COMPONENT_NAME 

Tip

Since the previous steps bound the Admin for Spring component to the Eureka Server for Spring component, the Admin component enables service discovery and allows you to manage it through the Admin for Spring dashboard at the same time.

View the dashboards

Important

To view the dashboard, you need to have at least the Microsoft.App/managedEnvironments/write role assigned to your account on the managed environment resource. You can either explicitly assign Owner or Contributor role on the resource or follow the steps to create a custom role definition and assign it to your account.

  1. Create the custom role definition.

    az role definition create --role-definition '{
        "Name": "Java Component Dashboard Access",
        "IsCustom": true,
        "Description": "Can access managed Java Component dashboards in managed environments",
        "Actions": [
            "Microsoft.App/managedEnvironments/write"
        ],
        "AssignableScopes": ["/subscriptions/<SUBSCRIPTION_ID>"]
    }'
    

    Make sure to replace the <SUBSCRIPTION_ID> placeholder in the AssignableScopes value with your subscription ID.

  2. Assign the custom role to your account on managed environment resource.

    Get the resource ID of the managed environment.

    export ENVIRONMENT_ID=$(az containerapp env show \
        --name $ENVIRONMENT --resource-group $RESOURCE_GROUP \
        --query id \
        --output tsv)
    
  3. Assign the role to your account.

    Before running this command, replace the <USER_OR_SERVICE_PRINCIPAL_ID> placeholder with your user or service principal ID.

    az role assignment create \
        --assignee <USER_OR_SERVICE_PRINCIPAL_ID> \
        --role "Java Component Dashboard Access" \
        --scope $ENVIRONMENT_ID
    
  4. Get the URL of the Admin for Spring dashboard.

    az containerapp env java-component admin-for-spring show \
        --environment $ENVIRONMENT \
        --resource-group $RESOURCE_GROUP \
        --name $ADMIN_COMPONENT_NAME \
        --query properties.ingress.fqdn \
        --output tsv
    
  5. Get the URL of the Eureka Server for Spring dashboard.

    az containerapp env java-component eureka-server-for-spring show \
        --environment $ENVIRONMENT \
        --resource-group $RESOURCE_GROUP \
        --name $EUREKA_COMPONENT_NAME \
        --query properties.ingress.fqdn \
        --output tsv
    

    This command returns the URL you can use to access the Eureka Server for Spring dashboard. Through the dashboard, your container app is also to you as shown in the following screenshot.

    Screenshot of the Admin for Spring dashboard.

    Screenshot of the Eureka Server for Spring dashboard.

Clean up resources

The resources created in this tutorial have an effect on your Azure bill. If you aren't going to use these services long-term, run the following command to remove everything created in this tutorial.

az group delete --resource-group $RESOURCE_GROUP