Skip to content

Commit 4b6c4eb

Browse files
committed
replace mariadb with mysql
1 parent ab0aad6 commit 4b6c4eb

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

content/en/docs/06_azure/5-mariadb.md

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "6.5. MariaDB"
2+
title: "6.5. MySQL"
33
weight: 65
44
sectionnumber: 6.5
55
onlyWhen: azure
@@ -8,7 +8,7 @@ onlyWhen: azure
88
## Step {{% param sectionnumber %}}.1: Configure AKS egress IP
99

1010
By default, AKS routes traffic to the internet via a (randomly assigned) Azure public IP. For some scenarios like
11-
our MariaDB instance, we want to whitelist the source IP to restrict access to the services.
11+
our MySQL instance, we want to whitelist the source IP to restrict access to the services.
1212

1313
Add the following content below the resource `azurerm_public_ip.aks_lb_ingress` in `aks.tf`:
1414
```terraform
@@ -55,58 +55,57 @@ terraform state show azurerm_public_ip.aks_lb_egress
5555
```
5656

5757

58-
## Step {{% param sectionnumber %}}.2: Add a MariaDB instance
58+
## Step {{% param sectionnumber %}}.2: Add a MySQL instance
5959

6060
```mermaid
6161
flowchart LR
6262
classDef red fill:#f96
6363
subgraph rg: db
64-
mServer(mariadb):::red --> mDb(database):::red
64+
mServer(mysql):::red --> mDb(database):::red
6565
mFire(firewall):::red --> mDb
6666
end
6767
```
6868

69-
Create a new file named `mariadb.tf` and add the following content:
69+
Create a new file named `mysql.tf` and add the following content:
7070
```terraform
7171
resource "azurerm_resource_group" "db" {
7272
name = "rg-${local.infix}-db"
7373
location = var.location
7474
}
7575
76-
resource "random_password" "mariadb" {
76+
resource "random_password" "mysql" {
7777
length = 16
7878
special = false
7979
}
8080
81-
resource "azurerm_mariadb_server" "demo" {
82-
name = "mdb-${local.infix}"
83-
location = azurerm_resource_group.db.location
84-
resource_group_name = azurerm_resource_group.db.name
85-
86-
sku_name = "B_Gen5_1"
87-
88-
storage_mb = 5120
81+
resource "azurerm_mysql_flexible_server" "demo" {
82+
name = "mdb-${local.infix}"
83+
resource_group_name = azurerm_resource_group.db.name
84+
location = azurerm_resource_group.db.location
85+
administrator_login = "demo"
86+
administrator_password = random_password.mysql.result
87+
sku_name = "B_Standard_B1s"
8988
backup_retention_days = 7
9089
geo_redundant_backup_enabled = false
91-
92-
administrator_login = "demo"
93-
administrator_login_password = random_password.mariadb.result
94-
version = "10.2"
95-
ssl_enforcement_enabled = false
90+
version = "8.0.21"
91+
92+
storage {
93+
size_gb = 20
94+
}
9695
}
9796
98-
resource "azurerm_mariadb_database" "demo_app" {
99-
name = "demo_app"
97+
resource "azurerm_mysql_flexible_database" "demo_app" {
98+
name ="demo_app"
10099
resource_group_name = azurerm_resource_group.db.name
101-
server_name = azurerm_mariadb_server.demo.name
100+
server_name = azurerm_mysql_flexible_server.demo.name
102101
charset = "utf8"
103102
collation = "utf8_general_ci"
104103
}
105104
106-
resource "azurerm_mariadb_firewall_rule" "lab" {
107-
name = "lab-db-rule"
105+
resource "azurerm_mysql_flexible_server_firewall_rule" "aks_egress_ip" {
106+
name = "aks-egress-ip"
108107
resource_group_name = azurerm_resource_group.db.name
109-
server_name = azurerm_mariadb_server.demo.name
108+
server_name = azurerm_mysql_flexible_server.demo.name
110109
start_ip_address = azurerm_public_ip.aks_lb_egress.ip_address
111110
end_ip_address = azurerm_public_ip.aks_lb_egress.ip_address
112111
}
@@ -115,13 +114,13 @@ resource "azurerm_mariadb_firewall_rule" "lab" {
115114
Create a new file named `outputs.tf` and add the following content:
116115

117116
```terraform
118-
output "mariadb_uri" {
117+
output "mysql_uri" {
119118
sensitive = true
120119
value = format("mysql://%s:%s@%s/%s",
121-
azurerm_mariadb_server.demo.administrator_login,
122-
azurerm_mariadb_server.demo.administrator_login_password,
123-
azurerm_mariadb_server.demo.fqdn,
124-
azurerm_mariadb_database.demo_app.name
120+
azurerm_mysql_flexible_server.demo.administrator_login,
121+
azurerm_mysql_flexible_server.demo.administrator_password,
122+
azurerm_mysql_flexible_server.demo.fqdn,
123+
azurerm_mysql_flexible_database.demo_app.name
125124
)
126125
}
127126
```
@@ -131,17 +130,17 @@ Now run
131130
terraform apply -var-file=config/dev.tfvars
132131
```
133132

134-
The MariaDB URI can be displayed by running:
133+
The MySQL URI can be displayed by running:
135134
```bash
136-
terraform output mariadb_uri
135+
terraform output mysql_uri
137136
```
138137

139138

140139
### Explanation
141140

142-
The MariaDB instance is a managed service by Azure and has a public IP. By default, no IPs are allowed to access
143-
the instance. The resource `azurerm_mariadb_firewall_rule.lab` adds a firewall rule to whitelist the egress IP
144-
of the Kubernetes AKS cluster, which allows apps deployed on the cluster to access MariaDB.
141+
The MySQL instance is a managed service by Azure and has a public IP. By default, no IPs are allowed to access
142+
the instance. The resource `azurerm_mysql_flexible_server_firewall_rule.aks_egress_ip` adds a firewall rule to whitelist the egress IP
143+
of the Kubernetes AKS cluster, which allows apps deployed on the cluster to access MySQL.
145144

146-
To configure our demo app, we need to generate a MariaDB URI. The Terraform function `format` has familiar syntax to
145+
To configure our demo app, we need to generate a MySQL URI. The Terraform function `format` has familiar syntax to
147146
the GLIBC function `snprintf()` and allows better readable code.

content/en/docs/06_azure/6-demo-app.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ flowchart LR
3232
end
3333
pAc --> mFire
3434
subgraph rg: db
35-
mServer(mariadb) --> mDb(database)
35+
mServer(mysql) --> mDb(database)
3636
mFire(firewall) --> mDb
3737
end
3838
```
3939

4040
To test the setup end-to-end, we deploy an example application on Kubernetes. The app exposes a web service on port
41-
5000 and writes sample records to the MariaDB.
41+
5000 and writes sample records to the MySQL.
4242

43-
Create a Kubernetes secret containing the MariaDB URI to be exposed as the POD environment variable `MYSQL_URI`:
43+
Create a Kubernetes secret containing the MySQL URI to be exposed as the POD environment variable `MYSQL_URI`:
4444

4545
```bash
4646
kubectl create namespace workload
47-
kubectl create secret generic mariadb-uri --namespace workload --from-literal=mariadb_uri=$(terraform output -raw mariadb_uri)
47+
kubectl create secret generic mysql-uri --namespace workload --from-literal=mysql_uri=$(terraform output -raw mysql_uri)
4848
```
4949

5050
Create a new file named `tests/workload.yaml` and add the following content:
@@ -69,8 +69,8 @@ spec:
6969
- name: MYSQL_URI
7070
valueFrom:
7171
secretKeyRef:
72-
name: mariadb-uri
73-
key: mariadb_uri
72+
name: mysql-uri
73+
key: mysql_uri
7474

7575
---
7676

@@ -126,7 +126,7 @@ kubectl apply -f tests/workload.yaml
126126

127127
The application is now accessible via web browser at https://workload.YOUR_USERNAME.mobi.terraform-lab.cloud
128128

129-
To verify the application is connected to the MariaDB, run the following command to inspec the log files:
129+
To verify the application is connected to the MySQL, run the following command to inspec the log files:
130130
```bash
131131
kubectl logs -n workload example | head
132132
```

content/en/docs/06_azure/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Main components:
2121
* Static IP + DNS A record
2222
* Load balancer (Layer 4) + Kubernetes Ingress Controller (NGINX)
2323
* SSL Cert Manager
24-
* MariaDB
24+
* MySQL
2525

2626

2727
### Diagram

0 commit comments

Comments
 (0)