Sign inSign up

rilusmahmud/mongodb

By rilusmahmud

•Updated 3 months ago

Helm
0

437

rilusmahmud/mongodb repository overview

⁠MongoDB Helm Chart

A Helm chart for deploying MongoDB 8.0 on Kubernetes with StatefulSet and persistent storage.

⁠Prerequisites

  • Kubernetes 1.19+
  • Helm 3.0+
  • PV provisioner support in the underlying infrastructure (for persistent storage)

⁠Installing the Chart

To install the chart with the release name mongodb:

helm install mongodb ./mongodb

To install in a specific namespace:

helm install mongodb ./mongodb --namespace database --create-namespace

⁠Uninstalling the Chart

To uninstall the mongodb release:

helm uninstall mongodb

This command removes all the Kubernetes components associated with the chart and deletes the release.

Note: PersistentVolumeClaims are not automatically deleted. To delete them:

kubectl delete pvc -l app.kubernetes.io/instance=mongodb

⁠Configuration

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

⁠Image Configuration
ParameterDescriptionDefault
image.registryMongoDB image registrydocker.io
image.repositoryMongoDB image repositorymongo
image.tagMongoDB image tag8.0
image.pullPolicyImage pull policyIfNotPresent
⁠Authentication
ParameterDescriptionDefault
auth.rootUsernameMongoDB root usernamedbadmin
auth.rootPasswordMongoDB root passwordHxPlsytQ3Rt
auth.existingSecretName of existing secret to use for credentialsnil
⁠StatefulSet Configuration
ParameterDescriptionDefault
replicaCountNumber of MongoDB replicas1
⁠Service Configuration
ParameterDescriptionDefault
service.typeKubernetes service typeLoadBalancer
service.portMongoDB service port27017
service.clusterIPStatic cluster IP or "None" for headless servicenil
service.sessionAffinitySession affinityNone
⁠Resource Configuration
ParameterDescriptionDefault
resources.requests.memoryMemory request2Gi
resources.requests.cpuCPU request1000m
resources.limits.memoryMemory limit16Gi
resources.limits.cpuCPU limit6000m
⁠Persistence Configuration
ParameterDescriptionDefault
persistence.enabledEnable persistent storagetrue
persistence.storageClassStorage class for PVCstandard-rwo
persistence.accessModePVC access modeReadWriteOnce
persistence.sizePVC storage size100Gi
persistence.annotationsPVC annotations{}
⁠Health Probes
ParameterDescriptionDefault
livenessProbe.enabledEnable liveness probetrue
livenessProbe.initialDelaySecondsInitial delay30
livenessProbe.periodSecondsPeriod10
livenessProbe.timeoutSecondsTimeout5
livenessProbe.failureThresholdFailure threshold3
readinessProbe.enabledEnable readiness probetrue
readinessProbe.initialDelaySecondsInitial delay10
readinessProbe.periodSecondsPeriod5
readinessProbe.timeoutSecondsTimeout3
readinessProbe.failureThresholdFailure threshold3
⁠Other Configuration
ParameterDescriptionDefault
podLabelsAdditional pod labels{component: database}
podAnnotationsPod annotations{}
nodeSelectorNode selector{}
tolerationsTolerations[]
affinityAffinity rules{}
securityContextPod security context{}
serviceAccount.createCreate service accountfalse
serviceAccount.nameService account name""
serviceAccount.annotationsService account annotations{}
extraEnvAdditional environment variables[]
extraVolumesAdditional volumes[]
extraVolumeMountsAdditional volume mounts[]

⁠Examples

⁠Install with custom values

Create a custom-values.yaml file:

auth:
  rootUsername: "admin"
  rootPassword: "SecurePassword123!"

persistence:
  size: 200Gi
  storageClass: "premium-rwo"

resources:
  requests:
    memory: "4Gi"
    cpu: "2000m"
  limits:
    memory: "32Gi"
    cpu: "8000m"

service:
  type: ClusterIP

Install the chart:

helm install mongodb ./mongodb -f custom-values.yaml
⁠Install with existing secret

First, create a secret:

kubectl create secret generic mongodb-credentials \
  --from-literal=MONGO_INITDB_ROOT_USERNAME=admin \
  --from-literal=MONGO_INITDB_ROOT_PASSWORD=SecurePassword123!

Then install the chart:

helm install mongodb ./mongodb \
  --set auth.existingSecret=mongodb-credentials
⁠Install as a replica set (3 replicas)
helm install mongodb ./mongodb \
  --set replicaCount=3 \
  --set service.clusterIP=None

Note: After scaling to multiple replicas, you need to configure the MongoDB replica set manually.

⁠Upgrade the chart
helm upgrade mongodb ./mongodb -f custom-values.yaml
⁠Dry run to see generated manifests
helm install mongodb ./mongodb --dry-run --debug

⁠Accessing MongoDB

⁠From within the cluster

Connection string format:

mongodb://<username>:<password>@<release-name>-mongodb-0.<release-name>-mongodb.<namespace>.svc.cluster.local:27017

Example:

mongodb://dbadmin:[email protected]:27017
⁠From outside the cluster (LoadBalancer)

Get the LoadBalancer IP:

export SERVICE_IP=$(kubectl get svc mongodb --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
mongosh "mongodb://dbadmin:HxPlsytQ3Rt@$SERVICE_IP:27017"
⁠Using port-forward (ClusterIP)
kubectl port-forward svc/mongodb 27017:27017
mongosh "mongodb://dbadmin:HxPlsytQ3Rt@localhost:27017"

⁠Backup and Restore

⁠Create a backup
kubectl exec mongodb-0 -- mongodump \
  -u dbadmin -p HxPlsytQ3Rt \
  --out /tmp/backup

kubectl cp mongodb-0:/tmp/backup ./mongodb-backup
⁠Restore from backup
kubectl cp ./mongodb-backup mongodb-0:/tmp/backup

kubectl exec mongodb-0 -- mongorestore \
  -u dbadmin -p HxPlsytQ3Rt \
  /tmp/backup

⁠Monitoring

To check the status of your MongoDB deployment:

# Check StatefulSet
kubectl get statefulset mongodb

# Check pods
kubectl get pods -l app.kubernetes.io/name=mongodb

# Check service
kubectl get svc mongodb

# Check PVCs
kubectl get pvc -l app.kubernetes.io/name=mongodb

# View logs
kubectl logs -l app.kubernetes.io/name=mongodb -f

# Check MongoDB status
kubectl exec mongodb-0 -- mongosh -u dbadmin -p HxPlsytQ3Rt --eval "db.adminCommand('ping')"

⁠Production Considerations

  1. Use external secret management: Don't store credentials in values.yaml. Use auth.existingSecret or external secret managers (e.g., Sealed Secrets, External Secrets Operator).

  2. Set up regular backups: Implement automated backup solutions using tools like Velero or MongoDB Ops Manager.

  3. Configure MongoDB replica sets: For high availability, deploy with 3+ replicas and configure a replica set.

  4. Enable TLS/SSL: Configure MongoDB to use TLS for encrypted connections.

  5. Resource planning: Adjust CPU and memory based on your workload requirements.

  6. Storage planning: Use high-performance storage classes (e.g., SSD-backed volumes).

  7. Set up monitoring: Deploy monitoring solutions like Prometheus with MongoDB Exporter and Grafana.

  8. Network policies: Implement network policies to restrict access to MongoDB.

  9. Regular updates: Keep MongoDB and the chart up to date with security patches.

  10. Test disaster recovery: Regularly test backup and restore procedures.

⁠Troubleshooting

⁠Pod not starting
kubectl describe pod mongodb-0
kubectl logs mongodb-0
⁠Check PVC status
kubectl get pvc
kubectl describe pvc mongodb-data-mongodb-0
⁠Authentication issues
kubectl get secret mongodb -o yaml
kubectl exec mongodb-0 -- env | grep MONGO
⁠Test connection
kubectl run -it --rm debug --image=mongo:8.0 --restart=Never -- \
  mongosh "mongodb://dbadmin:[email protected]:27017"

⁠License

Copyright © 2024 SPL Team

⁠Support

For issues, questions, or contributions, please contact the SPL Team or open an issue in the repository.

Tag summary

Content type

Helm

Digest

sha256:93ff956ac…

Size

7.7 kB

Last updated

3 months ago

helm pull oci://registry-1.docker.io/rilusmahmud/mongodb --version 1.2.3