Running Production Databases on Kubernetes (CloudNativePG, MongoDB Operator)
Operate databases with operators that manage failover, backups, and topology.
In plain words
A database operator is a resident DBA following a written runbook continuously, but it cannot see value in data the backup never validated. The simple Kubernetes rule is: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
Think of it like…
A database operator is a resident DBA following a written runbook continuously, but it cannot see value in data the backup never validated.
Where you’ve seen it
Before approving a data-path change, the storage owner runs kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db. Expected evidence: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy. If the run instead shows this symptom, stop and restore the last known state: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready.
Words you’ll hear
- Operators
- For this lesson, Operators is the controlling idea: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
- CloudNativePG
- CloudNativePG is the checkpoint; run
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-dband inspect the owner chain. An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready. - MongoDB
- MongoDB is the outcome to preserve; the cost is explicit: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.
- Verification evidence
- The evidence command is
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db. It connects the declaration to this behavior: Operate databases with operators that manage failover, backups, and topology.
Visual diagram
Theory & deep dive
How Operators reaches the intended state
Operate databases with operators that manage failover, backups, and topology. Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
The concrete checkpoint is kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db; compare the Operators owner, CloudNativePG state, and MongoDB outcome instead of treating YAML acceptance as proof.
Run kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db after the change and correlate the result with Events and the owning object. Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
CloudNativePG: failure boundary and production cost
An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready. The prerequisite contract is concrete: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage. A safe design limits blast radius, records the last good configuration, and uses kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db as a deterministic rollback checkpoint.
Capture the current state with kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready.
How it works, step by step
Step 1 of 41. Declare the data contract
State capacity, topology, access, and ownership in the claim or class: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
- Goal
- Operate databases with operators that manage failover, backups, and topology.
- Owner
- Operators
When to use it & trade-offs
What it is
Operate databases with operators that manage failover, backups, and topology. Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
Why it matters: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready. The invariant at risk is specific: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy. The quickest fact check before changing the design is kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db.
When to reach for it
- Use Operators to enforce this invariant: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
- Use CloudNativePG evidence from
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-dbin reviews and incident timelines. Operate databases with operators that manage failover, backups, and topology. - Choose the managed external data plane route only when this cost is justified by governance or scale: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.
When to avoid or be careful
- Avoid assuming Operators is complete after YAML submission; the required behavior is concrete: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-dbfirst: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready. - Avoid adopting a heavier platform wrapper before measuring its cost: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.
Native, manual, and managed paths for Operators
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db.Strengths: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
Watch out: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage. Recovery must also recognize this signal: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready.
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db; the expected invariant is: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.Strengths: kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike Operators, it does not make this symptom self-documenting: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready.
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
Watch out: The added platform ownership buys value at this cost: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
- Trace Operators to MongoDB through CloudNativePG; the invariant is: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
- Recognize the symptom: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready.
- Justify the cost: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.
- Verify with kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db instead of only inspecting YAML.
Benchmarks & rules of thumb
- 3
- database states to monitor: primary health, replica lag, and backup restore
- 2
- object layers: custom resource and generated workload state
- 0
- automatic safety without tested failover
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the Operators owner contract: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy.
- Ignoring this telltale condition leads to unrelated changes: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready.
- Repeating
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-dbwithout an owner for remediation wastes retry cost. Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy?
- Which owner object, logs, and Events would you inspect for this symptom-An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready-?
- At what threshold would this cost become unacceptable: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage?
kubectl get clusters.postgresql.cnpg.io -A; kubectl describe cluster app-db, name the failure, then justify the cost. Invariant: Database operators reconcile a database custom resource into StatefulSets, Services, failover decisions, backups, PITR, and rolling version policy. Failure: An operator can remain healthy while a quorum is split, a replica is stale, or a backup never restores; database SLOs must be validated independently of custom resource Ready. Cost: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Running Production Databases on Kubernetes (CloudNativePG, MongoDB Operator) with generative AI interview Q&A and hands-on practice.