Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 75/ 160
04. Storage & Persistent Data

Running Production Databases on Kubernetes (CloudNativePG, MongoDB Operator)

Operate databases with operators that manage failover, backups, and topology.

AdvancedOperators · CloudNativePG · MongoDB3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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-db and 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

Loading interactive 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.

Verify CloudNativePG, not only object creation

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.

Key takeaway: Operators is implemented only when this invariant remains observable: 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.

Recover from CloudNativePG drift

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.

Key takeaway: Accept the trade-off consciously: Operators encode expert workflows but create version, upgrade, and extension dependencies around the exact database they manage.

How it works, step by step

Step 1 of 4
Data owner

1. 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.

Operators contract → owned state
Key numbers at this step
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-db in 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-db first: 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

Dynamically provisioned storage
Best for: Operate databases with operators that manage failover, backups, and topology. A concrete incident check is 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.

Manual pre-provisioning
Best for: Quickly testing the CloudNativePG assumption with 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.

Managed external data plane
Best for: Teams that need MongoDB integrated with guardrails; the evidence path is 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-db without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Ephemeral Generic Volumes
Next topic
Backup & Disaster Recovery with Velero