Skip to main content
helm chart · mongodb

MongoDB

Helm chart for deploying a MongoDB datastore

Latest version
v0.0.1
Chart type
Data source
Requires
Helm 3+

Install

Add the zop.dev chart repository, then install mongodb into your cluster.

helm repo add zopdev https://helm.zop.dev
helm repo update
helm install my-mongo zopdev/mongodb --version v0.0.1

Deploys a single-node MongoDB server on Kubernetes, with persistence, a Prometheus exporter, alerts, and one database + user per application listed in services.

Single node. One mongod (replicas: 1), no replica set. It is meant as an application datastore, not a highly available MongoDB cluster.

Prerequisites

  • Kubernetes 1.19+
  • Helm 3+
  • Prometheus Operator CRDs (ServiceMonitor, PrometheusRule). The chart renders both unconditionally, so helm install fails on a cluster without them.

Add Helm Repository

Terminal window
helm repo add zopdev https://helm.zop.dev
helm repo update

Install Helm Chart

Terminal window
helm install my-mongo zopdev/mongodb \
--set 'services[0].name=myapp' \
--set 'services[0].database=myapp'

Uninstall Helm Chart

Terminal window
helm uninstall my-mongo

The data volume (<release>-mongodb-persistent-storage-<release>-mongodb-0) is kept after uninstall, as with any StatefulSet. Delete the PVC to drop the data.


Configuration

ParameterDescriptionDefault
versionMongoDB image tag (mongo:<version>), pinned to a patch release7.0.45
diskSizeSize of the PVC backing /data/db. Fixed at install time10Gi
wiredTigerCacheSizeGBWiredTiger cache size, minimum 0.25. Keep it at about half of the memory limit or less0.25
resources.requests.cpuCPU request250m
resources.requests.memoryMemory request500Mi
resources.limits.cpuCPU limit1000m
resources.limits.memoryMemory limit1Gi
servicesDatabases to create: a list of {name, database}[]
nameService the alerts are attributed torelease name
nodeSelector / tolerations / affinityPod schedulingempty

What each services entry gets

For every entry {name: <svc>, database: <db>} the chart creates a user scoped to <db> (roles readWrite and dbAdmin on that database only) through a one-shot Job, plus:

ConfigMap <release>-<db>-<svc>-mongodb-configmap

KeyValue
MONGO_HOST<release>-mongodb
MONGO_PORT27017
MONGO_DB<db>

Secret <release>-<db>-<svc>-mongodb-database-secret

KeyValue
MONGO_USERgenerated username
MONGO_PASSWORDgenerated password
MONGO_URI / MONGODB_URImongodb://<user>:<password>@<release>-mongodb:27017/<db>?authSource=<db>

Underscores in <db> become hyphens in the object names. Credentials are generated on install and read back from the live Secret on every upgrade, so they stay stable.

Attach them to an app built on the service chart (0.0.34+) with:

Terminal window
datastores:
mongodb:
- datastore: <release>
database: <db>

The service chart looks for <datastore>-<db>-<its release>-mongodb-*, so this matches when the mongodb release, the services[].name and the app release share one name, which is the case when mongodb is bundled as a subchart.

The root password lives in <release>-mongodb-root-secret.

Credential caveats

  • Uninstall keeps the data and the root password. helm uninstall leaves the data PVC (as with any StatefulSet) and, through helm.sh/resource-policy: keep, the <release>-mongodb-root-secret. The root password is written into the volume on first boot only, so a reinstall with the same release name in the same namespace adopts the kept Secret and can still log in. To start from scratch, delete both: kubectl delete pvc <release>-mongodb-persistent-storage-<release>-mongodb-0 secret <release>-mongodb-root-secret.

  • Render with a cluster connection. Credentials are kept stable by reading the live Secrets with lookup. Under helm template, or a GitOps tool that renders without cluster access (for example Argo CD), lookup returns nothing, so every render generates a new username and password. The postgres chart behaves the same way. Install and upgrade with helm install / helm upgrade.

  • Don’t hand-edit MONGO_PASSWORD. The init Job’s name hashes the username but deliberately not the password, so changing only the password in the Secret does not re-run the Job, and mongod keeps the old password. If the Secret is deleted instead, the next upgrade generates a new username as well, which changes the Job name and re-runs it.


Monitoring

A percona/mongodb_exporter sidecar serves metrics on port 2121, scraped through the <release>-mongodb ServiceMonitor. The <release>-mongodb PrometheusRule raises:

AlertFires when
MongodbDownmongod is unreachable, or the exporter has stopped reporting (pod or exporter gone) for 1 minute
MongodbRestartedmongod has been up for less than a minute
MongodbTooManyConnectionsmore than 80% of available connections are in use for 2 minutes

Every alert carries a service label set to name (the owning service), or to the release name when name is empty, so alerts can be routed to whoever owns the app.

The rule is named <release>-mongodb, not after the bare release name, so an application chart can bundle mongodb next to redis or postgres without a PrometheusRule name collision.


Contributing

Please refer to CONTRIBUTING.md.

License

This project is licensed under the LICENSE.

See it fire on your bill.

Connect an account read-only in about five minutes. Findings start with the first scan.

472 rule families across 353 resource types on 22 platforms. Every threshold, metric, and IAM action is documented on these pages before you grant anything.

472 rule families documented
353 resource types covered
read-only default access level
Multi-cloud automation· Production-ready in 30 min· SOC 2 · ISO 27001· 20–60% off the bill, first month· 4 platforms · 1 console· Multi-cloud automation· Production-ready in 30 min· SOC 2 · ISO 27001· 20–60% off the bill, first month· 4 platforms · 1 console·