Sample Spring Boot App deployed on Azure AKS
This repo aims to provide a Spring Boot App that uses PostgreSQL to persist data, also stores data at the file system. The app dependencies are managed by maven.
Besides the actual app implementation, this repo presents instructions to provisioning Azure resources used to deploy a Spring Boot Application at Azure AKS.
az login
az group create --name=pay-bank-grp --location=brazilsouth
You shall see an resource group array.
az group list
export AZ_RESOURCE_GROUP=pay-bank-grp
export AZ_DATABASE_NAME=pay-bank-db
export AZ_LOCATION=brazilsouth
export AZ_POSTGRESQL_USERNAME=spring
export AZ_POSTGRESQL_PASSWORD=
export AZ_LOCAL_IP_ADDRESS=<YOUR_IP>
az postgres server create \
--resource-group pay-bank-grp \
--name pay-bank-db \
--location brazilsouth \
--sku-name B_Gen5_1 \
--storage-size 5120 \
--admin-user spring \
--admin-password $AZ_POSTGRESQL_PASSWORD
az postgres server firewall-rule create \
--resource-group pay-bank-grp \
--name pay-bank-db-database-allow-local-ip \
--server pay-bank-db \
--start-ip-address <YOUR_IP> \
--end-ip-address <YOUR_IP>
At that step you are able to connect at your Azure Database for PostgreSQL at jdbc
az postgres db create \
--resource-group pay-bank-grp \
--name banco \
--server-name pay-bank-db
docker build -t pay-bank-app:latest ./ -f Dockerfile
az acr create --resource-group pay-bank-grp --location brazilsouth --name paybankregistry --sku Basic
az acr login --name paybankregistry
At that step your app image was uploaded to your Azure Container Registry.
docker tag pay-bank-app:latest paybankregistry.azurecr.io/pay-bank-app:latest
docker push paybankregistry.azurecr.io/pay-bank-app:latest
az aks create -g pay-bank-grp -n pay-bank-cluster --kubernetes-version 1.17.11 --node-count 2 --node-vm-size Standard_DS2_v2 --nodepool-name bankpool --attach-acr paybankregistry --dns-name-prefix=pay-bank-app-kubernetes --generate-ssh-keys
The following example gets the node resource group for the AKS cluster name pay-bank-cluster in the resource group name pay-bank-grp:
az aks show --resource-group pay-bank-grp --name pay-bank-cluster --query nodeResourceGroup -o tsv
Now create a disk using the az disk create command. Specify the node resource group name obtained in the previous command:
az disk create \
--resource-group MC_SlcGroup_SlcCluster_brazilsouth \
--name myAKSDisk \
--size-gb 20 \
--query id --output tsv
The disk resource ID is displayed once the command has successfully completed, as shown in the following example output. This disk ID is used to mount the disk. Replace that information at the end of file Kubernetes File
/subscriptions/<subscriptionID>/resourceGroups/MC_myAKSCluster_myAKSCluster_eastus/providers/Microsoft.Compute/disks/myAKSDisk
az aks install-cli
az aks get-credentials --resource-group=pay-bank-grp --name=pay-bank-cluster
kubectl create secret generic postgres-pass --from-literal=password=<AZ_POSTGRESQL_PASSWORD>
kubectl apply -f payment-deployment.yml
If you get an error, should be because of the database firewall. Make sure to enable connection from you AKS cluster sing the command below with your AKS ip address.
kubectl get pods
az postgres server firewall-rule create \
--resource-group pay-bank-grp \
--name pay-bank-db-database-kubernetes \
--server pay-bank-db \
--start-ip-address 191.235.113.0 \
--end-ip-address 191.235.113.255
kubectl get services
curl -X POST \
http://<EXTERNAL_IP>/api/v1/arquivosCnab \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"nome": "file.txt"
}'
curl http://<EXTERNAL_IP>/api/v1/localFiles
In the preceding steps, you created Azure resources in a resource group. If you don’t expect to need these resources in the future, delete the resource group from portal, or by running the following command in the Cloud Shell:
az group delete --resource-group pay-bank-grp --subscription <SUBSCRIPTION> --yes
You can use azure-pipeline.yml to enable your repo CI/CD.