Deploy a highly available PostgreSQL database on AKS with Azure CLI

In this guide, you deploy a highly available PostgreSQL cluster that spans multiple Azure availability zones on AKS with Azure CLI.

This article walks through the prerequisites for setting up a PostgreSQL cluster on Azure Kubernetes Service (AKS) and provides an overview of the full deployment process and architecture.

Important

Open-source software is mentioned throughout AKS documentation and samples. Software that you deploy is excluded from AKS service-level agreements, limited warranty, and Azure support. As you use open-source technology alongside AKS, consult the support options available from the respective communities and project maintainers to develop a plan.

For example, the Ray GitHub repository describes several platforms that vary in response time, purpose, and support level.

Microsoft takes responsibility for building the open-source packages that we deploy on AKS. That responsibility includes having complete ownership of the build, scan, sign, validate, and hotfix process, along with control over the binaries in container images. For more information, see Vulnerability management for AKS and AKS support coverage.

Prerequisites

Deployment process

In this guide, you learn how to:

  • Use Azure CLI to create a multi-zone AKS cluster.
  • Deploy a highly available PostgreSQL cluster and database using the CNPG operator.
  • Set up monitoring for PostgreSQL using Prometheus and Grafana.
  • Deploy a sample dataset to a PostgreSQL database.
  • Perform PostgreSQL and AKS cluster upgrades.
  • Simulate a cluster interruption and PostgreSQL replica failover.
  • Perform backup and restore of a PostgreSQL database.

Deployment architecture

This diagram illustrates a PostgreSQL cluster setup with one primary replica and two read replicas managed by the CloudNativePG (CNPG) operator. The architecture provides a highly available PostgreSQL running on an AKS cluster that can withstand a zone outage by failing over across replicas.

Backups are stored on Azure Blob Storage, providing another way to restore the database in the event of an issue with streaming replication from the primary replica.

Diagram of CNPG architecture.

Note

For applications that require data separation at the database level, you can add more databases with postInitSQL commands and similar. It is not currently possible with the CNPG operator to add more databases in a declarative way. Learn more about the CNPG operator.

Next steps

Contributors

Microsoft maintains this article. The following contributors originally wrote it:

  • Ken Kilty | Principal TPM
  • Russell de Pina | Principal TPM
  • Adrian Joian | Senior Customer Engineer
  • Jenny Hayes | Senior Content Developer
  • Carol Smith | Senior Content Developer
  • Erin Schaffer | Content Developer 2
  • Adam Sharif | Customer Engineer 2