Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this tutorial, you find out how to create a Eureka service that's designed to remain operational in the face of failures and high demand. Building a highly available Eureka service helps ensure the service registry that you use for Azure Container Apps is always available to clients regardless of demand.
Achieving high availability status for Eureka includes linking multiple Eureka server instances together so they form a cluster. The cluster provides resources so that if one Eureka server fails, the other services remain available for requests.
In this tutorial, you:
- Create Eureka servers for Spring components.
- Bind two Eureka servers for Spring components together into a cluster.
- Bind a container app to both Eureka servers for highly available service discovery.
Prerequisites
- An Azure account with an active subscription. If you don't already have one, you can create one for free.
- The Azure CLI.
Considerations
When you run managed Java components in Container Apps, be aware of the following details:
| Item | Explanation |
|---|---|
| Scope | Components run in the same environment as the connected container app. |
| Scaling | Components 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 CPU cores is 0.5, and the memory size is 1 GB. |
| Pricing | Component billing falls under consumption-based pricing. Resources consumed by managed components are billed at the active or idle rates, depending on resource usage. 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. |
Set up initial resources
Use the following steps to create some resources that you need for your Eureka service cluster.
Create variables that hold application configuration values.
export LOCATION=eastus export RESOURCE_GROUP=my-services-resource-group export ENVIRONMENT=my-environment export EUREKA_COMPONENT_FIRST=eureka01 export EUREKA_COMPONENT_SECOND=eureka02 export APP_NAME=sample-service-eureka-client export IMAGE="mcr.microsoft.com/javacomponents/samples/sample-service-eureka-client:latest"Use the Azure CLI to sign in to Azure.
az loginCreate a resource group.
az group create --name $RESOURCE_GROUP --location $LOCATIONCreate your Container Apps environment.
az containerapp env create \ --name $ENVIRONMENT \ --resource-group $RESOURCE_GROUP \ --location $LOCATION
Create servers for a cluster
Create two Eureka Server for Spring components.
az containerapp env java-component eureka-server-for-spring create \
--environment $ENVIRONMENT \
--resource-group $RESOURCE_GROUP \
--name $EUREKA_COMPONENT_FIRST
az containerapp env java-component eureka-server-for-spring create \
--environment $ENVIRONMENT \
--resource-group $RESOURCE_GROUP \
--name $EUREKA_COMPONENT_SECOND
Bind components together to form a cluster
For the Eureka servers to work in a high-availability configuration, they need to be linked together as a cluster.
Bind the first Eureka server to the second.
az containerapp env java-component eureka-server-for-spring update \ --environment $ENVIRONMENT \ --resource-group $RESOURCE_GROUP \ --name $EUREKA_COMPONENT_FIRST \ --bind $EUREKA_COMPONENT_SECONDBind the second Eureka server to the first.
az containerapp env java-component eureka-server-for-spring update \ --environment $ENVIRONMENT \ --resource-group $RESOURCE_GROUP \ --name $EUREKA_COMPONENT_SECOND \ --bind $EUREKA_COMPONENT_FIRST
Deploy and bind the application
With the server components linked together, you can create the container app and bind it to the two Eureka components.
Create the container app.
az containerapp create \ --name $APP_NAME \ --resource-group $RESOURCE_GROUP \ --environment $ENVIRONMENT \ --image $IMAGE \ --min-replicas 1 \ --max-replicas 1 \ --ingress external \ --target-port 8080Bind the container app to the first Eureka server component.
az containerapp update \ --name $APP_NAME \ --resource-group $RESOURCE_GROUP \ --bind $EUREKA_COMPONENT_FIRSTBind the container app to the second Eureka server component.
az containerapp update \ --name $APP_NAME \ --resource-group $RESOURCE_GROUP \ --bind $EUREKA_COMPONENT_SECOND
View the dashboard
Important
To view the Eureka Server for Spring dashboard, you need to have the Microsoft.App/managedEnvironments/write, Owner, or Contributor role assigned to your account for the Container Apps environment resource.
- If you already have one of these roles, skip to the Get the dashboard URL section to get the URL and view the dashboard.
- If you want to create a custom role definition and assign it to your account, take the steps in the following section, Create and assign a custom role.
- If you want to assign your account the
OwnerorContributorrole for the resource, make that assignment, and then skip to the Get the dashboard URL section.
Create and assign a custom role
Create the custom role definition. Before you run this command, replace the placeholder in the
AssignableScopesvalue with your subscription ID.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>"] }'Get the resource ID of the Container Apps environment.
export ENVIRONMENT_ID=$(az containerapp env show \ --name $ENVIRONMENT --resource-group $RESOURCE_GROUP \ --query id \ --output tsv)Assign the custom role to your account for the Container Apps environment resource. Before you run this command, replace the placeholder in the
assigneevalue with your user object ID or service principal ID.az role assignment create \ --assignee <USER_OR_SERVICE_PRINCIPAL_ID> \ --role "Java Component Dashboard Access" \ --scope $ENVIRONMENT_ID
Get the dashboard URL
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_FIRST \
--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, you can verify that the Eureka server setup consists of two replicas.
Clean up resources
The resources created in this tutorial affect your Azure bill. If you aren't going to use these services in the long term, run the following command to remove everything created in this tutorial.
az group delete --resource-group $RESOURCE_GROUP