mongodb-operator
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
| Asset | URL | Usage |
|---|---|---|
| Centered service symbol | https://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/symbol.png | Artifact Hub package icon and screenshot |
| Keiailab base symbol | https://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/base-symbol.png | Source reference for the outer rotating-arrow mark |
| Repository wordmark | https://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/logo.png | Project pages and docs cards |
| Social cover | https://raw.githubusercontent.com/KeiaiLab/mongodb-operator/main/docs/branding/cover.png | Social cards and launch posts |
| Branding guide | https://github.com/KeiaiLab/mongodb-operator/blob/main/docs/BRANDING.md | GitHub 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
| Parameter | Description | Default |
|---|---|---|
replicaCount | Number of operator replicas | 1 |
image.repository | Operator image repository | keiailab/mongodb-operator |
image.tag | Operator image tag | Chart appVersion |
image.pullPolicy | Image pull policy | IfNotPresent |
RBAC Parameters
| Parameter | Description | Default |
|---|---|---|
serviceAccount.create | Create service account | true |
rbac.create | Create RBAC resources | true |
rbac.clusterScope | Use ClusterRole | true |
Metrics Parameters
| Parameter | Description | Default |
|---|---|---|
metrics.enabled | Enable metrics endpoint | true |
metrics.secure | Enable HTTPS for metrics | true |
metrics.serviceMonitor.enabled | Create ServiceMonitor | false |
metrics.serviceMonitor.interval | Scrape interval | 30s |
Resource Parameters
| Parameter | Description | Default |
|---|---|---|
resources.requests.cpu | CPU request | 100m |
resources.requests.memory | Memory request | 128Mi |
resources.limits.cpu | CPU limit | 500m |
resources.limits.memory | Memory limit | 512Mi |
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:
| CRD | Short Name | Description |
|---|---|---|
MongoDB | mdb | MongoDB ReplicaSet |
MongoDBSharded | mdbsh | MongoDB Sharded Cluster |
MongoDBBackup | mdbbackup | Backup 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartmongodb-operator is pinned at v1.16.18 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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