Zalando 에서 CloudNativePG 으로의 데이터 마이그레이션 (클러스터 및 Linux on IBM Z and LinuxONELinux x86_64 클러스터에서)

복제 모드로 운영 중인 클러스터 내에서 부트스트랩 pg_basebackup 모드를 사용하여 Zalando 에서 CloudNativePG 으로 데이터를 전송할 수 있습니다. 데이터를 전송하려면 Zalando 데이터 저장소(소스)를 복제하는 CloudNativePG 복제 클러스터(대상)를 생성해야 합니다.

전제조건

실행 중인 클러스터에서 부트스트랩하려면 다음 단계를 완료하십시오:

  • 대상과 소스가 동일한 메이저 버전( PostgreSQL )을 가지는지 확인하십시오.
  • ZalandoPostgreSQL 데이터베이스에서 복제 및 로그인 역할을 가진 사용자를 streaming_replica 설정하십시오.

Zalando 의 Postgres 데이터 저장소 수정(데이터 마이그레이션용)

데이터 마이그레이션을 위해 Zalando 의 Postgres 데이터 저장소를 수정하려면 다음 단계를 완료하십시오:

  1. Zalando 포드에 연결:

    1. 기본 포드의 세부 정보를 확인하세요:

      kubectl get pods -o jsonpath={.items..metadata.name} -l application=spilo,spilo-role=master -n instana-postgres
      
    2. 포드 내에서 직접 명령어를 실행합니다:

      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. 모든 포드의 pgdata 디렉터리 내에 파일과 postgresql.conf 동일한 override.conf 위치에 및 custom.conf 라는 두 개의 빈 파일을 생성하십시오.

    1. 팟(Pod)을 나열하십시오.

      kubectl get pods -n instana-postgres
      
    2. 포드에서 직접 명령어를 실행합니다. 모든 포드에서 다음 명령어를 실행하십시오:

      kubectl exec -it <pod_name> -n instana-postgres
      
      cd /var/lib/postgresql/data/pgdata
      touch -f custom.conf
      touch -f override.conf
      
  3. 포드 터미널에서 나가기:

    exit
    

CloudNativePGPostgres 연산자를 사용한 데이터 마이그레이션을 통한 Postgres 데이터 저장소 생성

Postgres 운영자 온라인 설치

  1. CloudNativePGPostgres 오퍼레이터를 온라인으로 배포하려면 다음 단계를 완료하십시오:

    1. 네임스페이스를 instana-postgres-01 생성하십시오:

      kubectl create namespace instana-postgres-01
      
    2. Red Hat OpenShift 에서 파일 시스템 그룹 ID를 확인하십시오.

      Red Hat OpenShift 파일 시스템 그룹이 네임스페이스에 특정한 값 범위 내에 있어야 합니다. CloudNativePGKubernetes 연산자가 배포된 클러스터에서 다음 명령을 실행하십시오:

      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 허용되는 ID의 범위가 포함됩니다. 범위는 ID 로 시작하는 1000750000/10000 10,000개의 값을 1000750000나타내므로, ID 의 범위 를 지정합니다 10007500001000760000 . 이 예시에서 값은 파일 시스템 그룹 1000750000 ID로 사용될 수 있습니다.

    3. 다음 Helm 명령어를 실행하여 CloudNativePGPostgres 운영자를 설치하십시오:

      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. CloudNativePGCluster 리소스를 다음 replica 모드로 생성하십시오:

    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. 첫 번째 ` CloudNativePG ` 포드의 디버그 컨테이너에 SSH로 접속하여 수정합니다 postgresql.conf.

    클러스터가 복제본 모드로 초기화된 후, 초기 Pod (postgres-1-pgbasebackup) 상태는 가 됩니다 Completed. 첫 번째 CloudNativePG Pod(postgres-1)를 시작하려는 후속 시도는 실패할 것입니다. 이는 예상 동작입니다.

    포드의 Cluster 초기화 및 후속 시작을 성공적으로 수행하려면 다음 단계를 완료하십시오:

    1. 다음 명령어를 실행하여 초기 Pod를 확인하고, 해당 Pod에 SSH로 접속한 후 pgdata 볼륨이 포함된 디렉터리로 이동하십시오:

      kubectl debug pod/postgres-1 --as-root -n instana-postgres-01
      
      cd /var/lib/postgresql/data/pgdata/
      
    2. 각 포드 내부의 postgresql.conf 파일에서 및 pg_ident pg_hba 경로를 수정하십시오:

      • 경로를 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 'override.conf' 다음을 include 'custom.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