mongodb-operator

by Keiailab Co.,Ltd.

Helm chartv1.16.18App 1.16.18MITVerified publisher

A Kubernetes Operator for MongoDB — ReplicaSets, Sharded Clusters with auto scale-out, S3/PVC Backup, TLS, and LDAP. MIT licensed.

About this chart

MongoDB Operator Helm Chart

A Kubernetes Operator for deploying and managing MongoDB ReplicaSets and Sharded Clusters.

Design assets

AssetURLUsage
Centered service symbolhttps://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/symbol.pngArtifact Hub package icon and screenshot
Keiailab base symbolhttps://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/base-symbol.pngSource reference for the outer rotating-arrow mark
Repository wordmarkhttps://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/logo.pngProject pages and docs cards
Social coverhttps://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/cover.pngSocial cards and launch posts
Branding guidehttps://github.com/KeiaiLab/mongodb-operator/blob/main/docs/BRANDING.mdGitHub visual usage rules

Features

  • MongoDB ReplicaSet: Deploy highly available 3+ member replica sets
  • Sharded Cluster: Deploy distributed clusters with config servers, shards, and mongos routers
  • TLS Encryption: Automatic TLS with cert-manager integration
  • Authentication: SCRAM-SHA-256 authentication with keyfile support
  • Monitoring: Prometheus metrics with ServiceMonitor support
  • Backup/Restore: Automated backups to S3 or PVC storage
  • Auto-scaling: HPA support for Mongos routers

Prerequisites

  • Kubernetes 1.26+
  • Helm 3.8+
  • kubectl configured to communicate with your cluster

Optional Dependencies

  • cert-manager for TLS certificate management
  • Prometheus Operator for metrics collection
  • S3-compatible storage for backups (e.g., AWS S3, MinIO, Ceph ObjectStore)

Installation

Add the Helm Repository

helm repo add mongodb-operator https://keiailab.github.io/mongodb-operator
helm repo update

Install the Chart

helm install mongodb-operator mongodb-operator/mongodb-operator \
  --namespace mongodb-operator-system \
  --create-namespace

Install with Custom Values

helm install mongodb-operator mongodb-operator/mongodb-operator \
  --namespace mongodb-operator-system \
  --create-namespace \
  --set replicaCount=1 \
  --set metrics.serviceMonitor.enabled=true

Configuration

See values.yaml for the full list of configurable parameters.

Common Parameters

ParameterDescriptionDefault
replicaCountNumber of operator replicas1
image.repositoryOperator image repositorykeiailab/mongodb-operator
image.tagOperator image tagChart appVersion
image.pullPolicyImage pull policyIfNotPresent

RBAC Parameters

ParameterDescriptionDefault
serviceAccount.createCreate service accounttrue
rbac.createCreate RBAC resourcestrue
rbac.clusterScopeUse ClusterRoletrue

Metrics Parameters

ParameterDescriptionDefault
metrics.enabledEnable metrics endpointtrue
metrics.secureEnable HTTPS for metricstrue
metrics.serviceMonitor.enabledCreate ServiceMonitorfalse
metrics.serviceMonitor.intervalScrape interval30s

Resource Parameters

ParameterDescriptionDefault
resources.requests.cpuCPU request100m
resources.requests.memoryMemory request128Mi
resources.limits.cpuCPU limit500m
resources.limits.memoryMemory limit512Mi

Usage

Create a MongoDB ReplicaSet

apiVersion: mongodb.keiailab.com/v1alpha1
kind: MongoDB
metadata:
  name: my-mongodb
  namespace: database
spec:
  members: 3
  version:
    version: "9.0.2"
  storage:
    storageClassName: standard
    size: 10Gi
  auth:
    mechanism: SCRAM-SHA-256
    adminCredentialsSecretRef:
      name: mongodb-admin
  monitoring:
    enabled: true
  tls:
    enabled: true
    certManager:
      issuerRef:
        name: letsencrypt
        kind: ClusterIssuer

Create a Sharded Cluster

apiVersion: mongodb.keiailab.com/v1alpha1
kind: MongoDBSharded
metadata:
  name: my-sharded
  namespace: database
spec:
  version:
    version: "9.0.2"
  configServer:
    members: 3
    storage:
      size: 5Gi
  shards:
    count: 3
    membersPerShard: 3
    storage:
      size: 50Gi
  mongos:
    replicas: 2
    service:
      type: LoadBalancer
    autoScaling:
      enabled: true
      minReplicas: 2
      maxReplicas: 10

Create a Backup

apiVersion: mongodb.keiailab.com/v1alpha1
kind: MongoDBBackup
metadata:
  name: my-backup
  namespace: database
spec:
  clusterRef:
    name: my-mongodb
    kind: MongoDB
  type: full
  compression: true
  compressionType: zstd
  storage:
    type: s3
    s3:
      bucket: mongodb-backups
      endpoint: https://s3.amazonaws.com
      credentialsRef:
        name: s3-credentials

Custom Resource Definitions

The operator manages the following CRDs:

CRDShort NameDescription
MongoDBmdbMongoDB ReplicaSet
MongoDBShardedmdbshMongoDB Sharded Cluster
MongoDBBackupmdbbackupBackup configuration

List MongoDB Resources

kubectl get mdb,mdbsh,mdbbackup -A

Uninstallation

helm uninstall mongodb-operator -n mongodb-operator-system

Note: CRDs are not removed by default. To remove CRDs:

kubectl delete crd mongodbs.mongodb.keiailab.com
kubectl delete crd mongodbshardeds.mongodb.keiailab.com
kubectl delete crd mongodbbackups.mongodb.keiailab.com

Upgrading

helm repo update
helm upgrade mongodb-operator mongodb-operator/mongodb-operator \
  --namespace mongodb-operator-system

Troubleshooting

Check Operator Logs

kubectl logs -n mongodb-operator-system -l app.kubernetes.io/name=mongodb-operator -f

Check MongoDB Status

kubectl describe mdb my-mongodb -n database

Check Events

kubectl get events -n database --sort-by='.lastTimestamp'

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

Support

Secure metrics scraping with Prometheus

When metrics.secure: true the operator exposes /metrics over HTTPS behind kube-rbac-proxy (or the controller-runtime native authenticated handler). For Prometheus to scrape it, the ServiceMonitor must present a bearer token and the Prometheus ServiceAccount must be allowed to invoke a TokenReview.

Minimal setup with kube-prometheus-stack

metrics:
  enabled: true
  secure: true
  serviceMonitor:
    enabled: true
    bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
    tlsConfig:
      insecureSkipVerify: true   # or pin CA via caFile / ca.configMap

Grant the Prometheus ServiceAccount system:auth-delegator so kube-rbac-proxy's TokenReview succeeds:

kubectl create clusterrolebinding prometheus-auth-delegator \
  --clusterrole=system:auth-delegator \
  --serviceaccount=monitoring:kube-prometheus-stack-prometheus

For a hardened setup, prefer authorization.credentials (referencing a Secret) over bearerTokenFile, and pin the CA instead of insecureSkipVerify.

Deploy mongodb-operator with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has mongodb-operator on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartmongodb-operator is pinned at v1.16.18 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply