AlloyDB Omni on Kubernetes 配置示例

本页面提供了在 Kubernetes 上部署和管理 AlloyDB Omni 的 YAML 配置示例。

DBCluster 核心和操作系统配置

探索基本集群配置和自定义操作系统设置。

最小 DBCluster

用于部署 AlloyDB Omni DBCluster 的基本配置。

查看最简 DBCluster YAML 配置

# This is a minimal DBCluster spec. See v1_dbcluster_full.yaml for more configurations.
apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

完整 DBCluster

显示可用设置的全面设置。

查看完整的 DBCluster YAML 配置

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  allowExternalIncomingTraffic: true
  availability:
    healthcheckPeriodSeconds: 30 # default is 30secs, new feature in 1.2.0. minimum value is 1 and the maximum value is 86400
    autoFailoverTriggerThreshold: 3 # after which failover is triggered
    autoHealTriggerThreshold: 3
    enableAutoFailover: true
    enableAutoHeal: true
    enableStandbyAsReadReplica: true
    numberOfStandbys: 1
  controlPlaneAgentsVersion: 1.6.0
  databaseVersion: "18.1.0"
  databaseImageOSType: UBI9
  isDeleted: false
  mode: ""
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    allowExternalIncomingTrafficToInstance: false
    auditLogTarget: {}
    dbLoadBalancerOptions:
      annotations:
        networking.gke.io/load-balancer-type: "internal"
        lb.company.com/enabled: "true"
      gcp: {}
    features:
      columnarSpillToDisk:
        cacheSize: 50Gi
      ultraFastCache:
        cacheSize: 100Gi
        # either generic volume or local volume
        genericVolume:
          storageClass: "local-storage"
        # localVolume:
        #   path: "/mnt/disks/raid/0"
        #   nodeAffinity:
        #     required:
        #       nodeSelectorTerms:
        #         - matchExpressions:
        #           - key: "cloud.google.com/gke-local-nvme-ssd"
        #           operator: "In"
        #           values:
        #           - "true"
      googleMLExtension:
        config:
          vertexAIKeyRef: vertex-ai-key-alloydb # secret used to enable AlloyDB Omni to access AlloyDB AI features
          vertexAIRegion: us-central1 # default
    resources:
      cpu: "12"
      disks:
      - name: DataDisk
        size: 1000Gi
        storageClass: px-ceph
      - name: LogDisk
        size: 10Gi
        storageClass: px-ceph
      - name: ObsDisk
        size: 4Gi
        storageClass: px-ceph
      - name: BackupDisk
        size: 10Gi
        storageClass: px-ceph
      memory: 100Gi
    walArchiveSetting:
      location: wal/log  # enable WAL archiving and archive logs to /archive/wal/log
    sidecarRef:
      name: cv-sidecar-config # provide a sidecar config that is referenced here
    parameters:
      google_columnar_engine.enabled: "on"
      google_columnar_engine.memory_size_in_mb: "256"
      google_storage.parallel_log_replay_enabled: 'off'
      google_pg_auth.enable_auth: 'false'
      shared_preload_libraries: "pg_cron,pg_bigm3"
      archive_mode: 'on'
      archive_timeout: '300'
      work_mem: '4MB'
# operator default values
# shared_preload_libraries='g_stats,google_columnar_engine,google_db_advisor,google_job_scheduler,pg_stat_statements,pglogical,pgaudit'
      log_rotation_age: "2" # rotate every two minutes. Set to "0" to disable age-based rotation. If unset, no age-based rotation
      log_rotation_size: "400000" # rotate every 400,000kb. set to "0" to disable size-based rotation. If unset, rotate every 200,000kb
    schedulingconfig:
      tolerations:
        - effect: NoSchedule
          key: alloydb-node-type
          operator: Exists
      nodeaffinity:
        # requiredDuringSchedulingIgnoredDuringExecution: strong condition, not being able to meet this would stop pods being scheduled
        preferredDuringSchedulingIgnoredDuringExecution:
          nodeSelectorTerms:
          - matchExpressions:
            - key: alloydb-node-type
              operator: In
              values:
              - database
      podAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 1
          podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - store
            topologyKey: "kubernetes.io/hostname"
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 1
          podAffinityTerm:
            labelSelector:
              matchExpressions:
              - key: security
                operator: In
                values:
                - S1
            topologyKey: "topology.kubernetes.io/zone"
    services:
      Logging: true
      Monitoring: true
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: "example-local-pv"
spec:
  capacity:
    storage: 375Gi
  accessModes:
  - "ReadWriteOnce"
  persistentVolumeReclaimPolicy: "Retain"
  storageClassName: "local-storage"
  local:
    path: "/mnt/disks/raid/0"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
      # following example key applies to an operator that is deployed on
      # Google Cloud and uses the local ssd option
        - key: "cloud.google.com/gke-local-nvme-ssd"
          operator: "In"
          values:
          - "true"
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBInstance
metadata:
  name: dbcluster-sample-rp-1
spec:
  instanceType: ReadPool
  dbcParent:
    name: dbcluster-sample
  nodeCount: 2
  resources:
    memory: 6Gi
    cpu: 2
    disks:
    - name: DataDisk
      size: 15Gi
  schedulingconfig:
    tolerations:
    - key: "node-role.kubernetes.io/control-plane"
      operator: "Exists"
      effect: "NoSchedule"
    nodeaffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
    podAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: app
              operator: In
              values:
              - store
          topologyKey: "kubernetes.io/hostname"
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: security
              operator: In
              values:
              - S1
          topologyKey: "topology.kubernetes.io/zone"

自定义参数

配置自定义 PostgreSQL 参数。

查看自定义参数 YAML 配置

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi
    parameters:
      google_columnar_engine.enabled: "on"
      google_columnar_engine.memory_size_in_mb: "256"

基于 Debian 的部署

指定 Debian 操作系统映像基础。

查看基于 Debian 的部署的 YAML 配置

# This is a minimal DBCluster spec. See v1_dbcluster_full.yaml for more configurations.
apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  databaseImageOSType: Debian
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

基于 UBI9 的部署

指定 Red Hat 通用基础映像 9 (UBI 9) 作为基础。

查看基于 UBI9 的部署的 YAML 配置

# This is a minimal DBCluster spec. See v1_dbcluster_full.yaml for more configurations.
apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  databaseImageOSType: UBI9
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

Pod 调度选项

配置节点亲和性、容忍和调度行为。

查看 Pod 调度选项 YAML 配置

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  availability:
    numberOfStandbys: 1
    enableStandbyAsReadReplica: true
  primarySpec:
    schedulingconfig:
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: "topology.kubernetes.io/zone"
          whenUnsatisfiable: DoNotSchedule
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

高可用性和扩缩

分配流量并确保零停机时间或尽可能缩短停机时间。

高可用性 DBCluster

设置多个副本以实现高可用性。

查看高可用性 DBCluster YAML 配置

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  availability:
    numberOfStandbys: 1
    enableStandbyAsReadReplica: true
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

使用负载平衡器的 DBCluster

使用服务负载均衡公开读/写端点。

查看具有负载平衡器 YAML 配置的 DBCluster

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi
    dbLoadBalancerOptions:
      annotations:
        # Creates internal LoadBalancer in GKE.
        networking.gke.io/load-balancer-type: "internal"
  allowExternalIncomingTraffic: true

读取池实例

添加只读池实例以扩缩读取操作。

查看读取池实例 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBInstance
metadata:
  name: dbcluster-sample-rp-1
spec:
  instanceType: ReadPool
  dbcParent:
    name: dbcluster-sample
  nodeCount: 2
  resources:
    memory: 6Gi
    cpu: 2
    disks:
    - name: DataDisk
      size: 15Gi
  schedulingconfig:
    tolerations:
    - key: "node-role.kubernetes.io/control-plane"
      operator: "Exists"
      effect: "NoSchedule"
    nodeaffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
    podAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: app
              operator: In
              values:
              - store
          topologyKey: "kubernetes.io/hostname"
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: security
              operator: In
              values:
              - S1
          topologyKey: "topology.kubernetes.io/zone"

安全和密文管理

保护密钥、证书和集群凭据。

证书颁发机构

配置自定义 TLS 证书签发者。

查看证书签发机构 YAML 配置

# This is a minimal DBCluster spec. See v1_dbcluster_full.yaml for more configurations.
apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  primarySpec:
    tls:
      dataPlaneCertIssuer:
        name: data-plane-issuer
        kind: ClusterIssuer
      controlPlaneAgentsCertIssuer:
        name: control-plane-issuer
        kind: ClusterIssuer
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

保险柜集成

使用 HashiCorp Vault 检索并安全地存储 Secret。

查看 Vault 集成 YAML 配置

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
#  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
  dbcluster-sample: "ZGhhcm1hbGluZ2FtCg=="

---
apiVersion: v1
kind: Secret
metadata:
  name: alloydbadmin-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM="
#  dbcluster-sample: "ZGhhcm1hbGluZ2FtCg=="
#  dbcluster-sample: "YXJhdmluZGFuCg=="
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
#  availability:
#    numberOfStandbys: 1
#    enableStandbyAsReadReplica: true
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    agentPassword:
      passwordRef:
        name: alloydbadmin-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

主备复制

配置上游(主)数据库和下游(备用)数据库之间的复制。

上游(主)配置

配置主节点以发布更改。

查看上游(主要)配置 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Replication
metadata:
  name: replication-upstream-sample
spec:
  dbcluster:
    name: dbcluster-sample
  upstream: {}

下游(备用)配置

配置复制目标以从主节点同步。

查看下游(备用)配置 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Replication
metadata:
  name: replication-downstream-sample
spec:
  dbcluster:
    name: dbcluster-sample
  downstream:
    host: "10.10.10.10"
    port: 5432
    username: alloydbreplica
    password:
      name: "ha-rep-pw-dbcluster-sample"
    replicationSlotName: "dbcluster_sample_replication_upstream_sample"
    control: setup
    # to promote downstream, change control to promote

备份、恢复和克隆

管理灾难恢复、按需数据复制和时间表。

已安排的备份方案

安排完整备份和增量备份。

查看已安排的备份方案 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: BackupPlan
metadata:
  name: backupplan1
spec:
  dbclusterRef: dbcluster-sample
  backupRetainDays: 14
  paused: false
  backupSchedules:
    # Full backup at 00:00 on every Sunday.
    full: "0 0 * * 0"
    # Incremental backup at 21:00 every day.
    incremental: "0 21 * * *"

备份到 Google Cloud Storage (GCS)

将备份安全地存储在 Google Cloud Storage 存储桶中。

查看备份到 Google Cloud Storage (GCS) 的 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: BackupPlan
metadata:
  name: backupplan1
  namespace: db
spec:
  dbclusterRef: dbcluster-sample
  backupRetainDays: 14
  paused: false
  backupSchedules:
    # Full backup at 00:00 on every Sunday.
    full: "0 0 * * 0"
    # Incremental backup at 21:00 every day.
    incremental: "0 21 * * *"
  backupLocation:
    type: GCS
    gcsOptions:
      bucket: dbcluster-sample-backups
      key: /backup
      # You can optionally provide a key for accessing your GCS bucket.
      # The key.json needs to be base64 encoded and stored in the given secret under data[key.json].
      # Or comment out below, which will then use the GKE cluster service account
      # to access the GCS bucket (you need to make sure the service account has
      # the right permission to R/W the GCS bucket).
      secretRef:
        name: gcs-key
        namespace: db
---
apiVersion: v1
kind: Secret
metadata:
  name: gcs-key
  namespace: db
data:
  key.json: |
    <paste your base64 encoded GCS key json here with 4 spaces for indentation>

备份到 Amazon S3

将备份存储在与 Amazon S3 兼容的存储桶中。

查看“备份到 Amazon S3”YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: BackupPlan
metadata:
  name: backupplan1
  namespace: db
spec:
  dbclusterRef: dbcluster-sample
  backupRetainDays: 14
  paused: false
  backupSchedules:
    # Full backup at 00:00 on every Sunday.
    full: "0 0 * * 0"
    # Incremental backup at 21:00 every day.
    incremental: "0 21 * * *"
  backupLocation:
    type: S3
    s3Options:
      bucket: dbcluster-sample-backups-s3
      key: /backup
      region: "us-east-1"
      endpoint: "https://s3.storage.com"
      secretRef:
        name: s3-access-secret
        namespace: db
      # You can optionally provide the cert to be used to connect to the S3 with TLS.
      # If not provided, TLS verification will be skipped.
      certRef:
        name: server-tls
        namespace: server-ns
---
apiVersion: v1
kind: Secret
metadata:
  namespace: db
  name: "s3-access-secret"
type: Opaque
data:
  # Update the following with your S3 access keys.
  access-key-id: "Q2hhbmdlTWUxMjM=" # access-key-id is ChangeMe123
  access-key:  "Q2hhbmdlTWUxMjM=" # access-key is ChangeMe123

按需手动备份

创建单个手动备份。

查看按需手动备份 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Backup
metadata:
  name: backup1
spec:
  dbclusterRef: dbcluster-sample
  backupPlanRef: backupplan1
  manual: true
  physicalBackupSpec:
    backupType: full

使用备份进行恢复

从存储的备份恢复或创建集群。

查看“从备份恢复”YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Restore
metadata:
  name: restore1
spec:
  sourceDBCluster: dbcluster-sample
  backup: backup1

数据库克隆

克隆标准 DBCluster。

查看数据库克隆 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Restore
metadata:
  name: clone1
spec:
  sourceDBCluster: dbcluster-sample
  pointInTime: "2024-02-23T19:59:43Z"
  clonedDBClusterConfig:
    dbclusterName: new-dbcluster-sample

操作和故障切换

执行安全的拓扑转换。

受控切换

通过计划的切换(不会丢失任何数据)来提升次要副本。

查看受控切换 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Switchover
metadata:
  name: switchover-sample
spec:
  dbclusterRef: dbcluster-sample

灾难恢复故障转移

处理计划外的灾难恢复或故障切换场景。

查看灾难恢复故障转移 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Failover
metadata:
  name: failover-sample
spec:
  dbclusterRef: dbcluster-sample

连接池 (PgBouncer)

使用 PgBouncer 设置数据库代理层。

基本 PgBouncer

部署标准 PgBouncer 伴随容器。

查看基本的 PgBouncer YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: PgBouncer
metadata:
  name: mypgbouncer
spec:
  allowSuperUserAccess: true
  dbclusterRef: dbcluster-sample
  replicaCount: 1
  parameters:
    pool_mode: transaction
    ignore_startup_parameters: extra_float_digits
    default_pool_size: "15"
    max_client_conn: "800"
    max_db_connections: "160"
  podSpec:
    resources:
      memory: 1Gi
      cpu: 1
    image: "gcr.io/alloydb-omni-staging/g-pgbouncer:1.4.0"
  serviceOptions:
    type: "ClusterIP"

完整 PgBouncer

配置高级调优、自定义授权和连接池替换。

查看完整的 PgBouncer YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: PgBouncer
metadata:
  name: mypgbouncer
spec:
  allowSuperUserAccess: true
  dbclusterRef: dbcluster-sample
  replicaCount: 2
  parameters:
    pool_mode: transaction
    ignore_startup_parameters: extra_float_digits
    default_pool_size: "15"
    max_client_conn: "800"
    max_db_connections: "160"
  podSpec:
    resources:
      memory: 1Gi
      cpu: 1
    image: "gcr.io/alloydb-omni-staging/g-pgbouncer:1.4.0"
    schedulingconfig:
      nodeaffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
          nodeSelectorTerms:
          - matchExpressions:
            - key: nodetype
              operator: In
              values:
              - pgbouncer
  serviceOptions:
    type: "LoadBalancer"
    loadBalancerSourceRanges:
    - "11.0.0.0/8"
    annotations:
      networking.gke.io/load-balancer-type: "internal"

集成服务和 Sidecar

通过机器学习、可观测性和自定义代理容器来增强数据库功能。

具有 ML 代理的 DBCluster

集成本地机器学习或 Vertex AI 代理边车。

查看具有 ML 代理 YAML 配置的 DBCluster

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: v1
kind: Secret
metadata:
  name: vertex-ai-key-alloydb
type: Opaque
data:
  private-key.json: ""
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  primarySpec:
    features:
      googleMLExtension:
        enabled: true
        config:
          vertexAIKeyRef: vertex-ai-key-alloydb
          vertexAIRegion: us-central1
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi

可观测性配置

配置集群指标,包括用于收集用户定义的数据库和特定于应用的指标的自定义 SQL 查询。

查看可观测性配置 YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: ObservabilityConfig
metadata:
  name: my-custom-metrics
spec:
  dbClusterRefs:
    - dbcluster-sample
  customMetrics:
    resourceLimits:
      workMemory: "4MB"
      maxParallelWorkers: 0 #limits to 1 CPU core
    definitions:
      - metricGroup: querygroup_postgres
        database: "postgres"
        query: |
          SELECT
            datname,
            pg_database_size(datname) as db_size_bytes,
            (SELECT count(*) FROM pg_stat_activity WHERE datname = d.datname) as active_connections
          FROM pg_database d
          WHERE datname = 'postgres'
        metrics:
          - name: datname
            desc: "Database name"
            usage: label
          - name: db_size_bytes
            desc: "Size of the current database in bytes"
            usage: gauge
          - name: active_connections
            desc: "Number of active connections to the database"
            usage: gauge
      - metricGroup: querygroup_alloydbadmin
        database: "alloydbadmin"
        query: |
          SELECT count(*) as healthcheck_count
          FROM healthcheck
        metrics:
          - name: healthcheck_count
            desc: "Number of rows in healthcheck table"
            usage: gauge

自定义 Sidecar

将标准支持 Sidecar 注入到集群 Pod 中。

查看自定义 Sidecar YAML 配置

apiVersion: alloydbomni.dbadmin.goog/v1
kind: Sidecar
metadata:
  name: sidecar-sample
spec:
  sidecars:
  - image: busybox
    name: sidecar-sample
    volumeMounts:
      - name: obsdisk
        mountPath: /logs
    command: ["/bin/sh"]
    args:
    - -c
    - |
      while [ true ]
      do
      date
      set -x
      ls -lh /logs/diagnostic
      set +x
      done

具有自定义边车的 DBCluster

配置包含标准支持边车的 base DBCluster。

查看具有自定义 Sidecar YAML 配置的 DBCluster

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi
    sidecarRef:
        name: sidecar-sample

Commvault 备份 Sidecar

将 Commvault 代理配置指定为辅助边车。

查看 Commvault Backup Sidecar YAML 配置

# Source: commvault/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cvconfigmap
data:
  CV_MASVCNAME: commvault-prod
  CV_CSHOSTNAME: "tipcs.idcprodcert.loc"
  CV_CSIPADDR: "123.123.123.123"
  CV_CSCLIENTNAME: "tipcs"
  CV_CLIENT_ROLE: "postgres"
---
apiVersion: v1
kind: Secret
metadata:
  name: commcell-secret
data:
  CV_COMMCELL_USER: Y3ZhZG1pbgo= # commcell username is cvadmin
  CV_COMMCELL_PWD: Y3ZwYXNzd29yZAo= # commcell password is cvpassword
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: Sidecar
metadata:
  name: cv-sidecar-config
  annotations:
    alloydbomni.dbadmin.goog/sidecar: commvault
spec:
  sidecars:
  - name: "commvault-pgsqlagent"
    image: "commvault/accessnode:11.32.42"
    lifecycle:
      preStop:
        exec:
          command: [ "/bin/sh", "-c" , "cp /opt/commvault/Base/FwConfig* /etc/CommVaultRegistry/Galaxy/FwConfig/" ]
    envFrom:
    - configMapRef:
        name: cvconfigmap
    volumeMounts:
    - name: logdisk
      mountPath: /archive/
    - name: tmp-socket
      mountPath: /tmp
    - name: commvault-env-store2
      mountPath: /opt/cvdocker_env
      readOnly: true
    - name: backupdisk
      mountPath: /etc/CommVaultRegistry
      subPath: Registry
    - name: backupdisk
      mountPath: /var/log/commvault/Log_Files
      subPath: Log_Files
    - name: backupdisk
      mountPath: /opt/commvault/MediaAgent/IndexCache
      subPath: IndexCache
    - name: backupdisk
      mountPath: /opt/commvault/iDataAgent/jobResults
      subPath: jobResults
    - name: backupdisk
      mountPath: /opt/commvault/Base/certificates
      subPath: certificates
    - name: datadisk
      mountPath: /mnt/disks/pgsql
    - name: commcell-secret
      mountPath: /opt/commcell_secret
    ports:
    - name: cvdport
      containerPort: 8400
    securityContext:
      runAsUser: 0
  additionalVolumes:
  - name: commcell-secret
    secret:
      secretName: commcell-secret
  - name: commvault-env-store2
    configMap:
      name: cvconfigmap

具有 Commvault Sidecar 的 DBCluster

配置指定 Commvault 代理辅助边车容器的 DBCluster。

查看具有 Commvault Sidecar 的 DBCluster YAML 配置

apiVersion: v1
kind: Secret
metadata:
  name: db-pw-dbcluster-sample
type: Opaque
data:
  dbcluster-sample: "Q2hhbmdlTWUxMjM=" # Password is ChangeMe123
---
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: dbcluster-sample
spec:
  databaseVersion: "18.1.0"
  primarySpec:
    adminUser:
      passwordRef:
        name: db-pw-dbcluster-sample
    resources:
      memory: 5Gi
      cpu: 1
      disks:
      - name: DataDisk
        size: 10Gi
      - name: LogDisk
        size: 10Gi
    walArchiveSetting:
      location: wal/log  # enable WAL archiving and archive logs to /archive/wal/log
    sidecarRef:
        name: cv-sidecar-config