mongodb

by CloudPirates

Helm chartv0.20.6App 9.0.8Apache-2.0Verified publisher

MongoDB a flexible NoSQL database for scalable, real-time data management

About this chart

MongoDB

A flexible NoSQL database for scalable, real-time data management.

Description

This Helm chart provides a complete MongoDB StatefulSet deployment solution with persistent storage, authentication, health checks, and security configurations. It uses the official mongo Docker image and supports various deployment scenarios from development to production environments.

Features

  • Official MongoDB Image: Uses the official mongo Docker image from Docker Hub
  • Authentication: Configurable MongoDB authentication with root user credentials
  • Custom User: Optional custom user creation at initialisation with configurable credentials and database — works in both standalone and sharded cluster modes
  • Persistent Storage: Automatic persistent volume management through StatefulSet volumeClaimTemplates
  • Security: Non-root container execution with proper security contexts
  • Health Checks: Liveness and readiness probes using mongosh
  • Flexible Configuration: Comprehensive configuration options for various deployment needs
  • Service Account: RBAC-ready with configurable service account
  • Resource Management: Configurable CPU and memory limits/requests
  • Sharded Cluster: Full sharded cluster support with config servers, mongos routers, and shard servers including automated initialisation, replica set setup, balancer configuration, and auto-sharding

Installing the Chart

To install the chart with the release name my-mongodb:

helm install my-mongodb oci://registry-1.docker.io/cloudpirates/mongodb

To install with custom values:

helm install my-mongodb oci://registry-1.docker.io/cloudpirates/mongodb -f my-values.yaml

Uninstalling the Chart

To uninstall/delete the my-mongodb deployment:

helm delete my-mongodb

Security & Signature Verification

This Helm chart is cryptographically signed with Cosign to ensure authenticity and prevent tampering.

Public Key:

-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5U+rM2d3hDjgP5T3cLShuuQIU9vR
Z4/G+Nug6q5vRa+C3qUA1wXjbaJFAfcIrv5VjmYAYOj13shnPpp3Zh4fnQ==
-----END PUBLIC KEY-----

To verify the helm chart before installation, copy the public key to the file cosign.pub and run cosign:

cosign verify --key cosign.pub registry-1.docker.io/cloudpirates/mongodb:<version>

Configuration

The following table lists the configurable parameters of the MongoDB chart and their default values.

Global Parameters

ParameterDescriptionDefault
global.imageRegistryGlobal Docker Image registry""
global.imagePullSecretsGlobal Docker registry secret names as an array[]
global.dataNodes.extraContainersAdditional containers to add to all data node pods (statefulset, statefulset-shard, statefulset-hidden, statefulset-configserver)[]
global.dataNodes.extraVolumesAdditional volumes to add to all data node pods (statefulset, statefulset-shard, statefulset-hidden, statefulset-configserver)[]

Common Parameters

ParameterDescriptionDefault
nameOverrideString to partially override mongodb.fullname""
fullnameOverrideString to fully override mongodb.fullname""
namespaceOverrideString to override the namespace for all resources""
commonLabelsLabels to add to all deployed objects{}
commonAnnotationsAnnotations to add to all deployed objects{}
podAnnotationsAnnotations to add to the pod created by the statefulset{}
podLabelsLabels to add to the pod created by the statefulset{}
revisionHistoryLimitMaximum number of revisions maintained in revision history10
podManagementPolicyPod management policyOrderedReady
updateStrategyTypePod update strategyRollingUpdate

MongoDB Image Parameters

ParameterDescriptionDefault
image.registryMongoDB image registrydocker.io
image.repositoryMongoDB image repositorymongo
image.tagMongoDB image tag"8.2.1@sha256:86835e8da0f94efd61334decb320fa43e8a60027688cbd856bf29d065b470338"
image.pullPolicyMongoDB image pull policyAlways
image.extraArgsOverride default container args (useful when using custom images)[]

Replica Configuration

ParameterDescriptionDefault
replicaCountNumber of MongoDB replicas to deploy1

Service Parameters

ParameterDescriptionDefault
service.typeKubernetes service typeClusterIP
service.portMongoDB service port27017
service.annotationsAnnotations to add to the mongodb service{}
service.headlessServiceSuffixheadless

MongoDB Authentication Parameters

ParameterDescriptionDefault
auth.enabledEnable MongoDB authenticationtrue
auth.rootUsernameMongoDB root usernameadmin
auth.rootPasswordMongoDB root password (if empty, random password will be generated)""
auth.existingSecretName of existing secret containing MongoDB password""
auth.existingSecretPasswordKeyKey in existing secret containing MongoDB password""

MongoDB Configuration Parameters

ParameterDescriptionDefault
config.mountPathMongoDB configuration options/etc/mongo
config.contentInclude your custom MongoDB configurations here as stringsystemLog:\n quiet: true\n verbosity: 0\nnet:\n bindIpAll: true
config.existingConfigmapName of an existing Configmap to use instead of creating one""
config.existingConfigmapKeyName of the key in the Configmap that should be used""

Custom Role Configuration

Custom MongoDB roles can be created at initialisation time via the customRoles array. Roles are created before custom users, so you can reference custom roles in customUsers[].roles. If a role already exists, it will be skipped (not updated).

This works in standalone, replica set, and sharded cluster modes.

ParameterDescriptionDefault
customRoles[].roleRole name to create (required)
customRoles[].databaseDatabase where the role is createdadmin
customRoles[].privilegesList of privilege objects with resource and actions[]
customRoles[].privileges[].resourceMongoDB resource document (e.g. { db: "", collection: "" } or { cluster: true })
customRoles[].privileges[].actionsList of MongoDB privilege actions (e.g. ["find", "insert"])
customRoles[].rolesInherited roles. Strings apply to the same database; use { role, db } for cross-database inheritance[]

Example:

customRoles:
  - role: myCustomRole
    database: admin
    privileges:
      - resource: { cluster: true }
        actions: ["find"]
      - resource: { db: "", collection: "" }
        actions: ["find", "listCollections", "listIndexes"]
    roles:
      - backup
      - restore
      - clusterMonitor
      - { role: "read", db: "reporting" }

Custom User Configuration

Multiple users can be created at initialisation time via the customUsers array. Each user gets the specified roles on their database. This works in standalone, replica set, and sharded cluster modes (in sharded mode users are created via the mongos router after cluster initialisation).

Each entry supports either inline credentials (name + optional password/database) or an existing Kubernetes secret (existingSecret).

ParameterDescriptionDefault
customUsers[].nameUsername. A secret named <release>-custom-user-<i>-secret is auto-generated when no existingSecret""
customUsers[].databaseDatabase to create the user in. Defaults to name if not set""
customUsers[].passwordPassword. A random 32-char password is generated if not set""
customUsers[].existingSecretName of an existing secret. Supports Helm template strings""
customUsers[].secretKeys.nameKey in existingSecret holding the usernameCUSTOM_USER
customUsers[].secretKeys.passwordKey in existingSecret holding the passwordCUSTOM_PASSWORD
customUsers[].secretKeys.databaseKey in existingSecret holding the database nameCUSTOM_DB
customUsers[].rolesMongoDB roles to grant. Plain strings apply to the user's own database; use {role, db} for cross-database roles[readWrite, dbAdmin]

Examples:

customUsers:
  - name: appuser
    database: appdb
    password: supersecret
    roles:
      - readWrite
      - dbAdmin

  - name: readonlyuser
    database: reportingdb
    roles:
      - read

  # Cross-database role
  - name: monitoruser
    database: admin
    roles:
      - clusterMonitor
      - { role: readAnyDatabase, db: admin }

  # From an existing secret
  - existingSecret: my-app-credentials
    secretKeys:
      name: MONGO_USERNAME
      password: MONGO_PASSWORD
      database: MONGO_DATABASE
    roles:
      - readWrite

Persistence Parameters

| Parameter | Description | Default |

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 v0.20.6 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