mongodb

by HelmForge

Helm chartv1.9.1App 9.0.8Apache-2.0Verified publisher

MongoDB Helm Chart - standalone, replica set, or sharded cluster using the official MongoDB image

About this chart

MongoDB Helm Chart

MongoDB Helm chart using the official mongo Docker image. Supports standalone, replica set, and sharded cluster architectures — no Bitnami dependency.

Install

HTTPS repository

helm repo add helmforge https://repo.helmforge.dev
helm repo update
helm install mongodb helmforge/mongodb -f values.yaml

OCI registry

helm install mongodb oci://ghcr.io/helmforgedev/helm/mongodb -f values.yaml

Quick Start

# Standalone with auth
helm install mongodb helmforge/mongodb --set auth.rootPassword=changeme

# Replica set (3 members)
helm install mongodb helmforge/mongodb \
  --set architecture=replicaset \
  --set auth.rootPassword=changeme

Architectures

ModearchitectureDescription
StandalonestandaloneSingle mongod instance (StatefulSet, 1 replica)
Replica SetreplicasetN-member RS with automatic rs.initiate() via Helm hook Job
ShardedshardedMongos routers + config servers + N shards, auto-initialized

Read before choosing an architecture:

  • Standalone
  • Replica Set
  • Sharded
  • Backup and Restore

Key Features

  • Official mongo image — no vendor lock-in, standard paths (/data/db)
  • Upgrade-safe credential generation — generated root credentials and replica set keyFiles are retained with persistent data
  • Optional arbiter — one lightweight voting member for cost-constrained replica sets
  • Helm hook Jobs — idempotent rs.initiate() and shard registration
  • Prometheus exporter — optional percona/mongodb_exporter sidecar + ServiceMonitor
  • Built-in S3 backups — scheduled mongodump archive upload for standalone, replica set, and sharded topologies
  • Init scripts — .sh and .js files via ConfigMap (/docker-entrypoint-initdb.d/)
  • Custom mongod.conf — mount via ConfigMap
  • Security defaults — fsGroup: 999, startup/liveness/readiness probes; optional strict non-root securityContext, podSecurityContext, and keyfile init-container initContainerSecurityContext for clusters that require it
  • Extra manifests — inject arbitrary K8s resources with Helm templating

Configuration

Minimal (Standalone)

architecture: standalone
auth:
  enabled: true
  rootPassword: "my-secret-password"
persistence:
  size: 10Gi

Replica Set (Production)

architecture: replicaset
auth:
  enabled: true
  existingSecret: mongodb-credentials  # keys: mongodb-root-username, mongodb-root-password
replicaSet:
  name: rs0
  members: 3
persistence:
  size: 50Gi
resources:
  requests:
    cpu: 500m
    memory: 2Gi
  limits:
    cpu: "2"
    memory: 4Gi
metrics:
  enabled: true
  serviceMonitor:
    enabled: true

Sharded Cluster

architecture: sharded
auth:
  enabled: false
sharded:
  mongos:
    replicaCount: 2
  configServer:
    replicaCount: 3
    persistence:
      size: 8Gi
  shards:
    count: 2
    membersPerShard: 3
    persistence:
      size: 50Gi

The sharded example is intentionally unauthenticated. The official MongoDB container initializes MONGO_INITDB_ROOT_* as a standalone process, which is not compatible with --configsvr or --shardsvr. Production sharded authentication requires an operator-managed bootstrap flow outside this chart's automatic root user initialization path.

Replica Set with Arbiter

architecture: replicaset
replicaSet:
  members: 2
arbiter:
  enabled: true

This topology creates two persistent data-bearing members and one arbiter with ephemeral local storage. MongoDB recommends three data-bearing members when capacity permits. Use an arbiter only when the cost of a third data copy is the deciding constraint, and review the official arbiter considerations.

Parameters

Global

ParameterDescriptionDefault
architecturestandalone, replicaset, or shardedstandalone
image.repositoryMongoDB imagemongo
image.tagImage tag9.0.8
nameOverrideOverride chart name""
fullnameOverrideOverride full release name""

Authentication

ParameterDescriptionDefault
auth.enabledEnable MongoDB authenticationtrue
auth.rootUserRoot usernameroot
auth.rootPasswordRoot password (auto-generated if empty)""
auth.existingSecretExisting secret with credentials""
auth.replicaSetKeyKeyFile content (auto-generated if empty)""
auth.existingKeySecretExisting secret with keyFile""
auth.replicaSetKeySecretPermissionsKeyFile secret volume permission bits (0440 for non-root init)0400

Replica Set

ParameterDescriptionDefault
replicaSet.nameReplica set namers0
replicaSet.membersNumber of data-bearing members3
arbiter.enabledAdd one non-data-bearing voting memberfalse
arbiter.resourcesArbiter container resources{}

Sharded Cluster Parameters

ParameterDescriptionDefault
sharded.mongos.replicaCountNumber of mongos routers2
sharded.mongos.portMongos port27017
sharded.configServer.replicaCountConfig server members3
sharded.configServer.persistence.sizeConfig server PVC size8Gi
sharded.shards.countNumber of shards2
sharded.shards.membersPerShardMembers per shard RS3
sharded.shards.persistence.sizeShard PVC size16Gi

Persistence

ParameterDescriptionDefault
persistence.enabledEnable PVC via volumeClaimTemplatetrue
persistence.storageClassStorage class (empty = default)""
persistence.accessModePVC access modeReadWriteOnce
persistence.sizePVC size8Gi

Resources & Probes

ParameterDescriptionDefault
resourcesCPU/memory requests and limits for mongod{}
initContainerResourcesResources for init containers (e.g. init-keyfile on members/arbiter/mongos/configsvr/shards){}
replicaSet.initJob.resourcesResources for the rs-init Helm hook Job (prefer ≥256Mi/512Mi){}
sharded.initJob.resourcesResources for the sharded-init Job (prefer ≥256Mi/512Mi){}
livenessProbeLiveness probe configmongosh ping, 30s delay
readinessProbeReadiness probe configmongosh ping, 10s delay
startupProbeStartup probe configmongosh ping, 5s delay, 30 failures

Metrics

ParameterDescriptionDefault
metrics.enabledDeploy mongodb-exporter sidecarfalse
metrics.image.repositoryExporter imagepercona/mongodb_exporter
metrics.image.tagExporter tag0.49.0
metrics.portExporter port9216
metrics.serviceMonitor.enabledCreate ServiceMonitorfalse

Backup

ParameterDescriptionDefault
backup.enabledEnable built-in S3 backup CronJobfalse
backup.scheduleBackup schedule"0 3 * * *"
backup.s3.endpointS3-compatible endpoint URL""
backup.s3.bucketTarget bucket name""
backup.database.mongoDumpArgsExtra mongodump flags""

Service

ParameterDescriptionDefault
service.typeService typeClusterIP
service.portService port27017
service.ipFamilyPolicyService IP family policy (SingleStack, PreferDualStack, RequireDualStack)""
service.ipFamiliesService IP families override[]

External Secrets

ParameterDescriptionDefault
externalSecrets.enabledRender an ExternalSecret for MongoDB credentialsfalse
externalSecrets.secretStoreRef.nameSecretStore or ClusterSecretStore name""
externalSecrets.secretStoreRef.kindSecret store kindSecretStore
externalSecrets.dataExternalSecret data mappings for root credentials and backup secrets[]

Other

ParameterDescriptionDefault
configCustom mongod.conf (YAML){}
initdbScriptsInit scripts for first startup{}
initdbDatabaseDatabase for init scripts""
extraEnvExtra environment variables[]
extraVolumesExtra volumes[]
extraVolumeMountsExtra volume mounts[]
extraManifestsArbitrary K8s manifests[]
automountServiceAccountTokenMount a Kubernetes API token in MongoDB pods and hook jobsfalse
podSecurityContextPod-level security context (fsGroup: 999 and RuntimeDefault seccomp){"fsGroup":999,"seccompProfile":{"type":"RuntimeDefault"}}
securityContextContainer-level security context (empty for compatibility){}
initContainerSecurityContextInit container security context (root, CHOWN only){"runAsNonRoot":false,"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"],"add":["CHOWN"]}}
nodeSelectorNode selector{}
tolerationsTolerations[]
affinityAffinity rules{}

Resources Generated

ArchitectureResources
standaloneSecret, 2x Service (headless + client), StatefulSet
replicaset2x Secret (auth + keyfile), 2x Service, StatefulSet, Job (rs-init)
replicaset + arbiter2x Secret, 3x Service, 2x StatefulSet, Job (rs-init)
sharded2x Secret, 4x Service, 3x StatefulSet (config + shards), Deployment (mongos), Job (init)

Examples

See the examples/ directory:

  • standalone-simple.yaml — Minimal standalone instance
  • replicaset-production.yaml — Production RS with monitoring, init scripts, and anti-affinity
  • replicaset-arbiter.yaml — Two data members with one voting arbiter
  • sharded-cluster.yaml — Full sharded cluster

Architecture Guides

  • docs/standalone.md — when to use a single-node deployment
  • docs/replicaset.md — when to use replica set topology and what it requires operationally
  • docs/sharded.md — when to use sharding, mongos, config servers, and multiple shards
  • docs/backup-restore.md — S3 backup strategy and restore guidance

Upgrade Notes

Upgrading to 9.0.8

MongoDB 9.0.8 contains stability improvements and bug fixes. Review the official 9.0 release notes.

Upgrading to 9.0.2

MongoDB 9.0.2 is a patch in the MongoDB 9.0 rapid-release line. Before a binary upgrade from 8.3, take a tested backup and confirm every member reports featureCompatibilityVersion: "8.3". Upgrade using the topology-specific upstream procedure, then raise FCV to 9.0 only after all members are healthy and rollback is no longer required. Review the MongoDB 9.0 release notes before reusing existing PVCs. The chart keeps generated root credentials and replica set keyFiles stable across helm upgrade, including upgrades with --reset-values or --reuse-values, and retains them when persistent releases are removed. These credentials are bound to the initialized data directory. Rotate them with MongoDB administrative commands and a coordinated Secret update instead of changing initialization values. Back up both the PVC data and its credential Secrets; restoring only one side can make the database inaccessible.

StatefulSet claim-template sizes are immutable. During upgrades the chart keeps the size already applied to each MongoDB StatefulSet, including when --reset-values would otherwise restore the default and make Kubernetes reject the upgrade. Resize the bound PVCs through the storage class workflow; updating persistence.size alone does not resize an existing claim. It also does not change the size used for PVCs created by future scale-up. Before adding members after expanding existing PVCs, confirm that the retained claim-template size can hold a new member's initial synchronization.

Enabling or disabling arbiter.enabled on an existing replica set reconciles the arbiter membership through the post-upgrade hook. Increasing replicaSet.members adds missing data-bearing members. Reducing that value does not remove members from the MongoDB configuration; remove members safely with MongoDB administrative procedures before scaling down the StatefulSet.

MongoDB requires a global default write concern before a reconfiguration that would change its implicit value. When arbiter reconciliation encounters an implicit default, the hook preserves the currently effective value (w: 1 or majority) by promoting it to a global default. Existing operator-managed global defaults are not changed. The same preservation runs before adding a missing data-bearing member because scale-up can also change the implicit default. MongoDB 5.0 and newer do not allow a global default write concern to be unset after it is established.

Security Scan

Security Scan: Kubescape local scan against MITRE,NSA,SOC2 reports a 72.73% resource summary score.

Connection Strings

# Standalone
mongodb://root:password@<release>-mongodb.<namespac

Deploy mongodb with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has mongodb 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 is pinned at v1.9.1 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