将数据从 Zalando 迁移至 Linux on Power ( ppc64le ) 集群上的 CloudNativePG

您可以在以副本模式运行的集群中,通过引导 pg_basebackup 模式将数据从 Zalando 迁移至 CloudNativePG。 要传输数据,您需要创建一个 CloudNativePG 副本集群(目标),该集群将复制 Zalando 数据存储(源)。

先决条件

要从实时集群引导,请完成以下步骤:

  • 确保目标和源具有相同的主 PostgreSQL 版本。
  • 在 ZalandoPostgreSQL 数据库中,为用户 streaming_replica 配置复制和登录角色。

为数据迁移修改 Zalando Postgres 数据存储

要修改 Zalando Postgres 数据存储以进行数据迁移,请完成以下步骤:

  1. 连接到 Zalando pod:

    1. 查看主 pod 的详细信息:

      kubectl get pods -o jsonpath={.items..metadata.name} -l application=spilo,spilo-role=master -n instana-postgres
      
    2. 直接在 pod 中运行命令

      kubectl exec -it <primary_pod_name> -n instana-postgres
      
    3. 连接Postgres数据库:

      psql -U postgres
      
    4. 列出角色,并在 Zalando 数据库中创建一个具有复制和登录 streaming_replica 角色的用户:

      \du
      CREATE ROLE streaming_replica WITH REPLICATION;
      ALTER ROLE streaming_replica WITH LOGIN PASSWORD '<password_retrived_from_zalando>';
      
    5. 退出PostgreSQL交互式终端:

      \q
      
  2. 在所有 pod 上的 pgdata 目录中创建两个名为 custom.confoverride.conf 的空文件,这些文件与 postgresql.conf 文件一起存在。

    1. 列出 pod:

      kubectl get pods -n instana-postgres
      
    2. 直接在 pod 上运行命令 在所有 pod 上运行以下命令

      kubectl exec -it <pod_name> -n instana-postgres
      
      cd /var/lib/postgresql/data/pgdata
      touch -f custom.conf
      touch -f override.conf
      
  3. 从 pod 终端退出:

    exit
    

使用 CloudNativePG Postgres 操作员创建 Postgres 数据存储以进行数据迁移

在线安装 Postgres 操作员

  1. 要在线部署 CloudNativePG Postgres 操作器,请完成以下步骤:

    1. 创建 instana-postgres-01 名称空间:

      kubectl create namespace instana-postgres-01
      
    2. 确定 Red Hat OpenShift上的文件系统组标识。

      Red Hat OpenShift 要求文件系统组在特定于名称空间的值范围内。 在部署了 CloudNativePG Kubernetes 操作器的群集上,运行以下命令:

      kubectl get namespace instana-postgres-01 -o yaml
      

      对于该命令,将显示类似于以下示例的输出:

      apiVersion: v1
      kind: Namespace
      metadata:
        annotations:
          .......
          openshift.io/sa.scc.uid-range: 1000750000/10000
        creationTimestamp: "2024-01-14T07:04:59Z"
        labels:
          kubernetes.io/metadata.name: instana-postgres-01
          .......
        name: instana-postgres-01
      

      openshift.io/sa.scc.supplemental-groups 注释包含允许的标识范围。 范围 1000750000/10000 指示以标识 1000750000开头的 10,000 个值,因此它指定从 10007500001000760000的标识范围。 在此示例中,值 1000750000 可用作文件系统组标识。

    3. 运行以下 Helm 命令,安装 CloudNativePG Postgres 操作器:

      helm repo add instana https://artifact-public.instana.io/artifactory/rel-helm-customer-virtual --username=_ --password=<AGENT_KEY>
      
      helm repo update
      
      helm install cnpg instana/cloudnative-pg --set image.repository=artifact-public.instana.io/self-hosted-images/3rd-party/operator/cloudnative-pg --set image.tag=v1.29.1_v0.34.0 --version=0.28.2 --set imagePullSecrets[0].name=instana-registry --set containerSecurityContext.runAsUser=<UID from namespace> --set containerSecurityContext.runAsGroup=<UID from namespace> -n instana-postgres-01
      
  2. instana-postgres-01 名称空间创建映像拉取私钥:

    kubectl create secret docker-registry instana-registry -n instana-postgres-01 \
    --docker-username=_ \
    --docker-password=<AGENT_KEY> \
    --docker-server=artifact-public.instana.io
    
    注: 在创建私钥之前,请使用您自己的代理程序密钥更新 <AGENT_KEY> 值。
  3. 创建文件 (例如 postgres-secret.yaml) 以进行外部集群访问:

    kind: Secret
    apiVersion: v1
    metadata:
      name: instanaadmin
    type: Opaque
    stringData:
      username: instanaadmin
      password: <user_generated_password_from_zalando>
    
  4. 应用 "postgres-secret.yaml文件:

    kubectl apply -f postgres-secret.yaml -n instana-postgres-01
    
  5. replica 模式创建 CloudNativePG Cluster 资源:

    1. 创建文件,例如 cnpg-postgres.yaml,如下所示:

      apiVersion: postgresql.cnpg.io/v1
      kind: Cluster
      metadata:
        name: postgres
      spec:
        instances: 3
        imageName: artifact-public.instana.io/self-hosted-images/3rd-party/cnpg-containers:15_v0.39.0
        imagePullPolicy: IfNotPresent
        imagePullSecrets:
          - name: instana-registry
        enableSuperuserAccess: true
        replicationSlots:
          highAvailability:
            enabled: true
        managed:
          roles:
          - name: instanaadmin
            login: true
            superuser: true
            createdb: true
            createrole: true
            replication: true
            passwordSecret:
              name: instanaadmin
        postgresql:
          pg_hba:
            - local     all          all                            trust
            - host      replication  postgres          all          trust
            - host      replication  streaming_replica 0.0.0.0/0    trust
            - host      all          all               0.0.0.0/0    trust
            - local     replication  standby                        trust
            - hostssl   replication  standby      all               md5
            - hostnossl all          all          all               reject
            - hostssl   all          all          all               md5
        bootstrap:
          pg_basebackup:
            source: zalando-postgres
        replica:
          enabled: true
          source: zalando-postgres
      
        externalClusters:
        - name: zalando-postgres
          connectionParameters:
            host: postgres.instana-postgres.svc
            user: postgres
          password:
            name: instanaadmin
            key: password
      
        superuserSecret:
          name: instanaadmin
      
        storage:
          size: 20Gi
          storageClass: nfs-client
      
    2. 通过运行以下命令来应用 cnpg-postgres.yaml 文件:

      kubectl apply -f cnpg-postgres.yaml -n instana-postgres-01
      
  6. SSH 进入第一个 CloudNativePG pod 的调试容器,修改 postgresql.conf

    在以副本方式初始化集群之后,初始 Pod (postgres-1-pgbasebackup) 状态将为 Completed。 随后尝试启动第一个 CloudNativePG Pod (postgres-1)将失败。 这是预期的行为。

    要确保成功初始化 Cluster 并随后启动 Pod ,请完成以下步骤:

    1. 运行以下命令以确定初始 Pod , SSH 到其中,然后转至包含 pgdata 卷的目录:

      kubectl debug pod/postgres-1 --as-root -n instana-postgres-01
      
      cd /var/lib/postgresql/data/pgdata/
      
    2. 修改每个 pod 中 postgresql.conf 文件内的 pg_hbapg_ident 路径:

      • pg_hba 路径从 /var/lib/postgresql/15/main/pg_hba.conf 更改为以下路径:

        /var/lib/postgresql/data/pgdata/pg_hba.conf
        
      • pg_ident 路径从 /var/lib/postgresql/15/main/pg_ident.conf 更改为以下路径:

        /var/lib/postgresql/data/pgdata/pg_ident.conf
        
    3. 在文件末尾添加 include 'custom.conf'include 'override.conf' :

      echo "include 'custom.conf'" >> postgresql.conf
      echo "include 'override.conf'" >> postgresql.conf
      
  7. 重新启动 pod。 豆荚启动后,所有豆荚都从第一个豆荚开始复制。

  8. 使用新的 cnpg-cluster。

    1. 禁用副本集群:

      1. 修改 cnpg-postgres.yaml 文件:

        ........
        replica:
        enabled: false
        source: zalando-postgres
        ..........
        
      2. 重新应用 cnpg-postgres.yaml 文件:

        kubectl apply -f cnpg-postgres.yaml -n instana-postgres-01
        
    2. 连接到数据库:

      psql -U postgres
      
    3. 更新整理版本:

      ALTER DATABASE template1 REFRESH COLLATION VERSION;
      
  9. 更新核心规范配置:

    1. 在您的 Instana Core 文件中,请按照以下示例更新配置 postgresConfig

      .....................
      postgresConfigs:
        - authEnabled: true
           hosts:
             - postgres-rw.instana-postgres-01
      .....................
      
    2. 重新应用 core.yaml 文件:

      kubectl apply -f core.yaml -n instana-core