Runbook: MongoDB Connection Error
Overview
MongoDB is used to persist health events that are created by health monitors like syslog-health-monitor, gpu-health-monitor etc for 30 days. The fault-handling modules(like fault-quarantine, node-drainer, fault-remediation) connect to MongoDB to process these events and cordon/uncordon/remediate the node. When MongoDB pods crash or fail to start, all event processing in NVSentinel stops.
Common Causes
MongoDB connection failure can occur due to the following reasons:
1. TLS Certificates Not Installed or Expired
- Missing
mongodb-tls-secretormongo-app-client-cert-secretsecrets - Expired certificates
2. Initialization Job Not Completed
create-mongodb-database-<seconds>-<scriptHash>job failed or still running (-l app.kubernetes.io/name=create-mongodb-database)- Job creates required database, collections, and indexes
- Without successful completion, MongoDB pod can’t initialize properly
3. Storage Class Is Missing
- PersistentVolumeClaims (PVCs) use StorageClass to dynamically provision volume. Without a valid StorageClass, PVCs cannot bind to storage and MongoDB pods cannot start without bounded PVCs
4. Open-File Limit Too Low
- The node gives containers a soft open-file limit below 64000, for example 1024
- mongod runs out of file descriptors when the number of client connections grows with the cluster, and crashes
Quick Diagnosis
Run these commands to identify the issue:
Detailed Troubleshooting
Issue 1: Expired Certificates/Secrets
Diagnosis:
Solution:
Scenario A: Mongo secrets do NOT exist (cert-manager webhook is the problem)
If Step 1 showed no mongo secrets, or Step 3 showed cert-manager-webhook-ca is expired:
Scenario B: Mongo secrets exist but are expired (cert-manager is healthy)
If Step 1 showed mongo secrets exist, and Step 4 showed they are expired, but Step 3 showed cert-manager webhook is healthy:
Issue 2: Initialization Job Failed
Issue 3: Storage Class Is Missing
Issue 4: Open-File Limit Too Low
mongod uses one file descriptor for each client connection. Each platform-connectors pod has its own connection pool, so the number of connections grows with the number of nodes. If the node gives containers a low soft open-file limit, mongod runs out of file descriptors and crashes. This usually happens after the cluster grows, for example from 50 to 500 nodes.
Symptoms:
- MongoDB pods are in
CrashLoopBackOff. In issue #1555, mongod exited with code 139. - MongoDB does not become ready. With Bitnami, the
mongodbStatefulSet shows fewer than 3 ready replicas. In issue #1555 it showed0/3, and because of theOrderedReadypolicy, the last replica did not start. With the Percona Operator,kubectl -n nvsentinel get perconaservermongodbdoes not showready. - fault-quarantine, node-drainer and fault-remediation crash with
ReplicaSetNoPrimaryorconnection refused.
Diagnosis:
If a MongoDB pod is running, you can also read the limit of mongod directly:
Solution:
If a MongoDB pod moves to a node that you did not change, it fails again. Change every node that can run MongoDB, or keep MongoDB on nodes that you changed. See Node Placement for Bitnami and Pod placement (Percona) for the Percona Operator.
fault-quarantine, node-drainer and fault-remediation reconnect when the replica set has a primary. If MongoDB was down for a long time, see Stale Events.
To find this problem before mongod fails, monitor the connection capacity of mongod. See Open-file limit.