Skip to content

Java Spring Boot microservices using Azure serverless technology

License

Notifications You must be signed in to change notification settings

epomatti/azure-serverless-autoscaling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Serverless Auto Scaling

Container Apps and SQL Server Serverless operating with auto-scale.

Setup the Infrastructure

To create the infrastructure simply enter the infra directory and apply:

cd infra

terraform init
terraform apply -auto-approve

The setup has default variables that you can override with an .auto.tfvars file:

# Resources
location = "eastus2"

# SQL Server
sqlserver_version                     = "12.0"
sqlserver_max_size_gb                 = 10
sqlserver_sku_name                    = "GP_S_Gen5_4"
sqlserver_auto_pause_delay_in_minutes = 60
sqlserver_min_capacity                = 0.5
sqlserver_zone_redundant              = false

# Apps
app_cpu                            = 1
app_memory                         = "2.0Gi"
app_min_replicas                   = 1
app_max_replicas                   = 20
app_auto_scale_concurrent_requests = 50
auto_scale_cpu                     = 50

Simply run a load testing tool to view the application metrics. Example with K6:

k6 run \
    -e HOST_URL="https://<address>" \
    --vus 100 \
    --duration 500s \
    http_post.js
k6 run \
    --vus 100 \
    --duration 500s \
    orders.js

Local Development

Setup for local development:

cd app

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P4ssw0rd#777" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest

mvn spring-boot:run -Dspring-boot.run.profiles=dev

Setting the

export APPLICATIONINSIGHTS_CONNECTION_STRING="<...>"

Update Docker image

cd app

docker build . -t epomatti/azure-sqlserverless-books
docker login --username=epomatti
docker push epomatti/azure-sqlserverless-books

Testing the image locally:

docker run -it --rm \
    -e SQLSERVER_JDBC_URL="jdbc:sqlserver://<<<SERVER>>>.database.windows.net:1433;database=<<<DATABASE>>>;user=<<<USERNAME>>>;password=<<<PASSWORD>>>;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;" \
    -e APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=00000000000000000000000000;IngestionEndpoint=https://eastus2-3.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus2.livediagnostics.monitor.azure.com/" \
    -e HIKARI_CONFIG_LOGGING_LEVEL="INFO" \
    -e HIKARI_LOGGING_LEVEL="INFO" \
    -p 8080:8080 \
    -t epomatti/azure-sqlserverless-books

References