1
1
---
2
- title : " 6.5. MariaDB "
2
+ title : " 6.5. MySQL "
3
3
weight : 65
4
4
sectionnumber : 6.5
5
5
onlyWhen : azure
@@ -8,7 +8,7 @@ onlyWhen: azure
8
8
## Step {{% param sectionnumber %}}.1: Configure AKS egress IP
9
9
10
10
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.
12
12
13
13
Add the following content below the resource ` azurerm_public_ip.aks_lb_ingress ` in ` aks.tf ` :
14
14
``` terraform
@@ -55,58 +55,57 @@ terraform state show azurerm_public_ip.aks_lb_egress
55
55
```
56
56
57
57
58
- ## Step {{% param sectionnumber %}}.2: Add a MariaDB instance
58
+ ## Step {{% param sectionnumber %}}.2: Add a MySQL instance
59
59
60
60
``` mermaid
61
61
flowchart LR
62
62
classDef red fill:#f96
63
63
subgraph rg: db
64
- mServer(mariadb ):::red --> mDb(database):::red
64
+ mServer(mysql ):::red --> mDb(database):::red
65
65
mFire(firewall):::red --> mDb
66
66
end
67
67
```
68
68
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:
70
70
``` terraform
71
71
resource "azurerm_resource_group" "db" {
72
72
name = "rg-${local.infix}-db"
73
73
location = var.location
74
74
}
75
75
76
- resource "random_password" "mariadb " {
76
+ resource "random_password" "mysql " {
77
77
length = 16
78
78
special = false
79
79
}
80
80
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"
89
88
backup_retention_days = 7
90
89
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
+ }
96
95
}
97
96
98
- resource "azurerm_mariadb_database " "demo_app" {
99
- name = "demo_app"
97
+ resource "azurerm_mysql_flexible_database " "demo_app" {
98
+ name ="demo_app"
100
99
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
102
101
charset = "utf8"
103
102
collation = "utf8_general_ci"
104
103
}
105
104
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 "
108
107
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
110
109
start_ip_address = azurerm_public_ip.aks_lb_egress.ip_address
111
110
end_ip_address = azurerm_public_ip.aks_lb_egress.ip_address
112
111
}
@@ -115,13 +114,13 @@ resource "azurerm_mariadb_firewall_rule" "lab" {
115
114
Create a new file named ` outputs.tf ` and add the following content:
116
115
117
116
``` terraform
118
- output "mariadb_uri " {
117
+ output "mysql_uri " {
119
118
sensitive = true
120
119
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
125
124
)
126
125
}
127
126
```
@@ -131,17 +130,17 @@ Now run
131
130
terraform apply -var-file=config/dev.tfvars
132
131
```
133
132
134
- The MariaDB URI can be displayed by running:
133
+ The MySQL URI can be displayed by running:
135
134
``` bash
136
- terraform output mariadb_uri
135
+ terraform output mysql_uri
137
136
```
138
137
139
138
140
139
### Explanation
141
140
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 .
145
144
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
147
146
the GLIBC function ` snprintf() ` and allows better readable code.
0 commit comments