skills/kubeblocks-addon-mongodb/SKILL.md
Deploy and manage MongoDB clusters on KubeBlocks with topology selection guidance. Supports ReplicaSet (HA) and Sharding (mongos + config servers + shards) topologies. Use when the user mentions MongoDB, Mongo, document database, or explicitly wants to create a MongoDB cluster. Provides topology comparison, best-practice defaults, and connection methods. For generic cluster creation across all engines, see kubeblocks-create-cluster. For Day-2 operations (scaling, backup, etc.), use the corresponding operation skill.
npx skillsauth add apecloud/kubeblocks-skills kubeblocks-addon-mongodbInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Deploy MongoDB clusters on Kubernetes using KubeBlocks. Supports ReplicaSet for HA and Sharding for horizontal scaling with mongos routers and config servers.
Official docs: https://kubeblocks.io/docs/preview/user_docs/kubeblocks-for-mongodb/cluster-management/create-and-connect-a-mongodb-cluster Full doc index: https://kubeblocks.io/llms-full.txt
# Check if mongodb addon is installed
helm list -n kb-system | grep mongodb
# Install if missing
helm install kb-addon-mongodb kubeblocks/mongodb --namespace kb-system --version 1.0.0
| Topology | topology value | Components | Use Case |
|---|---|---|---|
| ReplicaSet | replicaset | mongodb (3 replicas) | Standard HA, most common |
| Sharding | sharding | shard (N) + config-server + mongos | Horizontal scaling, large datasets |
MongoDB 4.0 through 7.0 are supported. Common serviceVersion values:
| Version | serviceVersion |
|---|---|
| MongoDB 4.0 | 4.0 |
| MongoDB 4.2 | 4.2 |
| MongoDB 4.4 | 4.4 |
| MongoDB 5.0 | 5.0 |
| MongoDB 6.0 | 6.0 |
| MongoDB 7.0 | 7.0.12 |
- [ ] Step 1: Ensure addon is installed
- [ ] Step 2: Create namespace
- [ ] Step 3: Create cluster (choose topology)
- [ ] Step 4: Wait for cluster to be ready
- [ ] Step 5: Connect to MongoDB
helm list -n kb-system | grep mongodb
If not found:
helm install kb-addon-mongodb kubeblocks/mongodb --namespace kb-system --version 1.0.0
kubectl create namespace demo --dry-run=client -o yaml | kubectl apply -f -
Standard HA setup with automatic primary election:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: mongo-cluster
namespace: demo
spec:
clusterDef: mongodb
topology: replicaset
terminationPolicy: Delete
componentSpecs:
- name: mongodb
serviceVersion: "7.0.12"
replicas: 3
resources:
limits: {cpu: "0.5", memory: "0.5Gi"}
requests: {cpu: "0.5", memory: "0.5Gi"}
volumeClaimTemplates:
- name: data
spec:
accessModes: [ReadWriteOnce]
resources: {requests: {storage: 20Gi}}
Apply:
kubectl apply -f mongo-cluster.yaml
Key points:
For horizontal scaling across multiple shards. Uses both spec.shardings (for shard data) and spec.componentSpecs (for config-server and mongos):
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: mongo-sharded
namespace: demo
spec:
clusterDef: mongodb
topology: sharding
terminationPolicy: Delete
shardings:
- name: shard
shards: 2
template:
name: mongodb
serviceVersion: "7.0.12"
replicas: 3
resources:
limits: {cpu: "0.5", memory: "0.5Gi"}
requests: {cpu: "0.5", memory: "0.5Gi"}
volumeClaimTemplates:
- name: data
spec:
accessModes: [ReadWriteOnce]
resources: {requests: {storage: 20Gi}}
componentSpecs:
- name: config-server
serviceVersion: "7.0.12"
replicas: 3
resources:
limits: {cpu: "0.5", memory: "0.5Gi"}
requests: {cpu: "0.5", memory: "0.5Gi"}
volumeClaimTemplates:
- name: data
spec:
accessModes: [ReadWriteOnce]
resources: {requests: {storage: 20Gi}}
- name: mongos
serviceVersion: "7.0.12"
replicas: 2
resources:
limits: {cpu: "0.5", memory: "0.5Gi"}
requests: {cpu: "0.5", memory: "0.5Gi"}
Key points:
spec.shardings (each shard is a ReplicaSet)spec.componentSpecsshards: 2 creates 2 shards (each with 3 replicas)mongos for data operations (port 27017)kubectl -n demo get cluster <cluster-name> -w
Wait until STATUS shows Running. Sharded clusters take longer (3-5 minutes).
Check pods:
kubectl -n demo get pods -l app.kubernetes.io/instance=<cluster-name>
# Secret name format: <cluster>-mongodb-account-root
kubectl -n demo get secret mongo-cluster-mongodb-account-root -o jsonpath='{.data.password}' | base64 -d
# ReplicaSet
kubectl -n demo exec -it mongo-cluster-mongodb-0 -- mongosh --username root --authenticationDatabase admin
# Sharded cluster (connect via mongos)
kubectl -n demo exec -it mongo-sharded-mongos-0 -- mongosh --username root --authenticationDatabase admin
# ReplicaSet
kubectl -n demo port-forward svc/mongo-cluster-mongodb 27017:27017
# Sharded (via mongos)
kubectl -n demo port-forward svc/mongo-sharded-mongos 27017:27017
# Then from another terminal:
mongosh mongodb://root:<password>@127.0.0.1:27017/admin
Cluster stuck in Creating:
kubectl -n demo describe cluster <cluster-name>
kubectl -n demo get events --sort-by='.lastTimestamp'
ReplicaSet not forming:
kubectl -n demo exec -it mongo-cluster-mongodb-0 -- mongosh --eval "rs.status()"
Sharding status:
kubectl -n demo exec -it mongo-sharded-mongos-0 -- mongosh --eval "sh.status()"
| Operation | Skill | External Docs | |---|---|---| | Stop / Start / Restart | cluster-lifecycle | Docs | | Scale CPU / Memory | vertical-scaling | Docs | | Add / Remove replicas | horizontal-scaling | Docs | | Expand storage | volume-expansion | Docs | | Change parameters | reconfigure-parameters | Docs | | Backup | backup | Docs | | Restore | restore | Docs |
Follow safety-patterns.md for dry-run before apply, status confirmation after watch, and pre-deletion checklist.
devops
Expand persistent volume storage for KubeBlocks database clusters via OpsRequest. Requires the StorageClass to support volume expansion (allowVolumeExpansion=true). Use when the user needs more disk space, wants to increase storage, expand volumes, or resize PVCs. NOT for changing CPU/memory (see vertical-scaling) or adding more replicas (see horizontal-scaling). Note that volume shrinking is not supported by Kubernetes.
data-ai
Scale CPU and memory resources for KubeBlocks database clusters via OpsRequest (vertical scaling). Supports in-place updates when the feature gate is enabled. Use when the user wants to change, increase, decrease, resize, or adjust CPU or memory resources of a database cluster. NOT for adding/removing replicas or shards (see horizontal-scaling) or expanding disk storage (see volume-expansion).
data-ai
Upgrade the KubeBlocks operator itself via Helm. Covers update operator, upgrade to v1.0, update kubeblocks version, and CRD updates. Use when the user wants to upgrade KubeBlocks, update the operator, or upgrade to a new KubeBlocks release. NOT for upgrading database engine versions (see minor-version-upgrade).
development
Diagnostic guide for KubeBlocks-managed database clusters. Use when the user reports troubleshoot, debug, diagnose, not working, error, failed, stuck, CrashLoopBackOff, cluster exception, or similar problems with their database cluster. This skill guides the agent through diagnostic steps — it does NOT perform actions.