Skip to content

ShibraAmin18/terraform-kubernetes-mysql

 
 

Repository files navigation

MySQL DB

squareops_avatar

SquareOps Technologies Your DevOps Partner for Accelerating cloud journey.


This module allows you to easily deploy a MySQL database on Kubernetes using Helm. It provides flexible configuration options for the MySQL database, including storage class, database volume sizes, and architecture. In addition, it supports enabling backups and restoring from backups, as well as deploying MySQL database exporters to gather metrics for Grafana. This module is designed to be highly configurable and customizable, and can be easily integrated into your existing Terraform infrastructure code.

Supported Versions:

MysqlDB Helm Chart Version K8s supported version
9.2.0 1.23,1.24,1.25,1.26,1.27

Usage Example

module "mysql" {
  source                   = "squareops/mysql/kubernetes"
  cluster_name             = "dev-cluster"
  mysqldb_config = {
    name                             = "mysql"
    values_yaml                      = ""
    environment                      = "prod"
    architecture                     = "replication"
    storage_class_name               = "gp3"
    custom_user_username             = "admin"
    primary_db_volume_size           = "10Gi"
    secondary_db_volume_size         = "10Gi"
    secondary_db_replica_count       = 2
    store_password_to_secret_manager = true
  }
  mysqldb_custom_credentials_enabled = true
  mysqldb_custom_credentials_config = {
    root_user            = "root"
    root_password        = "RJDRIFsYC8ZS1WQuV0ps"
    custom_username      = "admin"
    custom_user_password = "NCPFUKEMd7rrWuvMAa73"
    replication_user     = "replicator"
    replication_password = "nvAHhm1uGQNYWVw6ZyAH"
    exporter_user        = "mysqld_exporter"
    exporter_password    = "ZawhvpueAehRdKFlbjaq"
  }
  mysqldb_backup_enabled   = true
  mysqldb_backup_config = {
    s3_bucket_uri        = ""
    s3_bucket_region     = ""
    cron_for_full_backup = "* * * * *"
  }
  mysqldb_restore_enabled = true
  mysqldb_restore_config = {
    s3_bucket_uri    = ""
    s3_bucket_region = ""
  }
  mysqldb_exporter_enabled = true
}

Refer examples for more details.

IAM Permissions

The required IAM permissions to create resources from this module can be found here

Important Notes

  1. In order to enable the exporter, it is required to deploy Prometheus/Grafana first.
  2. The exporter is a tool that extracts metrics data from an application or system and makes it available to be scraped by Prometheus.
  3. Prometheus is a monitoring system that collects metrics data from various sources, including exporters, and stores it in a time-series database.
  4. Grafana is a data visualization and dashboard tool that works with Prometheus and other data sources to display the collected metrics in a user-friendly way.
  5. To deploy Prometheus/Grafana, please follow the installation instructions for each tool in their respective documentation.
  6. Once Prometheus and Grafana are deployed, the exporter can be configured to scrape metrics data from your application or system and send it to Prometheus.
  7. Finally, you can use Grafana to create custom dashboards and visualize the metrics data collected by Prometheus.
  8. This module is compatible with EKS version 1.23,1.24,1.25,1.26 and 1.27, which is great news for users deploying the module on an EKS cluster running that version. Review the module's documentation, meet specific configuration requirements, and test thoroughly after deployment to ensure everything works as expected.

Requirements

No requirements.

Providers

Name Version
aws n/a
helm n/a
kubernetes n/a
random n/a

Modules

No modules.

Resources

Name Type
aws_iam_role.mysql_backup_role resource
aws_iam_role.mysql_restore_role resource
aws_secretsmanager_secret.mysql_user_password resource
aws_secretsmanager_secret_version.mysql_user_password resource
helm_release.mysqldb resource
helm_release.mysqldb_backup resource
helm_release.mysqldb_restore resource
kubernetes_namespace.mysqldb resource
random_password.mysqldb_custom_user_password resource
random_password.mysqldb_exporter_user_password resource
random_password.mysqldb_replication_user_password resource
random_password.mysqldb_root_password resource
aws_caller_identity.current data source
aws_eks_cluster.kubernetes_cluster data source

Inputs

Name Description Type Default Required
app_version Version of the MySQL application that will be deployed. string "8.0.29-debian-11-r9" no
chart_version Version of the Mysql chart that will be used to deploy MySQL application. string "9.2.0" no
cluster_name Specifies the name of the EKS cluster to deploy the MySQL application on. string "" no
create_namespace Specify whether or not to create the namespace if it does not already exist. Set it to true to create the namespace. string true no
mysqldb_backup_config configuration options for MySQL database backups. It includes properties such as the S3 bucket URI, the S3 bucket region, and the cron expression for full backups. any
{
"cron_for_full_backup": "",
"s3_bucket_region": "",
"s3_bucket_uri": ""
}
no
mysqldb_backup_enabled Specifies whether to enable backups for MySQL database. bool false no
mysqldb_config Specify the configuration settings for MySQL, including the name, environment, storage options, replication settings, and custom YAML values. any
{
"architecture": "",
"custom_user_username": "",
"environment": "",
"name": "",
"primary_db_volume_size": "",
"secondary_db_replica_count": 1,
"secondary_db_volume_size": "",
"storage_class_name": "",
"store_password_to_secret_manager": true,
"values_yaml": ""
}
no
mysqldb_custom_credentials_config Specify the configuration settings for MySQL to pass custom credentials during creation any
{
"custom_user_password": "",
"custom_username": "",
"exporter_password": "",
"exporter_user": "",
"replication_password": "",
"replication_user": "",
"root_password": "",
"root_user": ""
}
no
mysqldb_custom_credentials_enabled Specifies whether to enable custom for MySQL database. bool false no
mysqldb_exporter_enabled Specify whether or not to deploy Mysql exporter to collect Mysql metrics for monitoring in Grafana. bool false no
mysqldb_restore_config Configuration options for restoring dump to the MySQL database. any
{
"s3_bucket_region": "",
"s3_bucket_uri": ""
}
no
mysqldb_restore_enabled Specifies whether to enable restoring dump to the MySQL database. bool false no
namespace Name of the Kubernetes namespace where the MYSQL deployment will be deployed. string "mysqldb" no
recovery_window_aws_secret Number of days that AWS Secrets Manager will wait before deleting a secret. This value can be set to 0 to force immediate deletion, or to a value between 7 and 30 days to allow for recovery. number 0 no

Outputs

Name Description
mysqldb_credential MySQL credentials used for accessing the MySQL database.
mysqldb_endpoints MySQL endpoints in the Kubernetes cluster.

Contribution & Issue Reporting

To report an issue with a project:

  1. Check the repository's issue tracker on GitHub
  2. Search to see if the issue has already been reported
  3. If you can't find an answer to your question in the documentation or issue tracker, you can ask a question by creating a new issue. Be sure to provide enough context and details so others can understand your problem.

License

Apache License, Version 2.0, January 2004 (http://www.apache.org/licenses/).

Support Us

To support a GitHub project by liking it, you can follow these steps:

  1. Visit the repository: Navigate to the GitHub repository.

  2. Click the "Star" button: On the repository page, you'll see a "Star" button in the upper right corner. Clicking on it will star the repository, indicating your support for the project.

  3. Optionally, you can also leave a comment on the repository or open an issue to give feedback or suggest changes.

Starring a repository on GitHub is a simple way to show your support and appreciation for the project. It also helps to increase the visibility of the project and make it more discoverable to others.

Who we are

We believe that the key to success in the digital age is the ability to deliver value quickly and reliably. That’s why we offer a comprehensive range of DevOps & Cloud services designed to help your organization optimize its systems & Processes for speed and agility.

  1. We are an AWS Advanced consulting partner which reflects our deep expertise in AWS Cloud and helping 100+ clients over the last 5 years.
  2. Expertise in Kubernetes and overall container solution helps companies expedite their journey by 10X.
  3. Infrastructure Automation is a key component to the success of our Clients and our Expertise helps deliver the same in the shortest time.
  4. DevSecOps as a service to implement security within the overall DevOps process and helping companies deploy securely and at speed.
  5. Platform engineering which supports scalable,Cost efficient infrastructure that supports rapid development, testing, and deployment.
  6. 24*7 SRE service to help you Monitor the state of your infrastructure and eradicate any issue within the SLA.

We provide support on all of our projects, no matter how small or large they may be.

To find more information about our company, visit squareops.com, follow us on Linkedin, or fill out a job application. If you have any questions or would like assistance with your cloud strategy and implementation, please don't hesitate to contact us.

About

Terraform module for MYSQL for easy provisioning and management in Kubernetes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 100.0%