Skip to content

Commit a9354a4

Browse files
authored
Merge pull request #5 from fossygirl/aj_fixes
Install Krew and cnpg Fixing md and yaml syntax separating out from command execution for copy/paste
2 parents a0d2393 + e876d66 commit a9354a4

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

articles/aks/create-postgresql-ha.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ az extension add --upgrade --name k8s-extension --yes --allow-preview false
5353
az extension add --upgrade --name amg --yes --allow-preview false
5454
```
5555

56+
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.
57+
58+
```azurecli
59+
(
60+
set -x; cd "$(mktemp -d)" &&
61+
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
62+
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
63+
KREW="krew-${OS}_${ARCH}" &&
64+
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
65+
tar zxvf "${KREW}.tar.gz" &&
66+
./"${KREW}" install krew
67+
)
68+
69+
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
70+
71+
kubectl krew install cnpg
72+
```
73+
5674
## Create a resource group
5775

5876
Create a resource group to hold the resources you create in this guide using the [`az group create`][az-group-create] command.
@@ -112,7 +130,7 @@ The CNPG operator automatically generates a service account called *postgres* th
112130
--kind StorageV2 \
113131
--query 'provisioningState' \
114132
--output tsv
115-
```
133+
```
116134
117135
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.
118136
@@ -124,7 +142,7 @@ The CNPG operator automatically generates a service account called *postgres* th
124142
```
125143
126144
> [!NOTE]
127-
> 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.
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.
128146
129147
```azurecli-interactive
130148
az role assignment list --scope $STORAGE_ACCOUNT_PRIMARY_RESOURCE_ID --output table
@@ -507,3 +525,5 @@ Now that you've created the require infrastructure, [deploy a highly available P
507525
[helm-upgrade]: https://helm.sh/docs/helm/helm_upgrade/
508526
[kubectl-apply]: https://kubernetes.io/docs/reference/kubectl/generated/kubectl_apply/
509527
[deploy-postgresql]: ./deploy-postgresql-ha.md
528+
[install-krew]: https://krew.sigs.k8s.io/
529+
[cnpg-plugin]: https://cloudnative-pg.io/documentation/current/kubectl-plugin/#using-krew

articles/aks/deploy-postgresql-ha.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ The following table outlines the key properties set in the YAML deployment manif
145145
instances: 3
146146
minSyncReplicas: 1
147147
maxSyncReplicas: 1
148-
148+
149149
topologySpreadConstraints:
150150
- maxSkew: 1
151151
topologyKey: topology.kubernetes.io/zone
@@ -230,9 +230,10 @@ The following table outlines the key properties set in the YAML deployment manif
230230
231231
```azurecli-interactive
232232
kubectl get pods --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
233+
```
233234
234-
# Example output
235-
235+
Example output
236+
```output
236237
NAME READY STATUS RESTARTS AGE
237238
pg-primary-cnpg-r8c7unrw-1 1/1 Running 0 4m25s
238239
pg-primary-cnpg-r8c7unrw-2 1/1 Running 0 3m33s
@@ -251,9 +252,10 @@ The CNPG operator automatically creates a PodMonitor for the primary instance us
251252
get podmonitors.monitoring.coreos.com \
252253
$PG_PRIMARY_CLUSTER_NAME \
253254
--output yaml
254-
255-
# Example output
255+
```
256256
257+
Example output
258+
```output
257259
kind: PodMonitor
258260
metadata:
259261
annotations:
@@ -402,9 +404,10 @@ In this section, you create a table and insert some data into the app database t
402404
403405
```azurecli-interactive
404406
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME 1 --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
407+
```
405408
406-
# Example output
407-
409+
Example output
410+
```output
408411
Continuous Backup status
409412
First Point of Recoverability: Not Available
410413
Working WAL archiving: FAILING
@@ -433,9 +436,10 @@ In this section, you create a table and insert some data into the app database t
433436
434437
```azurecli-interactive
435438
kubectl describe backup $BACKUP_ONDEMAND_NAME --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
439+
```
436440
437-
# Example output
438-
441+
Example output
442+
```output
439443
Type Reason Age From Message
440444
---- ------ ---- ---- -------
441445
Normal Starting 6s cloudnative-pg-backup Starting backup for cluster pg-primary-cnpg-r8c7unrw
@@ -447,9 +451,10 @@ In this section, you create a table and insert some data into the app database t
447451
448452
```azurecli-interactive
449453
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME 1 --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
454+
```
450455
451-
# Example output
452-
456+
Example output
457+
```output
453458
Continuous Backup status
454459
First Point of Recoverability: 2024-06-05T13:47:18Z
455460
Working WAL archiving: OK
@@ -638,9 +643,10 @@ You also retrieve the following endpoints from the Cluster IP service:
638643
639644
```azurecli-interactive
640645
kubectl get services --context $AKS_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE -l cnpg.io/cluster=$PG_PRIMARY_CLUSTER_NAME
646+
```
641647
642-
# Example output
643-
648+
Example output
649+
```output
644650
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
645651
pg-primary-cnpg-sryti1qf-r ClusterIP 10.0.193.27 <none> 5432/TCP 3h57m
646652
pg-primary-cnpg-sryti1qf-ro ClusterIP 10.0.237.19 <none> 5432/TCP 3h57m
@@ -756,7 +762,7 @@ Remember that the primary read-write endpoint maps to TCP port 5432 and the read
756762
# Query the primary, pg_is_in_recovery = false
757763
758764
psql -h $AKS_PRIMARY_CLUSTER_ALB_DNSNAME \
759-
-p 5432 -U app -d appdb -W -c "SELECT pg_is_in_recovery();"
765+
-p 5432 -U app -d appdb -W -c "SELECT pg_is_in_recovery();"
760766
761767
# Example output
762768
@@ -768,14 +774,14 @@ Remember that the primary read-write endpoint maps to TCP port 5432 and the read
768774
# Query a replica, pg_is_in_recovery = true
769775
770776
psql -h $AKS_PRIMARY_CLUSTER_ALB_DNSNAME \
771-
-p 5433 -U app -d appdb -W -c "SELECT pg_is_in_recovery();"
777+
-p 5433 -U app -d appdb -W -c "SELECT pg_is_in_recovery();"
772778
773779
# Example output
774780
775781
pg_is_in_recovery
776782
-------------------
777783
t
778-
(1 row)
784+
(1 row)
779785
```
780786
781787
When successfully connected to the primary read-write endpoint, the PostgreSQL function returns `f` for *false*, indicating that the current connection is writable.
@@ -790,9 +796,10 @@ In this section, you trigger a sudden failure by deleting the pod running the pr
790796
791797
```azurecli-interactive
792798
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
793-
794-
# Example output
799+
```
795800
801+
Example output
802+
```output
796803
Name Current LSN Rep role Status Node
797804
--------------------------- ----------- -------- ------- -----------
798805
pg-primary-cnpg-sryti1qf-1 0/9000060 Primary OK aks-postgres-32388626-vmss000000
@@ -815,9 +822,10 @@ In this section, you trigger a sudden failure by deleting the pod running the pr
815822
816823
```azurecli-interactive
817824
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
825+
```
818826
819-
# Example output
820-
827+
Example output
828+
```output
821829
pg-primary-cnpg-sryti1qf-2 0/9000060 Primary OK aks-postgres-32388626-vmss000001
822830
pg-primary-cnpg-sryti1qf-1 0/9000060 Standby (sync) OK aks-postgres-32388626-vmss000000
823831
pg-primary-cnpg-sryti1qf-3 0/9000060 Standby (sync) OK aks-postgres-32388626-vmss000002
@@ -833,9 +841,10 @@ In this section, you trigger a sudden failure by deleting the pod running the pr
833841
834842
```azurecli-interactive
835843
kubectl cnpg status $PG_PRIMARY_CLUSTER_NAME --namespace $PG_NAMESPACE
844+
```
836845
837-
# Example output
838-
846+
Example output
847+
```output
839848
Name Current LSN Rep role Status Node
840849
--------------------------- ----------- -------- ------- -----------
841850
pg-primary-cnpg-sryti1qf-1 0/9000060 Primary OK aks-postgres-32388626-vmss000000

0 commit comments

Comments
 (0)