KubeKanvas Logo
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
Back to Templates

Deploy MongoDB on Kubernetes: NoSQL Database

Tags:
MongoDBStatefulsetKubernetesKubekanvas
Created by:
Siddiqui
Deploy MongoDB on Kubernetes: NoSQL Database template preview
0 uses
KubeKanvas Logo
Visual Kubernetes cluster design tool that helps you create, manage, and deploy your applications with ease.
Product
  • Features
  • Pricing
  • Templates
Resources
  • Blog
  • Tutorials
Company
  • About Us
  • Contact
  • Terms of Service
  • Privacy Policy
  • Responsible AI Policy
  • Impressum
XGitHubLinkedIn
© 2026 KubeKanvas. All rights reserved.

Deploy MongoDB on Kubernetes to manage persistent document database workloads with built-in authentication. Running MongoDB as a StatefulSet ensures stable network identifiers and dedicated persistent storage across pod restarts. This setup provides a complete single-replica database instance configured with internal routing and operational health checks.

What's Included

ComponentTypePortRole
defaultNamespaceN/AGroups resources within the default namespace scope
mongodb-secretSecretN/AStores root username and password credentials
mongodb-headlessService27017Provides network identity for StatefulSet pods
mongodbService27017Exposes MongoDB internally via ClusterIP
mongodbStatefulSet27017Manages single-replica MongoDB pod lifecycle
mongodb-storagePersistentVolumeClaimN/AProvisions 20Gi persistent storage for database files

Architecture Overview

The StatefulSet executes a single mongo container that pulls root initialization credentials directly from the Secret. Data persists across restarts via a 20Gi PersistentVolumeClaim mounted at /data/db. The headless Service maintains direct network identity for the pod, while the standard ClusterIP Service exposes database port 27017 to cluster-internal clients. Exec probes run mongosh ping commands inside the container to monitor startup, liveness, and readiness states.

Prerequisites

  • Active Kubernetes cluster with support for dynamic volume provisioning.

  • StorageClass configured to satisfy the ReadWriteOnce 20Gi volume claim.

  • KubeKanvas CLI installed and running on your computer (Optional, if you want to use one-click deployment)

How to Deploy

  1. Verify target namespace configuration or keep the default namespace scope.

  2. Update the default MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD secret entries.

  3. Adjust the 20Gi storage request in the volumeClaimTemplates section if required.

  4. Deploy the template to your cluster via the Play button in the top right bar. If you prefer to deploy manually, download the YAML and apply it with kubectl.

  5. Wait for all pods to reach Running status. You can monitor progress in the Release Monitor screen.

How to Test

  1. Check database readiness by running kubectl exec -n default statefulset/mongodb -- mongosh --eval "db.adminCommand('ping')".

  2. Authenticate against the admin database by running kubectl exec -it -n default statefulset/mongodb -- mongosh -u admin -p ChangeMe123! --authenticationDatabase admin.

Use Cases

  • Single-Node Application Backend: Serve microservices running inside the cluster through internal ClusterIP service routing.

  • Stateful Document Storage: Store persistent JSON documents using dedicated volume storage and automated container lifecycle management.

Summary

This template configures a secure MongoDB StatefulSet on Kubernetes with persistent storage, internal service endpoints, and exec-based health probing.