Skip to content

Commit b5a8711

Browse files
Merge pull request #17 from amanmallsops/feature/resource-limit-request
feature adding resource limit and request on slow log
2 parents c5a8ef2 + 1309be9 commit b5a8711

File tree

6 files changed

+131
-22
lines changed

6 files changed

+131
-22
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ module "mysql" {
116116
## IAM Permissions
117117
The required IAM permissions to create resources from this module can be found [here](https://github.com/squareops/terraform-kubernetes-mysql/blob/main/IAM.md)
118118

119+
## MySQL Backup and Restore
120+
This module provides functionality to automate the backup and restore process for MySQL databases using AWS S3 buckets. It allows users to easily schedule backups, restore databases from backups stored in S3, and manage access permissions using AWS IAM roles.
121+
Features
122+
### Backup
123+
- Users can schedule full backups.
124+
- upports specifying individual database names for backup or backing up all databases except system databases.
125+
- Backups are stored in specified S3 buckets.
126+
### Restore
127+
- Users can restore MySQL databases from backups stored in S3 buckets.
128+
- Supports specifying the backup file to restore from and the target S3 bucket region.
129+
### IAM Role for Permissions
130+
- Users need to provide an IAM role for the module to access the specified S3 bucket and perform backup and restore operations.
131+
## Module Inputs
132+
### Backup Configuration
133+
- command using to do backup:
134+
```
135+
mysqldump -h$HOST -u$USER -p$PASSWORD --databases db_name > full-backup.sql
136+
```
137+
- mysql_database_name: The name of the MySQL database to backup. Leave blank to backup all databases except system databases.
138+
- bucket_uri: The URI of the S3 bucket where backups will be stored.
139+
- s3_bucket_region: The region of the S3 bucket.
140+
- cron_for_full_backup: The cron expression for scheduling full backups.
141+
### Restore Configuration
142+
- mysqldb_restore_config: Configuration for restoring databases.bucket_uri: The URI of the S3 bucket containing the backup file.
143+
- file_name: The name of the backup file to restore.
144+
- s3_bucket_region: The region of the S3 bucket containing the backup file.
119145
## Important Notes
120146
1. In order to enable the exporter, it is required to deploy Prometheus/Grafana first.
121147
2. The exporter is a tool that extracts metrics data from an application or system and makes it available to be scraped by Prometheus.

examples/complete/aws/helm/values.yaml

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ primary:
88
operator: In
99
values:
1010
- "true"
11+
resources:
12+
limits:
13+
cpu: 350m
14+
memory: 1Gi
15+
requests:
16+
cpu: 200m
17+
memory: 700Mi
18+
19+
sidecars:
20+
- name: slow-log
21+
image: busybox:1.28
22+
args: [/bin/sh, -c, 'tail -n+1 -F /bitnami/mysql/slow-log.log']
23+
volumeMounts:
24+
- name: data
25+
mountPath: /bitnami/mysql
26+
resources:
27+
limits:
28+
cpu: 100m
29+
memory: 256Mi
30+
requests:
31+
cpu: 50m
32+
memory: 128Mi
1133

1234
secondary:
1335
affinity:
@@ -20,29 +42,62 @@ secondary:
2042
values:
2143
- "true"
2244

45+
resources:
46+
limits:
47+
cpu: 350m
48+
memory: 1Gi
49+
requests:
50+
cpu: 200m
51+
memory: 700Mi
52+
53+
sidecars:
54+
- name: slow-log
55+
image: busybox:1.28
56+
args: [/bin/sh, -c, 'tail -n+1 -F /bitnami/mysql/slow-log.log']
57+
volumeMounts:
58+
- name: data
59+
mountPath: /bitnami/mysql
60+
resources:
61+
limits:
62+
cpu: 100m
63+
memory: 256Mi
64+
requests:
65+
cpu: 50m
66+
memory: 128Mi
67+
68+
metrics:
69+
resources:
70+
limits:
71+
cpu: 200m
72+
memory: 500Mi
73+
requests:
74+
cpu: 10m
75+
memory: 50Mi
76+
77+
2378
affinity:
24-
nodeAffinity:
25-
requiredDuringSchedulingIgnoredDuringExecution:
26-
nodeSelectorTerms:
27-
- matchExpressions:
28-
- key: "Infra-Services"
29-
operator: In
30-
values:
31-
- "true"
79+
nodeAffinity:
80+
requiredDuringSchedulingIgnoredDuringExecution:
81+
nodeSelectorTerms:
82+
- matchExpressions:
83+
- key: "Infra-Services"
84+
operator: In
85+
values:
86+
- "true"
3287
backupjob:
3388
resources:
3489
requests:
35-
memory: 100Mi
36-
cpu: 50m
37-
limits:
38-
memory: 200Mi
90+
memory: 250Mi
3991
cpu: 100m
92+
limits:
93+
memory: 500Mi
94+
cpu: 200m
4095

4196
restorejob:
4297
resources:
4398
requests:
44-
memory: 100Mi
45-
cpu: 50m
46-
limits:
47-
memory: 200Mi
99+
memory: 250Mi
48100
cpu: 100m
101+
limits:
102+
memory: 500Mi
103+
cpu: 200m

helm/values/mysqldb/values.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,17 @@ primary:
467467
volumeMounts:
468468
- name: data
469469
mountPath: /bitnami/mysql
470+
resources:
471+
## Example:
472+
## limits:
473+
## cpu: 100m
474+
## memory: 256Mi
475+
limits: {}
476+
## Examples:
477+
## requests:
478+
## cpu: 100m
479+
## memory: 256Mi
480+
requests: {}
470481

471482

472483
## MySQL Primary Service parameters
@@ -843,6 +854,17 @@ secondary:
843854
volumeMounts:
844855
- name: data
845856
mountPath: /bitnami/mysql
857+
resources:
858+
## Example:
859+
## limits:
860+
## cpu: 100m
861+
## memory: 256Mi
862+
limits: {}
863+
## Examples:
864+
## requests:
865+
## cpu: 100m
866+
## memory: 256Mi
867+
requests: {}
846868
## MySQL Secondary Service parameters
847869
##
848870
service:

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ resource "helm_release" "mysqldb_backup" {
5454
azure_storage_account_key = var.bucket_provider_type == "azure" ? var.azure_storage_account_key : ""
5555
azure_container_name = var.bucket_provider_type == "azure" ? var.azure_container_name : ""
5656
annotations = var.bucket_provider_type == "s3" ? "eks.amazonaws.com/role-arn: ${var.iam_role_arn_backup}" : "iam.gke.io/gcp-service-account: ${var.service_account_backup}"
57-
})
57+
}),
58+
var.mysqldb_config.values_yaml
5859
]
5960
}
6061

@@ -78,6 +79,7 @@ resource "helm_release" "mysqldb_restore" {
7879
azure_storage_account_key = var.bucket_provider_type == "azure" ? var.azure_storage_account_key : ""
7980
azure_container_name = var.bucket_provider_type == "azure" ? var.azure_container_name : ""
8081
annotations = var.bucket_provider_type == "s3" ? "eks.amazonaws.com/role-arn: ${var.iam_role_arn_restore}" : "iam.gke.io/gcp-service-account: ${var.service_account_restore}"
81-
})
82+
}),
83+
var.mysqldb_config.values_yaml
8284
]
8385
}

modules/backup/templates/cronjob.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ spec:
1313
spec:
1414
template:
1515
spec:
16-
affinity: {{ .Values.affinity | toYaml | nindent 10 }}
16+
affinity:
17+
{{- toYaml .Values.affinity | nindent 12 }}
1718
restartPolicy: OnFailure
1819
imagePullSecrets:
1920
- name: regcred
@@ -43,4 +44,5 @@ spec:
4344
value: "s3"
4445
- name: AWS_DEFAULT_REGION
4546
value: {{ .Values.backup.aws_default_region }}
46-
resources: {{ .Values.backupjob.resources | toYaml | nindent 12 }}
47+
resources:
48+
{{- toYaml .Values.backupjob.resources | nindent 14 }}

modules/restore/templates/job.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ metadata:
55
spec:
66
template:
77
spec:
8-
affinity: {{ .Values.affinity | toYaml | nindent 6 }}
8+
affinity:
9+
{{- toYaml .Values.affinity | nindent 8 }}
910
serviceAccountName: sa-mysql-restore
1011
containers:
1112
- name: restore-mysqldb
@@ -32,6 +33,7 @@ spec:
3233
value: {{ .Values.bucket_provider_type}}
3334
- name: AWS_DEFAULT_REGION
3435
value: {{ .Values.restore.aws_default_region}}
35-
resources: {{ .Values.restorejob.resources | toYaml | nindent 12 }}
36+
resources:
37+
{{- toYaml .Values.restorejob.resources | nindent 14 }}
3638
restartPolicy: Never
3739
backoffLimit: 4

0 commit comments

Comments
 (0)