Deploying Microservices with Azure Spring Cloud

Recently Microsoft announced Azure Spring Cloud project. In cooperation with Pivotal, they created a platform that makes a microservices application using Spring Cloud deployment very easy. It has been released today, so let’s try it!

Let’s start with setting up Azure CLI:

Login and setup subscription:

az login     
az account list -o table     
az account set --subscription 

Add Azure Spring Cloud CLI extension:

az extension add --name spring-cloud

Create a resource group, provision an instance of Azure Spring Cloud and set them as defaults:

az group create --location westeurope --name spring-cloud-fun-group
az spring-cloud create -n spring-cloud-fun -g spring-cloud-fun-group
az configure --defaults group=spring-cloud-fun-group
az configure --defaults spring-cloud=spring-cloud-fun

Config server setup

For deployment, we are going to use Piggymetrics sample project from Azure Samples (it’s a fork of the original piggymetrics project).
First, we need to update config-server:

az spring-cloud config-server git set -n spring-cloud-fun --uri https://github.com/Azure-Samples/piggymetrics --label config

That’s it, we have configuration server set up. The command above made config server use config branch of the Piggybank git repository.
The branch contains only config YAML files for all the services (account-service.yml, application.yml, auth-service.yml, gateway.yml).
When setting up properties for services in gonfig server be aware that Azure injects following properties automatically and should not be used manually in config files:


Build the project and deploy

Checkout project and build:

git clone https://github.com/Azure-Samples/piggymetrics
cd PiggyMetrics
mvn clean package -DskipTests

Create microservices:

az spring-cloud app create --name gateway
az spring-cloud app create --name auth-service
az spring-cloud app create --name account-service


az spring-cloud app deploy -n gateway --jar-path ./gateway/target/gateway.jar
az spring-cloud app deploy -n account-service --jar-path ./account-service/target/account-service.jar
az spring-cloud app deploy -n auth-service --jar-path ./auth-service/target/auth-service.jar

Make the gateway public and get its public URL:

az spring-cloud app update -n gateway --is-public true
az spring-cloud app show --name gateway | grep url

In response, you should get URL like https://spring-cloud-fun-gateway.azuremicroservices.io/

If you open it, you should see the Piggy Metrics login page:

Distributed Tracing

Once the application is deployed we can easily enable Distributed Tracing in Azure Portal. It shows communication and dependencies between microservices. In our case it looks like this:


That’s it, deployment of three Spring Cloud microservices takes about
20 minutes, where most of the time is consumed by environment provisioning. Config, discovery, logging, monitoring, alerting and distributed tracing services are provided out of the box so a lot of infrastructure does not have to be set up manually.

Azure Spring Cloud was released officially today. It looks promising and is definitely worth looking at, especially when you want to quick start with Spring Cloud.