Recreate Azure Spring Apps service and apps in the virtual network
Now that you have all the networking resources ready, you need to recreate your Azure Spring Apps service within this virtual network. Before you do so, delete your existing Azure Spring Apps instance first. You can use the following guidance to perform this task:
When you recreate your Spring Apps instance in the virtual network, you will also need to rerun some of the steps from the previous exercise:
- Reconfigure the Application Configuration Service.
- Recreate and redeploy all apps. In the previous exercises you assigned an endpoint to the
api-gateway
andapp-admin
service apps. At this point, in this task, you will skip this step and, instead, you will do so later in this exercise, once you configure the internal DNS name resolution. - Reassign a user assigned managed identity to each of the apps (for
customers-service
,vets-service
andvisits-service
only) and give them access to the Azure Key Vault so they can access the secrets in there. - Recreate the service connections to the database.
Step by step guidance
-
To start, delete your existing Azure Spring Apps instance by running the following command from the Git Bash shell prompt.
az spring delete \ --name $SPRING_APPS_SERVICE \ --resource-group $RESOURCE_GROUP
-
Next, recreate your Azure Spring Apps instance within the designated subnets of the virtual network you created earlier in this exercise.
SPRING_APPS_SERVICE_VNET=sa-vnet-$APPNAME-$UNIQUEID az config set defaults.group=$RESOURCE_GROUP defaults.spring=$SPRING_APPS_SERVICE_VNET az spring create \ --resource-group $RESOURCE_GROUP \ --name $SPRING_APPS_SERVICE_VNET \ --sku Standard \ --vnet $VIRTUAL_NETWORK_NAME \ --service-runtime-subnet service-runtime-subnet \ --app-subnet apps-subnet \ --location $LOCATION
Wait for the provisioning to complete. This might take about 15 minutes.
Notice the differences in this create statement to the first time you created the Spring Apps service. You are now also indicating in which vnet and subnets the deployment should happen.
-
Set up the Application Configuration Service.
az spring config-server git set \ --name $SPRING_APPS_SERVICE_VNET \ --resource-group $RESOURCE_GROUP \ --label main \ --uri $GIT_REPO \ --password $GIT_PASSWORD \ --username $GIT_USERNAME
In case you are using a branch other than
main
in your config repo, you can change the branch name with thelabel
parameter.Wait for the operation to complete. This might take about 10 minutes.
-
Recreate each of the apps in Spring Apps.
az spring app create \ --name $API_GATEWAY \ --runtime-version Java_17 az spring app create \ --name $ADMIN_SERVER \ --runtime-version Java_17 az spring app create \ --name $CUSTOMERS_SERVICE \ --runtime-version Java_17 az spring app create \ --name $VETS_SERVICE \ --runtime-version Java_17 az spring app create \ --name $VISITS_SERVICE \ --runtime-version Java_17
Wait for the provisioning of each app to complete. This might take about 5 minutes for each app.
-
Reassign the user assigned managed identities to the apps. Since you are using user assigned managed identities here, you can reuse them and you don’t need to reapply role assignments to them.
az spring app identity assign \ --resource-group $RESOURCE_GROUP \ --name $CUSTOMERS_SERVICE \ --user-assigned $CUSTOMERS_SERVICE_ID az spring app identity assign \ --resource-group $RESOURCE_GROUP \ --name $VISITS_SERVICE \ --user-assigned $VISITS_SERVICE_ID az spring app identity assign \ --resource-group $RESOURCE_GROUP \ --name $VETS_SERVICE \ --user-assigned $VETS_SERVICE_ID
-
Create for the
customers
,visits
andvets
services the service connection to the database.az spring connection create mysql-flexible \ --resource-group $RESOURCE_GROUP \ --service $SPRING_APPS_SERVICE_VNET \ --app $CUSTOMERS_SERVICE \ --target-resource-group $RESOURCE_GROUP \ --server $MYSQL_SERVER_NAME \ --database $DATABASE_NAME \ --user-identity mysql-identity-id=$ADMIN_IDENTITY_RESOURCE_ID client-id=$CUSTOMERS_SERVICE_CID subs-id=$SUBID az spring connection create mysql-flexible \ --resource-group $RESOURCE_GROUP \ --service $SPRING_APPS_SERVICE_VNET \ --app $VISITS_SERVICE \ --target-resource-group $RESOURCE_GROUP \ --server $MYSQL_SERVER_NAME \ --database $DATABASE_NAME \ --user-identity mysql-identity-id=$ADMIN_IDENTITY_RESOURCE_ID client-id=$VISITS_SERVICE_CID subs-id=$SUBID az spring connection create mysql-flexible \ --resource-group $RESOURCE_GROUP \ --service $SPRING_APPS_SERVICE_VNET \ --app $VETS_SERVICE \ --target-resource-group $RESOURCE_GROUP \ --server $MYSQL_SERVER_NAME \ --database $DATABASE_NAME \ --user-identity mysql-identity-id=$ADMIN_IDENTITY_RESOURCE_ID client-id=$VETS_SERVICE_CID subs-id=$SUBID
-
Redeploy each of the apps.
cd ~/workspaces/java-microservices-asa-aca-lab/src az spring app deploy --name ${API_GATEWAY} \ --config-file-patterns ${API_GATEWAY} \ --artifact-path ${API_GATEWAY_JAR} az spring app deploy --name ${ADMIN_SERVER} \ --config-file-patterns ${ADMIN_SERVER} \ --artifact-path ${ADMIN_SERVER_JAR} az spring app deploy --name ${CUSTOMERS_SERVICE} \ --config-file-patterns ${CUSTOMERS_SERVICE} \ --artifact-path ${CUSTOMERS_SERVICE_JAR} az spring app deploy --name ${VETS_SERVICE} \ --config-file-patterns ${VETS_SERVICE} \ --artifact-path ${VETS_SERVICE_JAR} az spring app deploy --name ${VISITS_SERVICE} \ --config-file-patterns ${VISITS_SERVICE} \ --artifact-path ${VISITS_SERVICE_JAR}