Linux x86_64 에서 Postgres 데이터 저장소 생성하기

Postgres 운영자를 설치하고 데이터 저장소를 설정하십시오.

Postgres 배포용 운영체제 버전 및 이미지 태그

고정된 Helm 차트 또는 운영자 버전에는 다음 이미지가 필요합니다.

표 1. Postgres 운영자 버전 및 이미지 태그
플랫폼 오퍼레이터 버전 Helm 차트 버전 태그가 있는 이미지
Linux® x86_64 1.29.1 0.28.2 artifact-public.instana.io/self-hosted-images/3rd-party/operator/cloudnative-pg: v1.29.1_v0.34.0

artifact-public.instana.io/self-hosted-images/3rd-party/datastore/cnpg-containers: 15_v0.39.0

CloudNativePG 명령어를 사용하여 Postgres 을 온라인으로 설치하기

온라인 환경에 ‘ Postgres ’ 데이터 저장소를 설치하려면 다음 단계를 따르십시오.

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

    kubectl create namespace instana-postgres
     
  2. instana-postgres 네임스페이스에 대한 이미지 풀 시크릿을 작성하십시오.

    kubectl create secret docker-registry instana-registry --namespace instana-postgres \
      --docker-username=_ \
      --docker-password=<download_key> \
      --docker-server=artifact-public.instana.io
     
  3. Red Hat® OpenShift® 클러스터에 Postgres 를 설치하는 경우, instana-postgres 네임스페이스에서 파일 시스템 그룹 ID를 확인하십시오. Red Hat OpenShift 파일 시스템 그룹이 해당 네임스페이스에 특정한 값의 범위 내에 있어야 합니다.

    kubectl get namespace instana-postgres -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
      .......
      name: instana-postgres
     

    openshift.io/sa.scc.supplemental-groups 어노테이션에는 허용되는 ID의 범위가 포함되어 있습니다. 1000750000/10000 범위는 ID 1000750000로 시작하는 10 ,000개 값을 표시하므로 1000750000 에서 1000760000까지의 ID 범위를 지정합니다. 이 예제에서 1000750000 값은 파일 시스템 그룹 ID (UID) 로 사용될 수 있습니다.

  4. Postgres 운영자를 설치하십시오. 다음 명령에서 이전 단계의 UID를 <UID from namespace> 로 사용하십시오.

    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
     
  5. base64에서 비밀번호를 생성하십시오. 비밀번호를 적어두십시오. 이를 나중에 config.yaml 파일에 저장해야 합니다.

    openssl rand -base64 24 | tr -cd 'a-zA-Z0-9' | head -c32; echo
     
  6. 이전 명령에서 가져온 비밀번호를 사용하여 Secret 유형의 자원을 작성하십시오.

    kind: Secret
    apiVersion: v1
    metadata:
      name: instanaadmin
    type: Opaque
    stringData:
      username: instanaadmin
      password: <user-generate-password>
     
  7. Postgres 시크릿을 작성하십시오.

    kubectl apply -f postgres-secret.yaml -n instana-postgres
     
  8. 예를 들어 postgres.yaml, Postgres 클러스터 구성이 포함된 ` YAML ` 파일을 생성합니다.

    apiVersion: postgresql.cnpg.io/v1
    kind: Cluster
    metadata:
      name: postgres
    spec:
      # Add the following Affinity snippet to schedule each pod on a different node. 
      # affinity:
      #   podAntiAffinityType: required
      instances: 3
      imageName: artifact-public.instana.io/self-hosted-images/3rd-party/datastore/cnpg-containers:15_v0.39.0
      imagePullPolicy: IfNotPresent
      imagePullSecrets:
        - name: instana-registry
      postgresql:
        parameters:
          shared_buffers: 32MB
          pg_stat_statements.track: all
          auto_explain.log_min_duration: '10s'
        pg_hba:
          - local     all          all                            trust
          - host      all          all          0.0.0.0/0         md5
          - local     replication  standby                        trust
          - hostssl   replication  standby      all               md5
          - hostnossl all          all          all               reject
          - hostssl   all          all          all               md5
      managed:
        roles:
        - name: instanaadmin
          login: true
          superuser: true
          createdb: true
          createrole: true
          passwordSecret:
            name: instanaadmin
      bootstrap:
        initdb:
          database: instanaadmin
          owner: instanaadmin
          secret:
            name: instanaadmin
      superuserSecret:
        name: instanaadmin
      storage:
        size: 1Gi
      #    storageClass: "Optional"
     
  9. Postgres 클러스터를 배치하십시오.

    kubectl apply -f postgres.yaml -n instana-postgres
     
  10. Postgres (온라인 및 오프라인)의 단계를 완료하십시오.

CloudNative 의 PG 연산자를 사용하여 Postgres 를 오프라인으로 설치하기

오프라인 환경에서 Postgres 운영자를 설치하십시오.

설치 준비시 외부 레지스트리에서 Postgres 이미지를 아직 가져오지 않은 경우 지금 가져올 수 있습니다. bastion 호스트에서 다음 명령을 실행하십시오. 그런 다음, 해당 이미지를 에어갭 환경에 있는 Instana 호스트로 복사하십시오.

docker pull artifact-public.instana.io/self-hosted-images/3rd-party/operator/cloudnative-pg:v1.29.1_v0.34.0
docker pull artifact-public.instana.io/self-hosted-images/3rd-party/datastore/cnpg-containers:15_v0.39.0
         

Instana 호스트에서 다음 단계를 수행하십시오.

  1. 이미지를 내부 이미지 레지스트리에 다시 태그 지정하십시오.

    docker tag artifact-public.instana.io/self-hosted-images/3rd-party/operator/cloudnative-pg:v1.29.1_v0.34.0 <internal-image-registry>/operator/cloudnative-pg:v1.29.1_v0.34.0
    docker tag artifact-public.instana.io/self-hosted-images/3rd-party/datastore/cnpg-containers:15_v0.39.0 <internal-image-registry>/datastore/cnpg-containers:15_v0.39.0
                   
  2. 배스천 호스트의 내부 이미지 레지스트리에 이미지를 푸시하십시오.

    docker push <internal-image-registry>/operator/cloudnative-pg:v1.29.1_v0.34.0
    docker push <internal-image-registry>/datastore/cnpg-containers:15_v0.39.0
                   
  3. instana-postgres 네임스페이스를 작성하십시오.

    kubectl create namespace instana-postgres
     
  4. 선택 사항입니다: 내부 이미지 레지스트리에 인증이 필요한 경우 이미지 풀 시크릿을 생성합니다.

    kubectl create secret docker-registry <secret_name> --namespace instana-postgres \
    --docker-username=<registry_username> \
    --docker-password=<registry_password> \
    --docker-server=<internal-image-registry>:<internal-image-registry-port> \
    --docker-email=<registry_email>
     
  5. Red Hat® OpenShift® 클러스터에 Postgres 를 설치하는 경우, instana-postgres 네임스페이스에서 파일 시스템 그룹 ID를 확인하십시오. Red Hat OpenShift 파일 시스템 그룹이 해당 네임스페이스에 특정한 값의 범위 내에 있어야 합니다.

    kubectl get namespace instana-postgres -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
      .......
      name: instana-postgres
     

    openshift.io/sa.scc.supplemental-groups 어노테이션에는 허용되는 ID의 범위가 포함되어 있습니다. 1000750000/10000 범위는 ID 1000750000로 시작하는 10 ,000개 값을 표시하므로 1000750000 에서 1000760000까지의 ID 범위를 지정합니다. 이 예제에서 1000750000 값은 파일 시스템 그룹 ID (UID) 로 사용될 수 있습니다.

  6. Postgres 운영자를 설치하십시오. 다음 명령에서 < download_key>값을 사용자 고유의 에이전트 키로 업데이트하십시오. 내부 레지스트리에 대한 이미지 풀 시크릿을 만든 경우 다음 명령에 --set image.imagePullSecrets[0].name="<internal-image-registry-pull-secret>을 추가합니다.

    • Red Hat OpenShift 클러스터

      다음 명령에서 이전 단계의 UID를 <UID from namespace> 로 사용하십시오.

      helm install cnpg cloudnative-pg-0.28.2.tgz --set image.repository=image-registry.openshift-image-registry.svc:5000/instana-postgres/cloudnative-pg-operator --set image.tag=v1.29.1_v0.34.0 --version=0.28.2 --set containerSecurityContext.runAsUser=<UID from namespace> --set containerSecurityContext.runAsGroup=<UID from namespace> -n instana-postgres
       
    • Kubernetes 클러스터

      helm install cnpg cloudnative-pg-0.28.2.tgz --set image.repository=<internal-image-registry>/operator/cloudnative-pg --set image.tag=v1.29.1_v0.34.0 --version=0.28.2 -n instana-postgres
       
  7. base64에서 비밀번호를 생성하십시오. 비밀번호를 적어두십시오. 이를 나중에 config.yaml 파일에 저장해야 합니다.

    openssl rand -base64 24 | tr -cd 'a-zA-Z0-9' | head -c32; echo
     
  8. 이전 명령에서 가져온 비밀번호를 사용하여 Secret 유형의 자원을 작성하십시오.

    kind: Secret
    apiVersion: v1
    metadata:
      name: instanaadmin
    type: Opaque
    stringData:
      username: instanaadmin
      password: <user-generate-password>
     
  9. Postgres 시크릿을 작성하십시오.

    kubectl apply -f postgres-secret.yaml -n instana-postgres
     
  10. 예를 들어 postgres.yaml, Postgres 클러스터 구성이 포함된 ` YAML ` 파일을 생성합니다.

    apiVersion: postgresql.cnpg.io/v1
    kind: Cluster
    metadata:
      name: postgres
    spec:
      # Add the following Affinity snippet to schedule each pod on a different node. 
      # affinity:
      #   podAntiAffinityType: required
      instances: 3
      imageName: <internal-image-registry>/datastore/cnpg-containers:15_v0.39.0
      imagePullPolicy: IfNotPresent
     # Optional: if you created an image pull secret for your internal registry, uncomment the following lines and update the image pull secret information.
     # imagePullSecrets:
     #   - name: <internal-image-registry-pull-secret>
      postgresql:
        parameters:
          shared_buffers: 32MB
          pg_stat_statements.track: all
          auto_explain.log_min_duration: '10s'
        pg_hba:
          - local     all          all                            trust
          - host      all          all          0.0.0.0/0         md5
          - local     replication  standby                        trust
          - hostssl   replication  standby      all               md5
          - hostnossl all          all          all               reject
          - hostssl   all          all          all               md5
      managed:
        roles:
        - name: instanaadmin
          login: true
          superuser: true
          createdb: true
          createrole: true
          passwordSecret:
            name: instanaadmin
      bootstrap:
        initdb:
          database: instanaadmin
          owner: instanaadmin
          secret:
            name: instanaadmin
      superuserSecret:
        name: instanaadmin
      storage:
        size: 1Gi
      #    storageClass: "Optional"
     
  11. Postgres 클러스터를 배치하십시오.
    kubectl apply -f postgres.yaml -n instana-postgres
     
  12. Postgres (온라인 및 오프라인)의 단계를 완료하십시오.

Postgres 배포 및 검증 (온라인 및 오프라인)

Postgres 인스턴스를 배치하고 데이터 저장소를 작성하려면 다음 단계를 완료하십시오.

  1. 이전에 생성한 비밀번호를 config.yaml 파일에 저장하십시오.

    datastoreConfigs:
      ...
      postgresConfigs:
        - user: instanaadmin
          password: <USER_GENERATED_PASSWORD>
          adminUser: instanaadmin
          adminPassword: <USER_GENERATED_PASSWORD>
      ...
     
  2. postgresql 자원을 작성하십시오.

    kubectl apply -f postgres.yaml --namespace=instana-postgres
     
  3. Postgres 운영자 배포를 확인합니다.

    kubectl get all -n instana-postgres
     

    Postgres 운영자가 성공적으로 배치되면 명령의 결과는 다음과 같습니다.

    NAME                                      READY    STATUS    RESTARTS    AGE
    pod/postgres-1                             1/1     Running     0         100s
    pod/postgres-2                             1/1     Running     0         69s
    pod/postgres-3                             1/1     Running     0         41s
    pod/cnpg-cloudnative-pg-64bbc87958-fqnrl   1/1     Running     0         11m
    
    NAME                           TYPE        CLUSTER-IP       EXTERNAL-IP   PORT
    service/cnpg-webhook-service   ClusterIP   172.30.66.183    <none>        443/TCP
    service/postgres-r             ClusterIP   172.30.163.146   <none>        5432/TCP
    service/postgres-ro            ClusterIP   172.30.226.75    <none>        5432/TCP
    service/postgres-rw            ClusterIP   172.30.235.178   <none>        5432/TCP
    
    NAME                                READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/cnpg-cloudnative-p   1/1     1            1           11m
    
    NAME                                           DESIRED   CURRENT   READY   AGE
    replicaset.apps/cnpg-cloudnative-pg-64bbc87958   1         1         1       11m
     

Zalando 에서 CloudNativePG 으로 데이터 마이그레이션

pg_basebackup 부트스트랩 모드를 사용하여 기존 PostgreSQL 인스턴스 (소스) 의 정확한 실제 상태를 복제하는 새 PostgreSQL 클러스터 (대상) 를 작성할 수 있습니다.

유효한 스트리밍 복제 연결을 통해 그리고 소스 PostgreSQL 인스턴스를 기본 또는 대기 PostgreSQL 서버로 사용하여 라이브 클러스터에서 부트스트랩할 수 있습니다.

클러스터의 ZalandoPostgreSQL 데이터를 부트스트랩 pg_basebackup 모드를 통해 복제 CloudNativePG 클러스터로 마이그레이션하려면 다음을 참조하십시오 데이터를 에서 Zalando 로 마이그레이션 CloudNativePG.