Skip to content

Commit aa5a800

Browse files
authored
Merge pull request #7 from fossygirl/aj_fixes
WIP doc, md and best practices
2 parents 8691d16 + 9315920 commit aa5a800

File tree

3 files changed

+88
-87
lines changed

3 files changed

+88
-87
lines changed

articles/aks/create-postgresql-ha.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In this article, you create the infrastructure needed to deploy a highly availab
2222

2323
Set the following environment variables for use throughout this guide:
2424

25-
```azurecli-interactive
25+
```bash
2626
export SUFFIX=$(cat /dev/urandom | LC_ALL=C tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
2727
export LOCAL_NAME="cnpg"
2828
export TAGS="owner=user"
@@ -47,15 +47,15 @@ export MY_PUBLIC_CLIENT_IP=$(dig +short myip.opendns.com @resolver3.opendns.com)
4747

4848
The `aks-preview`, `k8s-extension` and `amg` extensions provide more functionality for managing Kubernetes clusters and querying Azure resources. Install these extensions using the following [`az extension add`][az-extension-add] commands:
4949

50-
```azurecli-interactive
50+
```bash
5151
az extension add --upgrade --name aks-preview --yes --allow-preview true
5252
az extension add --upgrade --name k8s-extension --yes --allow-preview false
5353
az extension add --upgrade --name amg --yes --allow-preview false
5454
```
5555

5656
As a prerequisite for utilizing kubectl, it is essential to first install [Krew][install-krew], followed by the installation of the [CNPG plugin][cnpg-plugin]. This will enable the management of the PostgreSQL operator using the subsequent commands.
5757

58-
```azurecli
58+
```bash
5959
(
6060
set -x; cd "$(mktemp -d)" &&
6161
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
@@ -75,7 +75,7 @@ kubectl krew install cnpg
7575

7676
Create a resource group to hold the resources you create in this guide using the [`az group create`][az-group-create] command.
7777

78-
```azurecli-interactive
78+
```bash
7979
az group create \
8080
--name $RESOURCE_GROUP_NAME \
8181
--location $PRIMARY_CLUSTER_REGION \
@@ -90,7 +90,7 @@ In this section, you create a user-assigned managed identity (UAMI) to allow the
9090

9191
1. Create a user-assigned managed identity using the [`az identity create`][az-identity-create] command.
9292

93-
```azurecli-interactive
93+
```bash
9494
AKS_UAMI_WI_IDENTITY=$(az identity create \
9595
--name $AKS_UAMI_CLUSTER_IDENTITY_NAME \
9696
--resource-group $RESOURCE_GROUP_NAME \
@@ -100,7 +100,7 @@ In this section, you create a user-assigned managed identity (UAMI) to allow the
100100

101101
1. Enable AKS workload identity and generate a service account to use later in this guide using the following commands:
102102

103-
```azurecli-interactive
103+
```bash
104104
export AKS_UAMI_WORKLOAD_OBJECTID=$( \
105105
echo "${AKS_UAMI_WI_IDENTITY}" | jq -r '.principalId')
106106
export AKS_UAMI_WORKLOAD_RESOURCEID=$( \
@@ -121,7 +121,7 @@ The CNPG operator automatically generates a service account called *postgres* th
121121

122122
1. Create an object storage account to store PostgreSQL backups in the primary region using the [`az storage account create`][az-storage-account-create] command.
123123

124-
```azurecli-interactive
124+
```bash
125125
az storage account create \
126126
--name $PG_PRIMARY_STORAGE_ACCOUNT_NAME \
127127
--resource-group $RESOURCE_GROUP_NAME \
@@ -134,7 +134,7 @@ The CNPG operator automatically generates a service account called *postgres* th
134134

135135
1. Create the storage container to store the Write Ahead Logs (WAL) and regular PostgreSQL on-demand and scheduled backups using the [`az storage container create`][az-storage-container-create] command.
136136

137-
```azurecli-interactive
137+
```bash
138138
az storage container create \
139139
--name $PG_STORAGE_BACKUP_CONTAINER_NAME \
140140
--account-name $PG_PRIMARY_STORAGE_ACCOUNT_NAME \
@@ -144,7 +144,7 @@ The CNPG operator automatically generates a service account called *postgres* th
144144
> [!NOTE]
145145
> If you encounter the error message: `The request may be blocked by network rules of storage account. Please check network rule set using 'az storage account show -n accountname --query networkRuleSet'. If you want to change the default action to apply when no rule matches, please use 'az storage account update'`. Please verify user permissions for Azure Blob Storage and, if **necessary**, elevate your role to `Storage Blob Data Owner` using the commands provided below.
146146

147-
```azurecli-interactive
147+
```bash
148148
az role assignment list --scope $STORAGE_ACCOUNT_PRIMARY_RESOURCE_ID --output table
149149
150150
export USER_ID=$(az ad signed-in-user show --query id --output tsv)
@@ -168,7 +168,7 @@ To enable backups, the PostgreSQL cluster needs to read and write to an object s
168168

169169
1. Get the primary resource ID for the storage account using the [`az storage account show`][az-storage-account-show] command.
170170

171-
```azurecli-interactive
171+
```bash
172172
export STORAGE_ACCOUNT_PRIMARY_RESOURCE_ID=$(az storage account show \
173173
--name $PG_PRIMARY_STORAGE_ACCOUNT_NAME \
174174
--resource-group $RESOURCE_GROUP_NAME \
@@ -180,7 +180,7 @@ To enable backups, the PostgreSQL cluster needs to read and write to an object s
180180
181181
1. Assign the "Storage Blob Data Contributor" Azure built-in role to the object ID with the storage account resource ID scope for the UAMI associated with the managed identity for each AKS cluster using the [`az role assignment create`][az-role-assignment-create] command.
182182
183-
```azurecli-interactive
183+
```bash
184184
az role assignment create \
185185
--role "Storage Blob Data Contributor" \
186186
--assignee-object-id $AKS_UAMI_WORKLOAD_OBJECTID \
@@ -199,7 +199,7 @@ In this section, you deploy an instance of Azure Managed Grafana, an Azure Monit
199199
200200
1. Create an Azure Managed Grafana instance using the [`az grafana create`][az-grafana-create] command.
201201
202-
```azurecli-interactive
202+
```bash
203203
export GRAFANA_PRIMARY="grafana-${LOCAL_NAME}-${SUFFIX}"
204204

205205
export GRAFANA_RESOURCE_ID=$(az grafana create \
@@ -216,7 +216,7 @@ In this section, you deploy an instance of Azure Managed Grafana, an Azure Monit
216216
217217
1. Create an Azure Monitor workspace using the [`az monitor account create`][az-monitor-account-create] command.
218218
219-
```azurecli-interactive
219+
```bash
220220
export AMW_PRIMARY="amw-${LOCAL_NAME}-${SUFFIX}"
221221

222222
export AMW_RESOURCE_ID=$(az monitor account create \
@@ -232,7 +232,7 @@ In this section, you deploy an instance of Azure Managed Grafana, an Azure Monit
232232
233233
1. Create an Azure Monitor Log Analytics workspace using the [`az monitor log-analytics workspace create`][az-monitor-log-analytics-workspace-create] command.
234234
235-
```azurecli-interactive
235+
```bash
236236
export ALA_PRIMARY="ala-${LOCAL_NAME}-${SUFFIX}"
237237

238238
export ALA_RESOURCE_ID=$(az monitor log-analytics workspace create \
@@ -253,7 +253,7 @@ You also add a user node pool to the AKS cluster to host the PostgreSQL cluster.
253253
254254
1. Create an AKS cluster using the [`az aks create`][az-aks-create] command.
255255
256-
```azurecli-interactive
256+
```bash
257257
export SYSTEM_NODE_POOL_VMSKU="standard_d2s_v3"
258258
export USER_NODE_POOL_NAME="postgres"
259259
export USER_NODE_POOL_VMSKU="standard_d4s_v3"
@@ -289,7 +289,7 @@ You also add a user node pool to the AKS cluster to host the PostgreSQL cluster.
289289
290290
2. Add a user node pool to the AKS cluster using the [`az aks nodepool add`][az-aks-node-pool-add] command.
291291
292-
```azurecli-interactive
292+
```bash
293293
az aks nodepool add \
294294
--resource-group $RESOURCE_GROUP_NAME \
295295
--cluster-name $AKS_PRIMARY_CLUSTER_NAME \
@@ -312,7 +312,7 @@ In this section, you get the AKS cluster credentials, which serve as the keys th
312312
313313
1. Get the AKS cluster credentials using the [`az aks get-credentials`][az-aks-get-credentials] command.
314314
315-
```azurecli-interactive
315+
```bash
316316
az aks get-credentials \
317317
--resource-group $RESOURCE_GROUP_NAME \
318318
--name $AKS_PRIMARY_CLUSTER_NAME \
@@ -321,7 +321,7 @@ In this section, you get the AKS cluster credentials, which serve as the keys th
321321
322322
2. Create the namespace for the CNPG controller manager services, the PostgreSQL cluster, and its related services by using the [`kubectl create namespace`][kubectl-create-namespace] command.
323323
324-
```azurecli-interactive
324+
```bash
325325
kubectl create namespace $PG_NAMESPACE --context $AKS_PRIMARY_CLUSTER_NAME
326326
kubectl create namespace $PG_SYSTEM_NAMESPACE --context $AKS_PRIMARY_CLUSTER_NAME
327327
```
@@ -332,7 +332,7 @@ The Azure Monitor workspace for Managed Prometheus and Azure Managed Grafana are
332332
333333
1. Enable Container insights monitoring on the AKS cluster using the [`az aks enable-addons`][az-aks-enable-addons] command.
334334
335-
```azurecli-interactive
335+
```bash
336336
az aks enable-addons \
337337
--addon monitoring \
338338
--name $AKS_PRIMARY_CLUSTER_NAME \
@@ -343,7 +343,7 @@ The Azure Monitor workspace for Managed Prometheus and Azure Managed Grafana are
343343
344344
2. Validate that Managed Prometheus is scraping metrics and Container insights is ingesting logs from the AKS cluster by inspecting the DaemonSet using the [`kubectl get`][kubectl-get] command and the [`az aks show`][az-aks-show] command.
345345
346-
```azurecli-interactive
346+
```bash
347347
kubectl get ds ama-metrics-node \
348348
--context $AKS_PRIMARY_CLUSTER_NAME \
349349
--namespace=kube-system
@@ -385,7 +385,7 @@ To validate deployment of the PostgreSQL cluster and use client PostgreSQL tooli
385385
386386
1. Get the name of the AKS cluster node resource group using the [`az aks show`][az-aks-show] command.
387387
388-
```azurecli-interactive
388+
```bash
389389
export AKS_PRIMARY_CLUSTER_NODERG_NAME=$(az aks show \
390390
--name $AKS_PRIMARY_CLUSTER_NAME \
391391
--resource-group $RESOURCE_GROUP_NAME \
@@ -397,7 +397,7 @@ To validate deployment of the PostgreSQL cluster and use client PostgreSQL tooli
397397
398398
2. Create the public IP address using the [`az network public-ip create`][az-network-public-ip-create] command.
399399
400-
```azurecli-interactive
400+
```bash
401401
export AKS_PRIMARY_CLUSTER_PUBLICIP_NAME="$AKS_PRIMARY_CLUSTER_NAME-pip"
402402
403403
az network public-ip create \
@@ -412,7 +412,7 @@ To validate deployment of the PostgreSQL cluster and use client PostgreSQL tooli
412412
413413
3. Get the newly created public IP address using the [`az network public-ip show`][az-network-public-ip-show] command.
414414
415-
```azurecli-interactive
415+
```bash
416416
export AKS_PRIMARY_CLUSTER_PUBLICIP_ADDRESS=$(az network public-ip show \
417417
--resource-group $AKS_PRIMARY_CLUSTER_NODERG_NAME \
418418
--name $AKS_PRIMARY_CLUSTER_PUBLICIP_NAME \
@@ -424,7 +424,7 @@ To validate deployment of the PostgreSQL cluster and use client PostgreSQL tooli
424424
425425
4. Get the resource ID of the node resource group using the [`az group show`][az-group-show] command.
426426
427-
```azurecli-interactive
427+
```bash
428428
export AKS_PRIMARY_CLUSTER_NODERG_NAME_SCOPE=$(az group show --name \
429429
$AKS_PRIMARY_CLUSTER_NODERG_NAME \
430430
--query id \
@@ -435,7 +435,7 @@ To validate deployment of the PostgreSQL cluster and use client PostgreSQL tooli
435435
436436
5. Assign the "Network Contributor" role to the UAMI object ID using the node resource group scope using the [`az role assignment create`][az-role-assignment-create] command.
437437
438-
```azurecli-interactive
438+
```bash
439439
az role assignment create \
440440
--assignee-object-id ${AKS_UAMI_WORKLOAD_OBJECTID} \
441441
--assignee-principal-type ServicePrincipal \
@@ -451,13 +451,13 @@ In this section, you install the CNPG operator in the AKS cluster using Helm or
451451
452452
1. Add the CNPG Helm repo using the [`helm repo add`][helm-repo-add] command.
453453
454-
```azurecli-interactive
454+
```bash
455455
helm repo add cnpg https://cloudnative-pg.github.io/charts
456456
```
457457
458458
2. Upgrade the CNPG Helm repo and install it on the AKS cluster using the [`helm upgrade`][helm-upgrade] command with the `--install` flag.
459459
460-
```azurecli-interactive
460+
```bash
461461
helm upgrade --install cnpg \
462462
--namespace $PG_SYSTEM_NAMESPACE \
463463
--create-namespace \
@@ -467,7 +467,7 @@ In this section, you install the CNPG operator in the AKS cluster using Helm or
467467
468468
3. Verify the operator installation on the AKS cluster using the [`kubectl get`][kubectl-get] command.
469469
470-
```azurecli-interactive
470+
```bash
471471
kubectl get deployment \
472472
--context $AKS_PRIMARY_CLUSTER_NAME \
473473
--namespace $PG_SYSTEM_NAMESPACE cnpg-cloudnative-pg
@@ -477,7 +477,7 @@ In this section, you install the CNPG operator in the AKS cluster using Helm or
477477
478478
1. Install the CNPG operator on the AKS cluster using the [`kubectl apply`][kubectl-apply] command.
479479
480-
```azurecli-interactive
480+
```bash
481481
kubectl apply --context $AKS_PRIMARY_CLUSTER_NAME \
482482
--namespace $PG_SYSTEM_NAMESPACE \
483483
--server-side -f \
@@ -486,7 +486,7 @@ In this section, you install the CNPG operator in the AKS cluster using Helm or
486486
487487
2. Verify the operator installation on the AKS cluster using the [`kubectl get`][kubectl-get] command.
488488
489-
```azurecli-interactive
489+
```bash
490490
kubectl get deployment \
491491
--namespace $PG_SYSTEM_NAMESPACE cnpg-controller-manager \
492492
--context $AKS_PRIMARY_CLUSTER_NAME

0 commit comments

Comments
 (0)