Skip to content

Commit f73d96d

Browse files
committed
Fixes:
- more descriptive steps for BLOB rbac - added fixes for HA - updated values for performance - reworked codeblocks for ease of copy/paste - fixed outputs to match text and desired state
1 parent 9315920 commit f73d96d

File tree

2 files changed

+114
-26
lines changed

2 files changed

+114
-26
lines changed

articles/aks/create-postgresql-ha.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,22 @@ The CNPG operator automatically generates a service account called *postgres* th
141141
--auth-mode login
142142
```
143143

144+
Example output:
145+
146+
```output
147+
{
148+
"created": true
149+
}
150+
```
151+
144152
> [!NOTE]
145-
> 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.
153+
> 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 and after retry the [`az storage container create`][az-storage-container-create] command.
146154

147155
```bash
148156
az role assignment list --scope $STORAGE_ACCOUNT_PRIMARY_RESOURCE_ID --output table
149157
150158
export USER_ID=$(az ad signed-in-user show --query id --output tsv)
159+
151160
export STORAGE_ACCOUNT_PRIMARY_RESOURCE_ID=$(az storage account show \
152161
--name $PG_PRIMARY_STORAGE_ACCOUNT_NAME \
153162
--resource-group $RESOURCE_GROUP_NAME \

articles/aks/deploy-postgresql-ha.md

Lines changed: 104 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,14 @@ The following table outlines the key properties set in the YAML deployment manif
142142
azure.workload.identity/use: "true"
143143
144144
instances: 3
145+
startDelay: 30
146+
stopDelay: 30
145147
minSyncReplicas: 1
146148
maxSyncReplicas: 1
149+
replicationSlots:
150+
highAvailability:
151+
enabled: true
152+
updateInterval: 30
147153
148154
topologySpreadConstraints:
149155
- maxSkew: 1
@@ -159,11 +165,11 @@ The following table outlines the key properties set in the YAML deployment manif
159165
160166
resources:
161167
requests:
162-
memory: '2Gi'
163-
cpu: 1.5
168+
memory: '8Gi'
169+
cpu: 2
164170
limits:
165-
memory: '2Gi'
166-
cpu: 1.5
171+
memory: '8Gi'
172+
cpu: 2
167173
168174
bootstrap:
169175
initdb:
@@ -196,15 +202,25 @@ The following table outlines the key properties set in the YAML deployment manif
196202
monitoring:
197203
enablePodMonitor: true
198204
199-
replicationSlots:
200-
highAvailability:
201-
enabled: true
202-
203205
postgresql:
204206
parameters:
205-
shared_buffers: "256MB"
206-
effective_cache_size: "512MB"
207-
# max_worker_processes: 64
207+
archive_timeout: '5min'
208+
auto_explain.log_min_duration: '10s'
209+
checkpoint_completion_target: '0.9'
210+
checkpoint_timeout: '15min'
211+
shared_buffers: '256MB'
212+
effective_cache_size: '512MB'
213+
pg_stat_statements.max: '1000'
214+
pg_stat_statements.track: 'all'
215+
max_connections: '400'
216+
max_prepared_transactions: '400'
217+
max_parallel_workers: '32'
218+
max_parallel_maintenance_workers: '8'
219+
max_parallel_workers_per_gather: '8'
220+
max_replication_slots: '32'
221+
max_worker_processes: '32'
222+
wal_keep_size: '512MB'
223+
max_wal_size: '1GB'
208224
pg_hba:
209225
- host all all all scram-sha-256
210226
@@ -228,7 +244,7 @@ The following table outlines the key properties set in the YAML deployment manif
228244
1. Validate that the primary PostgreSQL cluster was successfully created using the [`kubectl get`][kubectl-get] command. The CNPG Cluster CRD specified three instances, which can be validated by viewing running pods once each instance is brought up and joined for replication. Be patient as it can take some time for all three instances to come online and join the cluster.
229245
230246
```bash
231-
kubectl get pods --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
247+
kubectl get pods --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE -l cnpg.io/cluster=$PG_PRIMARY_CLUSTER_NAME
232248
```
233249
234250
Example output
@@ -292,7 +308,7 @@ Verify that the pod monitor is created (note the difference in the group name).
292308
kubectl --namespace $PG_NAMESPACE \
293309
--context $AKS_PRIMARY_CLUSTER_NAME \
294310
get podmonitors.azmonitoring.coreos.com \
295-
$PG_PRIMARY_CLUSTER_NAME \
311+
-l cnpg.io/cluster=$PG_PRIMARY_CLUSTER_NAME \
296312
-o yaml
297313
```
298314
@@ -361,7 +377,9 @@ In this section, you create a table and insert some data into the app database t
361377
362378
```bash
363379
kubectl cnpg psql $PG_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
380+
```
364381
382+
```sql
365383
# Run the following PSQL commands to create a small dataset
366384
# postgres=#
367385
@@ -374,22 +392,49 @@ In this section, you create a table and insert some data into the app database t
374392
# Type \q to exit psql
375393
```
376394
395+
Your output should resemble the following example output:
396+
397+
```output
398+
CREATE TABLE
399+
INSERT 0 1
400+
INSERT 0 1
401+
INSERT 0 1
402+
count
403+
-------
404+
3
405+
(1 row)
406+
```
407+
377408
## Connect to PostgreSQL read-only replicas
378409
379410
* Connect to the PostgreSQL read-only replicas and validate the sample dataset using the following commands:
380411
381412
```bash
382413
kubectl cnpg psql --replica $PG_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
414+
```
383415
416+
```sql
384417
#postgres=#
385418
SELECT pg_is_in_recovery();
419+
```
420+
421+
Example output
422+
423+
```output
386424
# pg_is_in_recovery
387425
#-------------------
388426
# t
389427
#(1 row)
428+
```
390429
430+
```sql
391431
#postgres=#
392432
SELECT COUNT(*) FROM datasample;
433+
```
434+
435+
Example output
436+
437+
```output
393438
# count
394439
#-------
395440
# 3
@@ -403,17 +448,20 @@ In this section, you create a table and insert some data into the app database t
403448
1. Validate that the PostgreSQL cluster can access the Azure storage account specified in the CNPG Cluster CRD and that `Working WAL archiving` reports as `OK` using the following command:
404449
405450
```bash
406-
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME 1 --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
451+
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME 1 \
452+
--context $AKS_PRIMARY_CLUSTER_NAME \
453+
--namespace $PG_NAMESPACE
407454
```
408455
409456
Example output
410457
411458
```output
412459
Continuous Backup status
413460
First Point of Recoverability: Not Available
414-
Working WAL archiving: FAILING
461+
Working WAL archiving: OK
415462
WALs waiting to be archived: 0
416-
Last Archived WAL: 000000010000000000000009 @ 2024-06-05T13:39:23.597668Z
463+
Last Archived WAL: 00000001000000000000000A @ 2024-07-09T17:18:13.982859Z
464+
Last Failed WAL: -
417465
```
418466
419467
1. Deploy an on-demand backup to Azure Storage, which uses the AKS workload identity integration, using the YAML file with the [`kubectl apply`][kubectl-apply] command.
@@ -436,7 +484,9 @@ In this section, you create a table and insert some data into the app database t
436484
1. Validate the status of the on-demand backup using the [`kubectl describe`][kubectl-describe] command.
437485
438486
```bash
439-
kubectl describe backup $BACKUP_ONDEMAND_NAME --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
487+
kubectl describe backup $BACKUP_ONDEMAND_NAME \
488+
--context $AKS_PRIMARY_CLUSTER_NAME \
489+
--namespace $PG_NAMESPACE
440490
```
441491
442492
Example output
@@ -452,7 +502,9 @@ In this section, you create a table and insert some data into the app database t
452502
1. Validate that the cluster has a first point of recoverability using the following command:
453503
454504
```bash
455-
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME 1 --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
505+
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME 1 \
506+
--context $AKS_PRIMARY_CLUSTER_NAME \
507+
--namespace $PG_NAMESPACE
456508
```
457509
458510
Example output
@@ -485,13 +537,19 @@ In this section, you create a table and insert some data into the app database t
485537
1. Validate the status of the scheduled backup using the [`kubectl describe`][kubectl-describe] command.
486538
487539
```bash
488-
kubectl describe scheduledbackup $BACKUP_SCHEDULED_NAME --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
540+
kubectl describe scheduledbackup $BACKUP_SCHEDULED_NAME \
541+
--context $AKS_PRIMARY_CLUSTER_NAME \
542+
--namespace $PG_NAMESPACE
489543
```
490544
491545
1. View the backup files stored on Azure blob storage for the primary cluster using the [`az storage blob list`][az-storage-blob-list] command.
492546
493547
```bash
494-
az storage blob list --account-name $PG_PRIMARY_STORAGE_ACCOUNT_NAME --container-name backups --query "[*].name" --only-show-errors
548+
az storage blob list \
549+
--account-name $PG_PRIMARY_STORAGE_ACCOUNT_NAME \
550+
--container-name backups \
551+
--query "[*].name" \
552+
--only-show-errors
495553
```
496554
497555
Your output should resemble the following example output, validating the backup was successful:
@@ -606,8 +664,15 @@ You also create a second federated credential to map the new recovery cluster se
606664
607665
```bash
608666
kubectl cnpg psql $PG_PRIMARY_CLUSTER_NAME_RECOVERED --namespace $PG_NAMESPACE
667+
```
609668
669+
```sql
610670
postgres=# SELECT COUNT(*) FROM datasample;
671+
```
672+
673+
Example output
674+
675+
```output
611676
# count
612677
#-------
613678
# 3
@@ -619,7 +684,9 @@ You also create a second federated credential to map the new recovery cluster se
619684
1. You can now delete the recovered cluster using the following command:
620685
621686
```bash
622-
kubectl cnpg destroy $PG_PRIMARY_CLUSTER_NAME_RECOVERED 1 --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
687+
kubectl cnpg destroy $PG_PRIMARY_CLUSTER_NAME_RECOVERED 1 \
688+
--context $AKS_PRIMARY_CLUSTER_NAME \
689+
--namespace $PG_NAMESPACE
623690
```
624691
625692
1. You can now delete the federated identity credential using the [`az identity federated-credential delete`][az-identity-federated-credential-delete] command.
@@ -645,7 +712,10 @@ You also retrieve the following endpoints from the Cluster IP service:
645712
1. Get the Cluster IP service details using the [`kubectl get`][kubectl-get] command.
646713
647714
```bash
648-
kubectl get services --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE -l cnpg.io/cluster=$PG_PRIMARY_CLUSTER_NAME
715+
kubectl get services \
716+
--context $AKS_PRIMARY_CLUSTER_NAME \
717+
--namespace $PG_NAMESPACE \
718+
-l cnpg.io/cluster=$PG_PRIMARY_CLUSTER_NAME
649719
```
650720
651721
Example output
@@ -767,19 +837,27 @@ Remember that the primary read-write endpoint maps to TCP port 5432 and the read
767837
768838
psql -h $AKS_PRIMARY_CLUSTER_ALB_DNSNAME \
769839
-p 5432 -U app -d appdb -W -c "SELECT pg_is_in_recovery();"
840+
```
770841
771-
# Example output
772-
842+
Example output
843+
844+
```output
773845
pg_is_in_recovery
774846
-------------------
775847
f
776848
(1 row)
849+
```
777850
778-
# Query a replica, pg_is_in_recovery = true
851+
```bash
852+
echo "Query a replica, pg_is_in_recovery = true"
779853
780854
psql -h $AKS_PRIMARY_CLUSTER_ALB_DNSNAME \
781855
-p 5433 -U app -d appdb -W -c "SELECT pg_is_in_recovery();"
856+
```
782857
858+
Example output
859+
860+
```output
783861
# Example output
784862
785863
pg_is_in_recovery
@@ -820,6 +898,7 @@ In this section, you trigger a sudden failure by deleting the pod running the pr
820898
--no-headers \
821899
-o custom-columns=":metadata.name" \
822900
-l role=primary)
901+
823902
kubectl delete pod $PRIMARY_POD --grace-period=1 --namespace $PG_NAMESPACE
824903
```
825904

0 commit comments

Comments
 (0)