Instructions needed to run a simple asa-e hello world application.
These instructions are a subset of the instructions at https://github.com/Azure-Samples/acme-fitness-store
In order to deploy a Java app to cloud, you need an Azure subscription. If you do not already have an Azure subscription, you can activate your MSDN subscriber benefits or sign up for a free Azure account.
In addition, you will need the following:
| Azure CLI version 2.17.1 or higher
| Git
| jq
utility
|
Install the Azure Spring Apps extension for the Azure CLI using the following command
az extension add --name spring
cp ./setup-env-variables-template.sh ./setup-env-variables.sh
Open ./setup-env-variables.sh
and update the following information:
export SUBSCRIPTION=subscription-id # replace it with your subscription-id
export RESOURCE_GROUP=resource-group-name # existing resource group or one that will be created in next steps
export SPRING_APPS_SERVICE=azure-spring-apps-name # name of the service that will be created in the next steps
export REGION=region-name # choose a region with Enterprise tier support
export APP_NAME=app-name
Then, set the environment:
source ./setup-env-variables.sh
Login to the Azure CLI and choose your active subscription.
az login
az account list -o table
az account set --subscription ${SUBSCRIPTION}
Accept the legal terms and privacy statements for the Enterprise tier.
az provider register --namespace Microsoft.SaaS
az term accept --publisher vmware-inc --product azure-spring-cloud-vmware-tanzu-2 --plan asa-ent-hr-mtr
Create a resource group to contain your Azure Spring Apps service.
Note: This step can be skipped if using an existing resource group
az group create --name ${RESOURCE_GROUP} \
--location ${REGION}
Create an instance of Azure Spring Apps Enterprise.
az spring create --name ${SPRING_APPS_SERVICE} \
--resource-group ${RESOURCE_GROUP} \
--location ${REGION} \
--sku Enterprise \
--enable-application-configuration-service \
--enable-service-registry \
--enable-gateway \
--enable-api-portal \
--build-pool-size S2
Note: The service instance will take around 10-15 minutes to deploy.
Set your default resource group name and cluster name using the following commands:
az configure --defaults \
group=${RESOURCE_GROUP} \
location=${REGION} \
spring=${SPRING_APPS_SERVICE}
az spring app create -n ${APP_NAME}
Perform the below steps to build the app locally
cd hello-world
./mvnw spring-boot:run
Test the application locally, from a different terminal window, e.g.
curl http://localhost:8080/
Also, you can test the application using a browser, e.g. http://localhost:8080/
Finally, terminate the running app, e.g. CTRL+C
in the running application terminal window, and go back to the main directory, e.g.
cd ..
az spring app deploy -n ${APP_NAME} --artifact-path ./jars/demo-0.0.1-SNAPSHOT.jar
Please go to the TEST endpoint to see the greeting message. Notice that TEST endpoint has automatically added authentication.
az spring app update -n ${APP_NAME} --assign-endpoint true
Observe the new URL assigned to the application, e.g. http://APP_URL_HERE
You can also get the URL programmatically, e.g.
az spring app show -n ${APP_NAME} --query "properties.url"
"https://production-hello-world.azuremicroservices.io"
Observe the Actuator endpoint for environment variables. Notice interesting environment variables that are automatically added by the Azure Spring Apps (i.e. Kubernetes under the covers), e.g. /actuator/env/HOSTNAME
curl http://APP_URL_HERE/actuator/env/HOSTNAME
Let's scale out the application by manually increasing the number of instances, e.g.
az spring app scale -n ${APP_NAME} --instance-count 3
Observe the Actuator endpoint and see how the HOSTNAME
changes with each request, e.g.
curl http://APP_URL_HERE/actuator/env/HOSTNAME
Let's clean up the application, Azure Spring Apps instance, and corresponding Resource Group.
az spring app delete -n ${APP_NAME}
az spring delete -n ${SPRING_APPS_SERVICE}
az group delete --name ${RESOURCE_GROUP}