在 Linux on Power 上创建一个 Postgres 数据存储( ppc64le )
安装 Postgres 操作程序并设置数据存储器。
准备工作
确保已准备好联机和脱机主机以从外部存储库中拉取映像。 此外,请确保添加了正确的 Helm 存储库。
如需更多信息,请参阅 “准备安装数据存储 ”。
Postgres 用于部署的操作系统版本和镜像标签
置顶的 Helm Chart 或操作程序版本需要以下映像。
CNPG Postgres
| 平台 | 操作程序版本 | Helm Chart 版本 | 带有标记的图像 |
|---|---|---|---|
| Linux® on Power® (ppc64le) | v1.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 |
Zalando Postgres
| 平台 | 操作程序版本 | Helm Chart 版本 | 带有标记的图像 |
|---|---|---|---|
| Linux® on Power® (ppc64le) | 1.10.0 | v1.10.1 | artifact-public.instana.io/self-hosted-images/3rd-party/operator/zalando: v1.10.0_v0.1.0 artifact-public.instana.io/self-hosted-images/3rd-party/datastore/zalando: 15.7_v0.1.0 |
在线安装 Postgres
在在线环境中安装 Postgres 操作员。
使用 CloudNativePG 操作符安装 Postgres
请按照以下步骤安装 Postgres 数据存储。
创建
instana-postgres名称空间。kubectl create namespace instana-postgres为
instana-postgres命名空间创建图像拉取秘钥。kubectl create secret docker-registry instana-registry --namespace instana-postgres \ --docker-username=_ \ --docker-password=<download_key> \ --docker-server=artifact-public.instana.io如果您要在 Red Hat® OpenShift® 集群上安装 Postgres ,请从命名空间中确定文件系统组 ID
instana-postgres。 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 开始的 10,1000750000000 个值,因此它指定了从1000750000到 的 ID1000760000范围。 在此示例中,该值1000750000可能被用作文件系统组 ID(UID)。安装 Postgres 操作员。 在以下命令中,将上一步骤中的
<UID from namespace>UID 作为 参数使用: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在 base64 中生成密码。 请记下密码。 你需要稍后将此内容保存到文件
config.yaml中。openssl rand -base64 24 | tr -cd 'a-zA-Z0-9' | head -c32; echo使用上一条命令中获取的密码,创建一个类型为
Secret的资源。kind: Secret apiVersion: v1 metadata: name: instanaadmin type: Opaque stringData: username: instanaadmin password: <user-generate-password>创建 Postgres 密钥。
kubectl apply -f postgres-secret.yaml -n instana-postgres创建一个名为 YAML 的文件,例如
postgres.yaml,其中包含 Postgres 集群的配置。apiVersion: postgresql.cnpg.io/v1 kind: Cluster metadata: name: postgres spec: 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"完成 部署和验证 Postgres (联机和脱机)中的步骤。
使用 Zalando 操作符安装 Postgres
要在线部署 Zalando Postgres 操作员,请完成以下步骤:
如果您使用的是 Red Hat OpenShift 集群,请在部署 Postgres 操作员之前创建安全上下文约束(SCC)。
创建一个名为 YAML 的文件(例如
postgres-scc.yaml),其中包含SCC资源定义。apiVersion: security.openshift.io/v1 kind: SecurityContextConstraints metadata: name: postgres-scc runAsUser: type: MustRunAs uid: 101 seLinuxContext: type: RunAsAny fsGroup: type: RunAsAny allowHostDirVolumePlugin: false allowHostNetwork: true allowHostPorts: true allowPrivilegedContainer: false allowHostIPC: true allowHostPID: true readOnlyRootFilesystem: false users: - system:serviceaccount:instana-postgres:postgres-operator - system:serviceaccount:instana-postgres:postgres-pod - system:serviceaccount:instana-postgres:default创建 SCC 资源。
kubectl apply -f postgres-scc.yaml
安装 Postgres 操作员。
创建
instana-postgres名称空间。kubectl create namespace instana-postgres为
instana-postgres命名空间创建图像拉取秘钥。 在以下命令中,用代理密钥替换<download_key>值。kubectl create secret docker-registry instana-registry --namespace instana-postgres \ --docker-username=_ \ --docker-password=<download_key> \ --docker-server=artifact-public.instana.io创建一个文件,例如
values.yaml,使用 Postgres 配置。configGeneral: kubernetes_use_configmaps: true securityContext: runAsUser: 101 image: registry: artifact-public.instana.io repository: self-hosted-images/3rd-party/operator/zalando tag: v1.10.0_v0.1.0 imagePullSecrets: - name: instana-registry configKubernetes: pod_service_account_definition: | apiVersion: v1 kind: ServiceAccount metadata: name: postgres-pod imagePullSecrets: - name: instana-registry podServiceAccount: name: postgres-pod安装 Postgres 操作员。
helm install postgres-operator instana/postgres-operator --version=v1.10.1 -f values.yaml -n instana-postgres
使用
postgresql资源定义创建文件,例如postgres.yaml。apiVersion: "acid.zalan.do/v1" kind: postgresql metadata: name: postgres spec: patroni: pg_hba: - local all all trust - host all all 0.0.0.0/0 trust - local replication standby trust - hostssl replication standby all trust - hostnossl all all all reject - hostssl all all all trust dockerImage: artifact-public.instana.io/self-hosted-images/3rd-party/datastore/zalando:15.7_v0.1.0 teamId: instana numberOfInstances: 3 postgresql: version: "15" parameters: # Expert section shared_buffers: "32MB" volume: size: 10Gi # Uncomment the following line to specify your own storage class, otherwise use the default. # storageClass: <REPLACE>- 完成 部署和验证 Postgres (联机和脱机)中的步骤。
离线安装 Postgres
在脱机环境中安装 Postgres 操作员。
使用 CloudNative PG 操作员离线安装 Postgres
如果在 准备安装时尚未从外部注册表中拉取 Postgres 映像,那么可以立即拉取这些映像。 在防御主机上运行以下命令。 然后,将这些图像复制到位于物理隔离环境中的 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 主机上完成以下步骤。
将映像重新标记到内部映像注册表。
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将映像推送到防御主机上的内部映像注册表。
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创建
instana-postgres名称空间。kubectl create namespace instana-postgres可选:如果内部图像注册表需要身份验证,请创建图像拉取密钥。
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>如果您要在 Red Hat® OpenShift® 集群上安装 Postgres ,请从命名空间中确定文件系统组 ID
instana-postgres。 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 开始的 10,1000750000000 个值,因此它指定了从1000750000到 的 ID1000760000范围。 在此示例中,该值1000750000可能被用作文件系统组 ID(UID)。安装 Postgres 操作员。 在以下命令中,请将 <download_key> 替换为您自己的代理密钥。 如果您为内部注册表创建了镜像拉取密钥,请
--docker-server=<internal-image-registry>:<internal-image-registry-port>在以下命令中添加。Red Hat OpenShift 集群
在以下命令中,
<UID from namespace>请使用上一步骤生成的 UID:helm install cnpg cloudnative-pg-1.28.0.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-postgresKubernetes 集群
helm install cnpg cloudnative-pg-operator --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
在 base64 中生成密码。 请记下密码。 你需要稍后将此内容保存到文件
config.yaml中。openssl rand -base64 24 | tr -cd 'a-zA-Z0-9' | head -c32; echo使用上一条命令中获取的密码,创建一个类型为
Secret的资源。kind: Secret apiVersion: v1 metadata: name: instanaadmin type: Opaque stringData: username: instanaadmin password: <user-generate-password>创建 Postgres 密钥。
kubectl apply -f postgres-secret.yaml -n instana-postgres创建一个名为 YAML 的文件,例如
postgres.yaml,其中包含 Postgres 集群的配置。apiVersion: postgresql.cnpg.io/v1 kind: Cluster metadata: name: postgres spec: 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"- 完成 部署和验证 Postgres (联机和脱机)中的步骤。
使用 Zalando 操作符离线安装 Postgres
如果您使用的是 Red Hat OpenShift 集群,请在部署 Postgres 操作员之前创建安全上下文约束。
创建一个名为 YAML 的文件(例如
postgres-scc.yaml),其中包含SCC资源定义。apiVersion: security.openshift.io/v1 kind: SecurityContextConstraints metadata: name: postgres-scc runAsUser: type: MustRunAs uid: 101 seLinuxContext: type: RunAsAny fsGroup: type: RunAsAny allowHostDirVolumePlugin: false allowHostNetwork: true allowHostPorts: true allowPrivilegedContainer: false allowHostIPC: true allowHostPID: true readOnlyRootFilesystem: false users: - system:serviceaccount:instana-postgres:postgres-operator - system:serviceaccount:instana-postgres:postgres-pod - system:serviceaccount:instana-postgres:default创建 SCC 资源。
kubectl apply -f postgres-scc.yaml
然后,继续安装 Postgres 操作程序。
如果在 准备安装时尚未从外部注册表中拉取 Postgres 映像,那么可以立即拉取这些映像。 在防御主机上运行以下命令。 然后,将这些图像复制到位于物理隔离环境中的 Instana 主机上。
docker pull artifact-public.instana.io/self-hosted-images/3rd-party/operator/zalando:v1.10.0_v0.1.0
docker pull artifact-public.instana.io/self-hosted-images/3rd-party/datastore/zalando:15.7_v0.1.0
请在您的 Instana 主机上完成以下步骤。
将映像重新标记到内部映像注册表。
docker tag artifact-public.instana.io/self-hosted-images/3rd-party/operator/zalando:v1.10.0_v0.1.0 <internal-image-registry>/self-hosted-images/3rd-party/operator/zalando:v1.10.0_v0.1.0 docker tag artifact-public.instana.io/self-hosted-images/3rd-party/datastore/zalando:15.7_v0.1.0 <internal-image-registry>/self-hosted-images/3rd-party/datastore/zalando:15.7_v0.1.0将映像推送到防御主机上的内部映像注册表。
docker push <internal-image-registry>/self-hosted-images/3rd-party/operator/zalando:v1.10.0_v0.1.0 docker push <internal-image-registry>/self-hosted-images/3rd-party/datastore/zalando:15.7_v0.1.0创建一个文件,例如
values.yaml,使用 Postgres 配置。configGeneral: kubernetes_use_configmaps: true securityContext: runAsUser: 101 image: registry: <internal-image-registry> repository: self-hosted-images/3rd-party/operator/zalando tag: v1.10.0_v0.1.0 imagePullSecrets: - name: instana-registry configKubernetes: pod_service_account_definition: | apiVersion: v1 kind: ServiceAccount metadata: name: postgres-pod imagePullSecrets: - name: instana-registry podServiceAccount: name: postgres-pod创建
instana-postgres名称空间。kubectl create namespace instana-postgres可选:如果内部图像注册表需要身份验证,请创建图像拉取密钥。
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>安装 Postgres 操作员。 如果您在上一步中创建了图像拉取秘密,请在以下命令中添加
--set imagePullSecrets[0].name="<internal-image-registry-pull-secret>"。helm install postgres-operator postgres-operator-ppc64le-1.10.0.tgz --version=1.10.0 --set configGeneral.kubernetes_use_configmaps=true --set securityContext.runAsUser=101 --namespace=instana-postgres --set image.registry=<internal-image-registry> --set image.repository=ppc64le-oss/postgres-operator-ppc64le --set image.tag=v1.10.0_v0.1.0使用
postgresql资源定义创建文件,例如postgres.yaml。apiVersion: "acid.zalan.do/v1" kind: postgresql metadata: name: postgres spec: patroni: pg_hba: - local all all trust - host all all 0.0.0.0/0 trust - local replication standby trust - hostssl replication standby all trust - hostnossl all all all reject - hostssl all all all trust dockerImage: <internal-image-registry>/self-hosted-images/3rd-party/datastore/zalando:15.7_v0.1.0 teamId: instana numberOfInstances: 3 postgresql: version: "15" parameters: # Expert section shared_buffers: "32MB" volume: size: 10Gi # Uncomment the line below to specify your own storage class, otherwise use the default. # storageClass: <REPLACE>完成 部署和验证 Postgres (联机和脱机)中的步骤。
部署和验证 Postgres (在线和离线)
完成以下步骤以部署 Postgres 实例并创建数据存储器。
创建
postgresql资源。kubectl apply -f postgres.yaml --namespace=instana-postgres如果您使用了 CNPG 运算符,请执行以下步骤:
将您之前生成的密码保存在 文件
config.yaml中。datastoreConfigs: ... postgresConfigs: - user: instanaadmin password: <USER_GENERATED_PASSWORD> adminUser: instanaadmin adminPassword: <USER_GENERATED_PASSWORD> ...
如果您使用了 Zalando 运算符,请执行以下步骤:
检索 Zalando 用户的自动生成密码。 默认情况下, Zalando 会创建一个
postgres用户,并为其设置随机生成的密码。kubectl get secret postgres.postgres.credentials.postgresql.acid.zalan.do -n instana-postgres --template='{{index .data.password | base64decode}}' && echo将检索到的密码存储在
config.yaml文件中。- 请将 `<RETRIEVED_FROM_SECRET>` 变量值替换为上一步中获取的密码。
- 请将 替换
<username in the Postgres data store>为 Zalando 的用户名。
datastoreConfigs: ... postgresConfigs: - user: <username in the Postgres data store> password: <RETRIEVED_FROM_SECRET> adminUser: <username in the Postgres data store> adminPassword: <RETRIEVED_FROM_SECRET> ...
验证 Postgres 操作员部署。
kubectl get all -n instana-postgres如果成功部署了 Postgres 操作符,则命令结果如下:
以下输出是 Zalando 运算符的一个示例:
NAME READY STATUS RESTARTS AGE pod/postgres-0 1/1 Running 0 100s pod/postgres-1 1/1 Running 0 69s pod/postgres-2 1/1 Running 0 41s pod/postgres-operator-766455c58c-ntmpf 1/1 Running 0 11m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/postgres ClusterIP 192.168.1.107 <none> 5432/TCP 101s service/postgres-operator ClusterIP 192.168.1.35 <none> 8080/TCP 11m service/postgres-repl ClusterIP 192.168.1.72 <none> 5432/TCP 101s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/postgres-operator 1/1 1 1 11m NAME DESIRED CURRENT READY AGE replicaset.apps/postgres-operator-766455c58c 1 1 1 11m NAME READY AGE statefulset.apps/postgres 3/3 103s NAME IMAGE CLUSTER-LABEL SERVICE-ACCOUNT MIN-INSTANCES AGE operatorconfiguration.acid.zalan.do/postgres-operator ghcr.io/zalando/spilo-15:3.0-p1 cluster-name postgres-pod -1 11m NAME TEAM VERSION PODS VOLUME CPU-REQUEST MEMORY-REQUEST AGE STATUS postgresql.acid.zalan.do/postgres instana 15 3 10Gi 500m 2Gi 106s Running以下输出是CloudNativePG操作员:
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 服务器。
若要通过引导 pg_basebackup 模式将数据从 Zalando PostgreSQL 集群迁移到 CloudNativePG 副本集群,请参阅 《将数据从 Zalando 迁移到 CloudNativePG 》。