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 99/ 160
05. Configuration, Packaging & GitOps

Kubernetes Operators & The Controller Reconciliation Loop (Kubebuilder / Operator SDK)

Build operators that continuously reconcile custom resources to desired state.

AdvancedOperator · Reconcile Loop · Kubebuilder3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

An operator is an on-call engineer modeled as a loop: observe, compare, act, record status, and then sleep until the next event. The simple Kubernetes rule is: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Think of it like…

An operator is an on-call engineer modeled as a loop: observe, compare, act, record status, and then sleep until the next event.

Where you’ve seen it

A platform team reviews a promoted source revision and runs kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}'. Expected evidence: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion. If the run instead shows this symptom, stop and restore the last known state: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.

Words you’ll hear

Operator
For this lesson, Operator is the controlling idea: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.
Reconcile Loop
Reconcile Loop is the checkpoint; run kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' and inspect the owner chain. A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.
Kubebuilder
Kubebuilder is the outcome to preserve; the cost is explicit: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.
Verification evidence
The evidence command is kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}'. It connects the declaration to this behavior: Build operators that continuously reconcile custom resources to desired state.

Visual diagram

Loading interactive diagram

Theory & deep dive

How Operator reaches the intended state

Build operators that continuously reconcile custom resources to desired state. An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

The concrete checkpoint is kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}'; compare the Operator owner, Reconcile Loop state, and Kubebuilder outcome instead of treating YAML acceptance as proof.

Verify Reconcile Loop, not only object creation

Run kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' after the change and correlate the result with Events and the owning object. An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Key takeaway: Operator is implemented only when this invariant remains observable: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Reconcile Loop: failure boundary and production cost

A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever. The prerequisite contract is concrete: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency. A safe design limits blast radius, records the last good configuration, and uses kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' as a deterministic rollback checkpoint.

Recover from Reconcile Loop drift

Capture the current state with kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}', then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.

Key takeaway: Accept the trade-off consciously: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.

How it works, step by step

Step 1 of 4
Source author

1. Choose the source of truth

Version the source and describe the review, render, and reconciliation boundary: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Operator contract → owned state
Key numbers at this step
Goal
Build operators that continuously reconcile custom resources to desired state.
Owner
Operator

When to use it & trade-offs

What it is

Build operators that continuously reconcile custom resources to desired state. An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Why it matters: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever. The invariant at risk is specific: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion. The quickest fact check before changing the design is kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}'.

When to reach for it

  • Use Operator to enforce this invariant: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.
  • Use Reconcile Loop evidence from kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' in reviews and incident timelines. Build operators that continuously reconcile custom resources to desired state.
  • Choose the platform operator workflow route only when this cost is justified by governance or scale: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.

When to avoid or be careful

  • Avoid assuming Operator is complete after YAML submission; the required behavior is concrete: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.
  • Avoid treating the next symptom as random; check the owner and state with kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' first: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.
  • Avoid adopting a heavier platform wrapper before measuring its cost: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.

Native, manual, and managed paths for Operator

Versioned declarative source
Best for: Build operators that continuously reconcile custom resources to desired state. A concrete incident check is kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}'.

Strengths: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Watch out: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency. Recovery must also recognize this signal: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.

Imperative cluster edit
Best for: Quickly testing the Reconcile Loop assumption with kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}'; the expected invariant is: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Strengths: kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' gives immediate feedback without first building a platform layer.

Watch out: A manual change can hide drift, and unlike Operator, it does not make this symptom self-documenting: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.

Platform operator workflow
Best for: Teams that need Kubebuilder integrated with guardrails; the evidence path is kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}'.

Strengths: Platform controls can wrap this exact behavior in policy or dashboards: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.

Watch out: The added platform ownership buys value at this cost: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.

Interview signals & numbers to know

When this topic comes up

  • Interview anchor: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.
  • Trace Operator to Kubebuilder through Reconcile Loop; the invariant is: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.
  • Recognize the symptom: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.
  • Justify the cost: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.
  • Verify with kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' instead of only inspecting YAML.

Benchmarks & rules of thumb

4 -
loop phases: observe, compare, act, record
1 -
reconcile should be idempotent at each retry
0 -
business side effects should depend on an ordered queue without deduplication

Common mistakes & follow-ups

Common interview mistakes

  • Debugging only the child object misses the Operator owner contract: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion.
  • Ignoring this telltale condition leads to unrelated changes: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever.
  • Repeating kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}' without an owner for remediation wastes retry cost. Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.

Likely interviewer follow-ups

  • How would API output and runtime evidence prove this behavior: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion?
  • Which owner object, logs, and Events would you inspect for this symptom-A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever-?
  • At what threshold would this cost become unacceptable: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency?
Interview tip: Interview sequence: state the invariant, run kubectl get pods -n operators; kubectl logs deploy/db-operator -n operators; kubectl get db app-db -o jsonpath='{.status}', name the failure, then justify the cost. Invariant: An operator watches custom resources, computes desired external or Kubernetes state, performs idempotent work, updates status, and uses finalizers only for cleanup that must outlive deletion. Failure: A non-idempotent reconcile repeats side effects on retries, and a missing finalizer status update can trap a resource in Terminating forever. Cost: Operators encode expert operations but controller bugs, API churn, and external credentials turn the automation into a production dependency.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Kubernetes Operators & The Controller Reconciliation Loop (Kubebuilder / Operator SDK) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Custom Resource Definitions (CRDs) & Extending the Kubernetes API
Next topic
Validating & Mutating Admission Webhooks + CEL Policies