Skip to content

Terraform module to deploy Highly Avalable and PostgreSQL Database inside kubernetes cluster with replication and backups enabled

License

Notifications You must be signed in to change notification settings

squareops/terraform-kubernetes-postgresql

Repository files navigation

Postgresql DB

squareops_avatar

SquareOps Technologies Your DevOps Partner for Accelerating cloud journey.


This module allows you to easily deploy a Postgresql database in HA on Kubernetes using Helm. It provides flexible configuration options for the Postgresql database, including storage class. Deploying Postgresql 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:

Postgrsql Helm Chart Version K8s supported version (EKS, AKS & GKE)
14.2.11 1.23,1.24,1.25,1.26,1.27,1.28,1.29

Usage Example

locals {
  name        = "postgresql"
  region      = "us-east-2"
  environment = "prod"
  additional_tags = {
    Owner      = "organization_name"
    Expires    = "Never"
    Department = "Engineering"
  }
  store_password_to_secret_manager = true
  custom_credentials_enabled       = true
  custom_credentials_config = {
    postgres_password = "60rbJs901a6Oa9hzUM5x7s8Q"
    repmgr_password   = "IWHLlEYOt25jL4Io7pancB"
  }
}

module "aws" {
  source                           = "[email protected]:sq-ia/terraform-kubernetes-postgresql.git//modules/resourcces/aws"
  name                             = local.name
  environment                      = local.environment
  cluster_name                     = "cluster-name"
  store_password_to_secret_manager = local.store_password_to_secret_manager
  custom_credentials_enabled       = local.custom_credentials_enabled
  custom_credentials_config        = local.custom_credentials_config
}

module "postgresql" {
  source                      = "[email protected]:sq-ia/terraform-kubernetes-postgresql.git"
  postgresql_exporter_enabled = true
  postgresql_config = {
    name                             = local.name
    environment                      = local.environment
    replicaCount                     = 3
    storage_class                    = "gp2"
    postgresql_values                = ""
    store_password_to_secret_manager = local.store_password_to_secret_manager
    custom_credentials_enabled       = local.custom_credentials_enabled
    custom_credentials_config        = local.custom_credentials_config
    postgres_password                = local.custom_credentials_enabled ? "" : module.aws.postgresql_credential.postgres_password
    repmgr_password                  = local.custom_credentials_enabled ? "" : module.aws.postgresql_credential.repmgr_password
  }
}

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, AKS & GKE which is great news for users deploying the module on an AWS, Azure & GCP cloud. Review the module's documentation, meet specific configuration requirements, and test thoroughly after deployment to ensure everything works as expected.

Requirements

Name Version
aws >= 4.23
helm >= 2.6
kubernetes >= 2.13

Providers

Name Version
helm >= 2.6
kubernetes >= 2.13

Modules

No modules.

Resources

Name Type
helm_release.postgres_exporter resource
helm_release.postgresql_backup resource
helm_release.postgresql_ha resource
helm_release.postgresql_restore resource
kubernetes_namespace.postgresql resource

Inputs

Name Description Type Default Required
chart_version Version of the Postgresql helm chart that will be deployed. string "14.2.11" no
cluster_name Name of eks cluster string "" no
create_namespace Whether or not to deploy postgresql bool true no
custom_credentials_config Specify the configuration settings for Postgresql to pass custom credentials during creation. any
{
"postgres_password": "",
"repmgr_password": ""
}
no
custom_credentials_enabled Specifies whether to enable custom credentials for PostgreSQL database. bool false no
iam_role_arn_backup IAM role ARN for backup (AWS) string "" no
iam_role_arn_restore IAM role ARN for restore (AWS) string "" no
postgres_password PostgresQL password any "" no
postgresql_backup_config configuration options for Pgsql database backups. It includes properties such as the S3 bucket Name, the S3 bucket region, and the cron expression for full backups. any
{
"bucket_name": "",
"cron_for_full_backup": "",
"s3_bucket_region": ""
}
no
postgresql_backup_enabled Specifies whether to enable backups for Pgsql database. bool false no
postgresql_config Configuration options for the postgresql such as number of replica,chart version, storage class and store password at secret manager. map(string)
{
"environment": "",
"name": "",
"postgresql_values": "",
"replicaCount": 3,
"storage_class": "gp2",
"store_password_to_secret_manager": true
}
no
postgresql_enabled Whether or not to deploy postgresql bool true no
postgresql_exporter_enabled Whether or not to deploy postgresql exporter bool false no
postgresql_namespace Name of the Kubernetes namespace where the postgresql will be deployed. string "postgresql" no
postgresql_restore_config Configuration options for restoring dump to the Postgresql database. any
{
"bucket_uri": "",
"file_name": "",
"s3_bucket_region": ""
}
no
postgresql_restore_enabled Specifies whether to enable restoring dump to the Postgresql database. bool false 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
repmgr_password Replication manager password any "" no

Outputs

Name Description
postgresql_credential PostgreSQL credentials used for accessing the database.
postgresql_endpoints PostgreSQL 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 to deploy Highly Avalable and PostgreSQL Database inside kubernetes cluster with replication and backups enabled

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages