Edit

Share via


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.

Storage considerations

The type of storage you use can have large effects on PostgreSQL performance. Later in this guide, you will select the option that is best suited for your goals and performance needs.

Storage type Compatible driver Description
Premium SSD Azure Disks CSI driver or Azure Container Storage Maximum data resiliency. Azure Premium SSD delivers high-performance storage and seamlessly works with Azure Premium zone-redundant storage (ZRS). Premium SSD is provisioned based on specific sizes, which each offer certain IOPS and throughput levels.
Premium SSD v2 Azure Disks CSI driver or Azure Container Storage Best price-performance. Azure Premium SSD v2 offers higher performance than Azure Premium SSDs while also generally being less costly. Unlike Premium SSDs, Premium SSD v2 doesn't have dedicated sizes. You can set a Premium SSD v2 to any supported size you prefer, and make granular adjustments to the performance without downtime. Azure Premium SSD v2 disks have certain limitations that you should be aware of. For a complete list, see Premium SSD v2 limitations.
Local NVMe or temp SSD (Ephemeral Disks) Azure Container Storage only Maximum performance. Ephemeral Disks are local NVMe and temporary SSD storage available on select VM families. They offer the highest possible IOPS, throughput, and sub-millisecond latency for your AKS cluster. You can also take advantage of Ephemeral Disks' high performance using Azure Container Storage, a managed Kubernetes storage solution that dynamically provisions persistent volumes for stateful workloads like PostgreSQL. However, because these disks reside on the local VMs hosting the cluster, data is not persisted to an Azure storage service. As a result, any data stored on these disks will be lost if the cluster is stopped or deallocated. To address this limitation, later sections in this guide will show you how to set up periodic backups of your PostgreSQL data to Azure Blob Storage.

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