# MongoDB 高可用（副本集）示例
# 说明：MongoDB 没有 Redis Sentinel 组件；副本集即其高可用机制。
apiVersion: v1
kind: Secret
metadata:
  name: mongodb-ha-app-user-password
  namespace: juwan
type: Opaque
stringData:
  password: ChangeMe_ReallyStrongPassword
---
apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
  name: juwan-mongodb-ha
  namespace: juwan
spec:
  members: 3
  type: ReplicaSet
  version: "7.0.12"
  # 生产建议开启持久化（具体 storageClassName 按集群调整）
  statefulSet:
    spec:
      volumeClaimTemplates:
        - metadata:
            name: data-volume
          spec:
            accessModes: ["ReadWriteOnce"]
            resources:
              requests:
                storage: 20Gi
  security:
    authentication:
      modes:
        - SCRAM
  users:
    - name: app-user
      db: admin
      passwordSecretRef:
        name: mongodb-ha-app-user-password
      roles:
        - name: readWrite
          db: appdb
      scramCredentialsSecretName: app-user-scram
  additionalMongodConfig:
    storage.wiredTiger.engineConfig.journalCompressor: zlib
