Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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
- 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.
Use the Bash environment in Azure Cloud Shell. For more information, see Get started with Azure Cloud Shell.
If you prefer to run CLI reference commands locally, 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.
If you're using a local installation, 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 Authenticate to Azure using Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use and manage 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.
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.
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
Azure Kubernetes Service