Skip to content

Commit 2040674

Browse files
authored
Merge pull request #1 from Aryan-CC/main
added documentation regarding the PostgreSQL usage instructions.
2 parents a55dbd2 + 9aabca0 commit 2040674

33 files changed

+885
-26
lines changed

docs/01_lab_plan/0103.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Now that you identified the viable compute platforms, you need to decide which A
1111

1212
The Azure platform offers several database-as-a-services options, including [Azure SQL Database](https://docs.microsoft.com/azure/azure-sql/database/sql-database-paas-overview?view=azuresql), [Azure Database for MySQL](https://docs.microsoft.com/azure/mysql/), [Azure Cosmos DB](https://docs.microsoft.com/azure/cosmos-db/introduction), and [Azure Database for PostgreSQL](https://docs.microsoft.com/azure/postgresql/). Your choice of the database technology should be based on the following requirements for the Spring Petclinic application:
1313

14-
* The target database service should simplify the migration path from the on-premises MySQL deployment.
14+
* The target database service should simplify the migration path from the on-premises MySQL and PostgreSQL deployment.
1515
* The target database service must support automatic backups.
1616
* The target database service needs to support automatic patching.
1717

18-
Based on these requirements, you decided to use Azure Database for MySQL Flexible Server.
18+
Based on these requirements, you will be having two options, either you can use PostgreSQL or MySQL based on your preference.
1919

docs/01_lab_plan/0104.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ In case you chose to use Azure Spring Apps, you have the option to deploy Azure
2323

2424
In case you chose AKS as the hosting platform, you will need at least one subnet in a virtual network to run the nodes of your AKS cluster. This subnet for now can be small, such as `/26`, which allows for a total of 64 IP addresses (although some of them are pre-allocated for the platform use).
2525

26-
The Azure Database for MySQL deployment will not require any virtual network connectivity for the first phase of the migration of the application. This will also change in one of the subsequent exercises, when you will implement additional security measures to protect the full application stack.
26+
The Azure Database for MySQL or PostgreSQL deployment will not require any virtual network connectivity for the first phase of the migration of the application. This will also change in one of the subsequent exercises, when you will implement additional security measures to protect the full application stack.
2727

2828
## Are there any supporting services you would need for running the application?
2929

docs/02_lab_migrate/0201.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ As a first step you will need to create your Azure Container Apps (ACA) environm
5353
az provider register --namespace Microsoft.OperationalInsights
5454
```
5555

56-
1. Run the following commands to create a resource group that will contain all of your resources (replace the `<azure-region>` placeholder with the name of any Azure region in which you can create an ACA and an Azure Database for MySQL Flexible Server instance, see [this page](https://azure.microsoft.com/explore/global-infrastructure/products-by-region/?products=container-apps) for regional availability details of those services:
56+
1. Run the following commands to create a resource group that will contain all of your resources (replace the `<azure-region>` placeholder with the name of any Azure region in which you can create an ACA and an Azure Database for MySQL or PostgreSQL Flexible Server instance, see [this page](https://azure.microsoft.com/explore/global-infrastructure/products-by-region/?products=container-apps) for regional availability details of those services:
5757

5858
```bash
5959
UNIQUEID=$(openssl rand -hex 3)

docs/02_lab_migrate/0203.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: '3. MySQL database'
2+
title: '3.1 MySQL database'
33
layout: default
4-
nav_order: 3
4+
nav_order: 4
55
parent: 'Lab 2: Migrate to Azure Container Apps'
66
---
77

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# COMMON APPLICATION PROPERTIES
2+
3+
# embedded database init, supports PostgreSQL too trough the 'PostgreSQL' spring profile
4+
spring:
5+
datasource:
6+
url: jdbc:postgresql://<your-postgresql-server-name>.database.azure.com:5432/petclinic?sslmode=require
7+
username: myadmin
8+
password: <your-postgresql-password>
9+
sql:
10+
init:
11+
schema-locations: classpath*:db/postgres/schema.sql
12+
data-locations: classpath*:db/postgres/data.sql
13+
mode: ALWAYS
14+
jms:
15+
queue:
16+
visits-requests: visits-requests
17+
visits-confirmations: visits-confirmations
18+
servicebus:
19+
enabled: false # disable messaging support by default
20+
namespace: ${SERVICEBUS_NAMESPACE}
21+
pricing-tier: premium
22+
passwordless-enabled: true
23+
credential:
24+
managed-identity-enabled: true
25+
client-id: ${CLIENT_ID}
26+
sleuth:
27+
sampler:
28+
probability: 1.0
29+
cloud:
30+
config:
31+
# Allow the microservices to override the remote properties with their own System properties or config file
32+
allow-override: true
33+
# Override configuration with any local property source
34+
override-none: true
35+
jpa:
36+
open-in-view: false
37+
hibernate:
38+
ddl-auto: none
39+
show-sql: true
40+
41+
# Spring Boot 1.5 makes actuator secure by default
42+
management.security.enabled: false
43+
# Enable all Actuators and not only the two available by default /health and /info starting Spring Boot 2.0
44+
management.endpoints.web.exposure.include: "*"
45+
46+
# Temporary hack required by the Spring Boot 2 / Spring Cloud Finchley branch
47+
# Waiting issue https://github.com/spring-projects/spring-boot/issues/13042
48+
spring.cloud.refresh.refreshable: false
49+
50+
# Logging
51+
logging.level.org.springframework: INFO
52+
53+
# enable health probes
54+
management.health.livenessState.enabled: true
55+
management.health.readinessState.enabled: true
56+
management.endpoint.health.probes.enabled: true
57+
58+
# Metrics
59+
management:
60+
endpoint:
61+
metrics:
62+
enabled: true
63+
prometheus:
64+
enabled: true
65+
endpoints:
66+
web:
67+
exposure:
68+
include: '*'
69+
metrics:
70+
export:
71+
prometheus:
72+
enabled: true
73+
eureka:
74+
client:
75+
serviceUrl:
76+
defaultZone: http://discovery-server:8761/eureka/
77+
enableSelfPreservation: true
78+
registryFetchIntervalSeconds: 20
79+
instance:
80+
preferIpAddress: true
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: '3.2 PostgreSQL database [OPTIONAL]'
3+
layout: default
4+
nav_order: 3
5+
parent: 'Lab 2: Migrate to Azure Container Apps'
6+
---
7+
8+
# Create an Azure PostgreSQL Database service
9+
10+
You now have the compute service that will host your applications and the config server that will be used by your migrated application. Before you start deploying individual microservices as Azure Container Apps, you need to first create an Azure Database for PostgreSQL Flexible Server-hosted database for them. To accomplish this, you can use the following guidance:
11+
12+
- [Quickstart: Create an Azure Database for PostgreSQL Flexible Server using Azure CLI](https://learn.microsoft.com/azure/PostgreSQL/flexible-server/quickstart-create-server-cli).
13+
14+
You will also need to update the config for your applications to use the newly provisioned PostgreSQL Server. This will involve updating the application.yml config file in your private git config repo with the values provided in the PostgreSQL Server connection string.
15+
16+
Your PostgreSQL database will also have a firewall enabled. This firewall will by default block all incoming calls. You will need to open this firewall in case you want to connect to it from your microservices running in the ACA environment.
17+
18+
## Step by step guidance
19+
20+
1. Run the following commands to create an instance of PostgreSQL Flexible server. Note that the name of the server must be globally unique, so adjust it accordingly in case the randomly generated name is already in use. Keep in mind that the name can contain only lowercase letters, numbers and hyphens. In addition, replace the `<sqladmin-password>` placeholder with a complex password and record its value.
21+
{: .note }
22+
> Here we use PostgreSQL admin password for apps to connect to sql server, this is for demo/test/learn purpose, not recommand in production environment. Please refer to [Lab 04: Connect to Database securely using identity](https://azure-samples.github.io/java-microservices-aca-lab/docs/04_lab_secrets/04_openlab_secrets_aca.html) for the secured managed identity solution.
23+
24+
```bash
25+
POSTGRES_SERVER_NAME=postgres-$APPNAME-$UNIQUEID
26+
POSTGRES_ADMIN_USERNAME=sqladmin
27+
POSTGRES_ADMIN_PASSWORD="<sqladmin-password>"
28+
DATABASE_NAME=petclinic
29+
30+
az postgres flexible-server create \
31+
--admin-user myadmin \
32+
--admin-password "$POSTGRES_ADMIN_PASSWORD" \
33+
--name "$POSTGRES_SERVER_NAME" \
34+
--resource-group "$RESOURCE_GROUP"
35+
```
36+
37+
{: .note }
38+
> During the creation you will be asked whether access for your IP address should be added and whether access for all IP's should be added. Answer `n` for no on both questions.
39+
40+
{: .note }
41+
> In case this statement fails with the message `ERROR: Unable to prompt for confirmation as no tty available`, add the `--yes` flag to the above statement. This will auto-install any missing resource providers.
42+
43+
{: .note }
44+
> Wait for the provisioning to complete. This might take about 3 minutes.
45+
46+
1. Once the Azure Database for PostgreSQL Flexible Server instance gets created, it will output details about its settings. In the output, you will find the server connection string. Record its value since you will need it later in this exercise.
47+
48+
1. Run the following commands to create a database in the Azure Database for PostgreSQL Flexible Server instance.
49+
50+
```bash
51+
az postgres flexible-server db create \
52+
--server-name $POSTGRES_SERVER_NAME \
53+
--resource-group $RESOURCE_GROUP \
54+
-d $DATABASE_NAME
55+
```
56+
57+
1. You will also need to allow connections to the server from your ACA environment. For now, to accomplish this, you will create a server firewall rule to allow inbound traffic from all Azure Services.
58+
59+
Check the status of your sql server
60+
![SQL Server Networking](../../images/sql-server-manage-firewall.png)
61+
62+
Checking `Allow Azure services and resources to access this server` adds an IP based firewall rule with start and end IP address of `0.0.0.0`, See [Connections from inside Azure](https://learn.microsoft.com/en-us/azure/azure-sql/database/firewall-configure?view=azuresql#connections-from-inside-azure).
63+
64+
This way your apps running in Azure Container Apps will be able to reach the PostgreSQL database. In one of the upcoming exercises, you will restrict this connectivity to limit it exclusively to the apps hosted by your ACA.
65+
66+
```bash
67+
az postgres flexible-server firewall-rule create \
68+
--rule-name allAzureIPs \
69+
--name $POSTGRES_SERVER_NAME \
70+
--resource-group $RESOURCE_GROUP \
71+
--start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
72+
```
73+
74+
Check the sql server firewall rules with command
75+
```bash
76+
az postgres flexible-server firewall-rule list \
77+
--name $POSTGRES_SERVER_NAME \
78+
--resource-group $RESOURCE_GROUP \
79+
```
80+
81+
1. From the Git Bash window, in the config repository you cloned locally, use your favorite text editor to open the _application.yml_ file. Replace the full contents of the _application.yml_ file with the contents of [this application.yml](0203_postgres_application.yaml) file. The updated _application.yml_ file includes the following changes:
82+
83+
* It removes the default `0` value for the `server.port` on line 5.
84+
* It changes the default `spring.sql.init` values to use `PostgreSQL` configuration on lines 15 to 19.
85+
* It adds a `spring.datasource` property for your PostgreSQL database on lines 10 to 14.
86+
* It adds extra `eureka` config on lines 61 to 66.
87+
* It removes the `chaos-monkey` and `PostgreSQL` profiles.
88+
89+
1. In the part you pasted, update the values of the target datasource endpoint on line 6, the corresponding admin user account on line 7, and its password on line 8 to match your configuration. Set these values by using the information in the Azure Database for PostgreSQL Flexible Server connection string you recorded earlier in this task.
90+
91+
1. Save the changes and push the updates you made to the _application.yml_ file to your private GitHub repo by running the following commands from the Git Bash prompt:
92+
93+
```bash
94+
git add .
95+
git commit -m 'azure postgres info'
96+
git push
97+
```
98+
99+
{: .note }
100+
> At this point, the admin account user name and password are stored in clear text in the application.yml config file. In one of upcoming exercises, you will remediate this potential vulnerability by removing clear text credentials from your configuration.
101+

docs/02_lab_migrate/0204.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: '4. Java Components'
33
layout: default
4-
nav_order: 4
4+
nav_order: 5
55
parent: 'Lab 2: Migrate to Azure Container Apps'
66
---
77

docs/02_lab_migrate/0205.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: '5. Deploy to ACA'
33
layout: default
4-
nav_order: 5
4+
nav_order: 6
55
parent: 'Lab 2: Migrate to Azure Container Apps'
66
---
77

@@ -66,7 +66,7 @@ Make sure the api-gateway and admin-server microservices have public IP addresse
6666
--runtime java
6767
```
6868

69-
1. Wait for the provisioning to finish, now you can create the other microservices, `customers`, `vets` and `visits`. These will be internal microservices, exposed by the `api-gateway`. Since these microservices connect to the MySQL database, you will also assign them the user assigned managed identity.
69+
1. Wait for the provisioning to finish, now you can create the other microservices, `customers`, `vets` and `visits`. These will be internal microservices, exposed by the `api-gateway`. Since these microservices connect to the MySQL or PostgreSQL database, you will also assign them the user assigned managed identity.
7070

7171
```bash
7272
APP_NAME=customers-service

docs/02_lab_migrate/0206.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: '6. Test'
33
layout: default
4-
nav_order: 6
4+
nav_order: 7
55
parent: 'Lab 2: Migrate to Azure Container Apps'
66
---
77

@@ -48,15 +48,23 @@ You will need to look for the `properties.configuration.ingress.fqdn` property.
4848

4949
You now have the Spring Petclinic application running properly on Azure Container Apps.
5050

51-
1. In case you are not seeing any data in your application, you can troubleshoot this issue by interactively connecting to your MySQL Flexible Server and querying your databases and tables.
51+
1. In case you are not seeing any data in your application, you can troubleshoot this issue by interactively connecting to your MySQL or PostgreSQL Flexible Server and querying your databases and tables.
5252

5353
```bash
54-
az mysql flexible-server connect -n $MYSQL_SERVER_NAME -u myadmin -p $MYSQL_ADMIN_PASSWORD --interactive
54+
az mysql flexible-server connect -n $MySQL_SERVER_NAME -u myadmin -p $MySQL_ADMIN_PASSWORD --interactive
5555
show databases;
5656
use petclinic;
5757
show tables;
5858
select * from owners;
5959
```
6060
61+
```bash
62+
az postgres flexible-server connect -n $POSTGRES_SERVER_NAME -u myadmin -p $POSTGRES_ADMIN_PASSWORD --interactive
63+
show databases;
64+
use petclinic;
65+
show tables;
66+
select * from owners;
67+
68+
6169
{: .note }
62-
> For the MySQL Flexible Server connection to work, you will need to have your local IP address added to the MySQL Flexible Server firewall.
70+
> For the MySQL or PostgreSQL Flexible Server connection to work, you will need to have your local IP address added to the MySQL or PostgreSQL Flexible Server firewall.

docs/02_lab_migrate/0207.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: '7. Review'
33
layout: default
4-
nav_order: 7
4+
nav_order: 8
55
parent: 'Lab 2: Migrate to Azure Container Apps'
66
---
77

@@ -11,7 +11,7 @@ In this lab, you migrated your existing Spring Petclinic microservices applicati
1111

1212
- Create an Azure Container Apps environment
1313
- Set up a configuration repository
14-
- Created an Azure MySQL Database service
14+
- Created an Azure MySQL or PostgreSQL Database service
1515
- Created the config and discovery server as java components on ACA
1616
- Deployed the microservices of the Spring Petclinic app as Azure container apps
1717
- Tested the application through the publicly available endpoint

0 commit comments

Comments
 (0)