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.
- This guide assumes a basic understanding of core Kubernetes concepts and PostgreSQL.
- You need the Owner or User Access Administrator and the Contributor Azure built-in roles on a subscription in your Azure account.
You can use the local Azure CLI.
If you prefer, install the Azure CLI to run CLI reference commands.
Local Azure CLI, see how to install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
Sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
You also need the following resources installed:
- Azure CLI version 2.56 or later.
- Azure Kubernetes Service (AKS) preview extension.
- jq, version 1.5 or later.
- kubectl version 1.21.0 or later.
- Helm version 3.0.0 or later.
- openssl version 3.3.0 or later.
- Visual Studio Code or equivalent.
- Krew version 0.4.4 or later.
- kubectl CloudNativePG (CNPG) Plugin.
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.
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.
Note
The CNPG operator supports only one database per cluster. Plan accordingly for applications that require data separation at the database level.
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