Installing Crunchy PostgreSQL Operator 5.1.0

以前Crunchy Postgres Operator 4系のインストール・アップグレードしたブログを書いた。

Crunchy PostgreSQL Operatorのサイトを確認したところ、Latest Versionが5系の5.1.0に更新されていたので、試しにインストールしてみる。

Crunchy Postgres Operator (PGO) v5のインストール方法や機能概要については、こちらの記事を参考にした。


導入環境・バージョン情報

  • PGO 5.1.0
  • DigitalOcean DOKS
    • Kubernetesバージョン:DOKS1.22.8
    • ノードタイプ:s-2vcpu-4gb
    • ノード数:3
  • オブジェクトストレージ:DigitalOcean Spaces(S3互換)

PGOのデプロイ

各種サンプル設定ファイルを作業環境に複製。

git clone https://github.com/CrunchyData/postgres-operator-examples.git
cd postgres-operator-examples/

PGO v5以降、PGOデプロイはKustomize or Helmを使うが、今回はHelmでデプロイ。

helm install pgo5 -n pgo5 --create-namespace helm/install

デプロイ確認。

helm ls -n pgo5
NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
pgo5    pgo5            1               2022-04-24 13:36:01.12609 +0900 JST     deployed        pgo-0.3.0       5.1.0
kubectl -n pgo5 get po -o wide
pgo-747d898c67-4jwg8               1/1     Running     0          2d2h   10.244.2.130   dok8s-pool1-cxo5d   <none>           <none>
pgo-upgrade-68b4797d7f-qfjph       1/1     Running     0          2d2h   10.244.2.150   dok8s-pool1-cxo5d   <none>           <none>

PostgreSQLクラスタ作成

postgres-operator-examplesレポジトリに各種構成のサンプル設定ファイルが用意されている。

今回はkustomize/high-availability, s3配下のサンプルファイルをベースに編集した。

cd postgres-operator-examples/kustomize
cp -rfp  high-availability hipha

PostgresCluster設定はpostgres.yamlファイルに記述されているため、下記のように再編集。

apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
  name: hipha
spec:
  image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi8-14.2-1
  postgresVersion: 14
  instances:
    - name: hipha1
      replicas: 2
      dataVolumeClaimSpec:
        accessModes:
        - "ReadWriteOnce"
        resources:
          requests:
            storage: 1Gi
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            podAffinityTerm:
              topologyKey: kubernetes.io/hostname
              labelSelector:
                matchLabels:
                  postgres-operator.crunchydata.com/cluster: hipha
                  postgres-operator.crunchydata.com/instance-set: hipha1

  proxy:
    pgBouncer:
      image: registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi8-1.16-2
      replicas: 2
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            podAffinityTerm:
              topologyKey: kubernetes.io/hostname
              labelSelector:
                matchLabels:
                  postgres-operator.crunchydata.com/cluster: hipha
                  postgres-operator.crunchydata.com/role: pgbouncer
                  
  backups:
    pgbackrest:
      image: registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi8-2.38-0
      configuration:
      - secret:
          name: pgo-s3-creds
      global:
        repo1-path: /pgbackrest/pgo5/hipha/repo1
        repo1-s3-uri-style: path
        repo1-s3-verify-tls: "n"
      repos:
      - name: repo1
        s3:
          bucket: "dok8s-space1"
          endpoint: "sgp1.digitaloceanspaces.com"
          region: "sgp1"
          
  users:
  - name: postgres
  - name: testuser
    databases:
      - testdb

次にDigitalOcean Spacesにアクセスするためのクレデンシャルを登録する。

cd postgres-operator-examples/kustomize/hipha
vi 3s.conf
[global]
repo1-s3-key=<AccessKey>
repo1-s3-key-secret=<SecretKey>

マニフェストの設定が完了したら、PostgreSQLクラスタをデプロイ。

kubectl apply -k kustomize/hipha

クラスタ状態の確認

master, replica, pgbouncerのPodが作成される。各Podがmaster or replicaかはラベルで確認可能。

kubectl -n pgo5 get po -L postgres-operator.crunchydata.com/role
NAME                               READY   STATUS      RESTARTS   AGE    ROLE
hipha-backup-b6jj--1-pl4n6         0/1     Completed   0          4d4h
hipha-hipha1-4467-0                2/2     Running     0          4d4h   master
hipha-hipha1-4xk4-0                2/2     Running     0          4d4h   replica
hipha-pgbouncer-7d586b7ff8-7rwd2   2/2     Running     0          4d4h   pgbouncer
hipha-pgbouncer-7d586b7ff8-mzhqv   2/2     Running     0          4d4h   pgbouncer
pgo-747d898c67-4jwg8               1/1     Running     0          4d4h
pgo-upgrade-68b4797d7f-qfjph       1/1     Running     0          4d4h

psqlでの接続確認

ローカルPCからkubectl port-forward機能を使って接続する。

まず、masterのPodにport-forwardする。

kubectl -n pgo5 port-forward hipha-hipha1-4467-0  5432:5432

クラスタデプロイ時に作成した”postgres”ユーザーで接続するが、パスワードはSecretから取得する。

PGPASSWORD=$(kubectl get secrets -n pgo5 hipha-pguser-postgres -o go-template='{{.data.password | base64decode}}') \ 
then else> psql -h localhost -U postgres
psql (14.2)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=#

PostgreSQL Serverのバージョン。

postgres=# select version();
                                                version
--------------------------------------------------------------------------------------------------------
 PostgreSQL 14.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4), 64-bit
(1 row)

レプリケーションの状態。

postgres=# select application_name, state, sync_state from pg_stat_replication;
  application_name   |   state   | sync_state
---------------------+-----------+------------
 hipha-hipha1-4xk4-0 | streaming | async
(1 row)

バックアップ設定

PGOのバックアップ・リストアは内部的にpgBackRestを利用している。

定期バックアップのスケジュール設定はspec.backups.pgbackrest.repos.schedulesで設定する。

バックアップ形式は”full”, “differential“, “incremental“。

スケジュールはcron形式で指定する。

  backups:
    pgbackrest:
      image: registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi8-2.38-0
      configuration:
      - secret:
          name: pgo-s3-creds
      global:
        repo1-path: /pgbackrest/pgo5/hipha/repo1
        repo1-s3-uri-style: path
        repo1-s3-verify-tls: "n"
        repo1-retention-full: "7"
        repo1-retention-full-type: time
      repos:
      - name: repo1
        schedules:
          full: "14 14 * * *"
        s3:
          bucket: "dok8s-space1"
          endpoint: "sgp1.digitaloceanspaces.com"
          region: "sgp1"

また、バックアップ有効期限は下記パラメータで指定している。

  • repo1-retention-full: “7”
  • repo1-retention-full-type: time ※保持期間を日数指定

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です