> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes API Reconciliation

> Explains Kubernetes reconciliation loop, controllers, informers, API server, self-healing, custom controllers and operators, and design best practices for building resilient declarative platform automation.

Welcome. This lesson explains how the Kubernetes API, controllers, informers, and reconciliation loops work together to provide declarative, self-healing infrastructure. This material is essential for platform engineers and appears frequently in platform certification curricula. By the end you'll understand the core pattern that powers Kubernetes: observe → compare → act → repeat.

<Callout icon="lightbulb" color="#1CB2FE">
  This guide covers: the reconciliation loop, controller/informer architecture, node health and self-healing, custom controllers/operators, and design best practices for building resilient controllers. Use this as a conceptual reference for exam prep and real-world platform design.
</Callout>

Why this matters

* Certification exams commonly test imperative vs. declarative approaches and scenarios where the reconciliation model is the correct answer.
* For platform teams (for example, "Sparkle Pony Ranch"), the Kubernetes API provides a single, consistent interface used by `kubectl`, UIs, controllers, and custom automation.
* Everything — from a `kubectl` listing to an operator action — goes through the same API surface.

Example API requests that interact with the same server:

```bash theme={null}
GET    /api/v1/namespaces/pony-prod/pods
POST   /apis/apps/v1/namespaces/pony-prod/deployments
```

Kubernetes objects: desired vs. current state
Kubernetes resources (Pods, Deployments, ConfigMaps, CRs) carry metadata and a `spec` that declares desired state. Controllers (the control plane) continuously move the cluster toward that desired state and report observed state in a `status` section.

Example Deployment — desired state in `spec`, observed state in `status`:

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pony-spawner
  namespace: magical-creatures
spec:  # Desired state
  replicas: 3
  template:
    spec:
      containers:
      - name: pony-spawner
        image: registry.spr.com/pony-spawner:v2.1.0

status:  # Current state (managed by Kubernetes)
  readyReplicas: 3
  conditions: [...]
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-objects-describing-what-you-want.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=cbfe28f6fc1e6e7acf32fc87f8ccf035" alt="A presentation slide titled &#x22;Kubernetes Objects – Describing What You Want&#x22; showing a circular avatar labeled &#x22;Phuong&#x22; and a &#x22;Sparkle Pony Ranch&#x22; tag. Three short points explain declaring the desired state (e.g., 3 replicas of pony-spawner), leaving scheduling/failure handling to Kubernetes, and using declarative configuration." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-objects-describing-what-you-want.jpg" />
</Frame>

The reconciliation loop (observe → compare → act → repeat)
At the heart of Kubernetes is the reconciliation loop. For each resource, controllers continuously converge the cluster’s current state toward the declared desired state. The common steps are:

1. Observe current state (via API server and informers).
2. Compare current vs desired state.
3. Act to correct drift (create, update, or delete resources).
4. Repeat until state converges.

This is an event-driven pattern: controllers react to watch events rather than relying solely on frequent polling. Informers provide efficient event delivery plus local caching. Controllers also use periodic resyncs or requeues to guard against missed events — reconciliation is event-driven and eventually consistent.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/reconciliation-observe-compare-act-repeat.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=033f48c35a890a22cb4799d761909417" alt="A slide titled &#x22;Reconciliation – Continuously Converging to Desired State&#x22; showing a colorful circular flow diagram with four steps labeled Observe, Compare, Act, and Repeat. A footer note reads that reconciliation enables self-healing and drift correction without human intervention." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/reconciliation-observe-compare-act-repeat.jpg" />
</Frame>

Controllers, informers, and work queues — responsibilities

* Controllers implement reconciliation logic: they define the business rules for a resource type.
* Informers watch the API server, maintain a local cache, and emit events on changes.
* Work queues buffer and de-duplicate keys so controllers can handle spikes and retries without being overwhelmed.

When a resource changes, informers typically enqueue an object key. The controller reconciler reads the current observed state (from cache or API), computes desired changes, and issues API requests to reconcile differences.

Key implications:

* Slow reaction is usually an informer/queue or processing issue, not a polling setting.
* Platform teams can extend Kubernetes by adding custom controllers to automate provisioning, SLO-based scaling, and other platform concerns.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-controllers-replicaset-deployment-service-namespace.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=fab9fa4d73bd25c8870ee76aaecce9b0" alt="A slide titled &#x22;Kubernetes Built-In Controllers at Work.&#x22; It lists four controllers — ReplicaSet, Deployment, Service, and Namespace — each with a short description of its responsibility." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-controllers-replicaset-deployment-service-namespace.jpg" />
</Frame>

Common controller types (quick reference)

| Controller | Purpose | Example behavior |
| - | - | - |
| ReplicaSet | Maintain a set number of Pod replicas | Recreate deleted pods to match `replicas` |
| Deployment | Manage rolling updates/rollbacks | Create ReplicaSets and orchestrate rollouts |
| Service | Provide stable network access | Manage Endpoints and cloud load-balancers |
| Namespace | Lifecycle of logical collections | Garbage-collect resources when namespace is deleted |

Controller chains of responsibility
Controllers often work in chains. For example, a Deployment controller creates ReplicaSets; a ReplicaSet controller creates Pods. Each controller focuses on a resource type and relies on the API server and informers to coordinate.

Node controller and node health
The node controller manages node lifecycle and health signals:

* Tracks node heartbeats and readiness (via Node status and Lease objects from kubelet).
* Updates node status and conditions (e.g., Ready, MemoryPressure, DiskPressure).
* Tracks capacity and resource pressure that influence scheduling.

Typical node conditions:

```yaml theme={null}
conditions:
- type: Ready
  status: "True"
- type: MemoryPressure
  status: "False"
- type: DiskPressure
  status: "False"
```

These conditions affect scheduling decisions and self-healing behaviors across the cluster.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/self-healing-automatic-recovery-kubernetes.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=39496ad3c56ddcf1fb67f6b53cd4c2c2" alt="A slide titled &#x22;Self-Healing – Automatic Recovery From Failures&#x22; showing four self-healing mechanisms: Pod Restart, Pod Replacement, Service Recovery, and Node Drain. Each box has a brief note (e.g., failed containers restarted, crashed pods recreated by ReplicaSet, endpoints updated when pods are unhealthy, workloads moved when nodes become unavailable)." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/self-healing-automatic-recovery-kubernetes.jpg" />
</Frame>

Self-healing examples

* Pod restart: kubelet restarts crashed containers.
* Pod replacement: ReplicaSets recreate pods to maintain desired replicas.
* Service recovery: Services/Endpoints update when pod health changes.
* Node drain/migration: workloads are relocated when nodes are removed or upgraded.

Custom controllers and operators
Custom controllers let platform teams automate multi-step workflows and integrate with external systems. Operators extend this model by combining Custom Resource Definitions (CRDs) with domain-specific logic (e.g., backups, scaling, failover) so the controller embodies operational best practices.

Operators are frequently covered in platform exams — their role is to codify expert operational behavior into automated lifecycle management.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/custom-controllers-platform-automation-slide.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=6c35240f48076624f2295d1208d9863c" alt="A presentation slide titled &#x22;Custom Controllers – Platform-Specific Automation.&#x22; It shows four colorful rounded boxes labeled &#x22;Domain-Specific Logic,&#x22; &#x22;Custom Resources,&#x22; &#x22;Complex Workflows,&#x22; and &#x22;Platform Integration.&#x22;" width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/custom-controllers-platform-automation-slide.jpg" />
</Frame>

API server — the control plane gateway
The API server is the cluster’s RESTful gateway:

* Validates and authorizes all requests.
* Runs admission control plugins (mutating and validating webhooks).
* Persists cluster state to etcd.

Best practice: always interact with the API server rather than modifying etcd directly so validation, admission, and auditability are preserved.

<Callout icon="warning" color="#FF6B6B">
  Do not modify etcd directly. Controllers and automation should submit changes through the API server to ensure validation, admission control, and persistence workflows are honored.
</Callout>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-api-server-components.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=cc0c46544ccd7c439b39d3da5bfd9208" alt="A slide diagram titled &#x22;API Server – The Heart of Kubernetes Control Plane&#x22; showing four components: REST API Gateway, Authentication & Authorization, Admission Control, and etcd Interface. Each box has a brief description of its role, and a note below about controller integration watching the API server for changes." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-api-server-components.jpg" />
</Frame>

Informers and efficient monitoring
Informers optimize resource monitoring by performing an initial list and then opening a watch:

1. Watch the API server for changes.
2. Maintain a local cache to minimize API traffic.
3. Emit events and enqueue keys for controllers.
4. Use work queues to handle spikes, retries, and deduplication.

Because informers are event-driven and cache state, they avoid expensive polling of large object sets.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/informers-architecture-watch-cache-events-queues.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=96dff763e676974e931792511a29fa16" alt="A slide titled &#x22;Informers – Efficient Resource Monitoring&#x22; showing an &#x22;Informer Architecture&#x22; diagram with four numbered components: Watch API, Local Cache, Event Processing, and Work Queues. Each box contains a brief description of its role (real-time updates, client-side caching, handling events, and buffering/processing)." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/informers-architecture-watch-cache-events-queues.jpg" />
</Frame>

State management, drift detection, and resilience
Controllers detect and correct configuration drift — when actual cluster state diverges from desired state. Robust controllers handle:

* Transient failures: retries with backoff and idempotent operations.
* Rate limiting: respect API server throttle and implement retry logic.
* Resource conflicts: use optimistic concurrency (e.g., `resourceVersion`) and retry on conflict.
* External dependency failures: graceful degradation and accurate status reporting.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/state-management-drift-detection-auto-fix.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=f8122978515a33cf82c2ccbeffc43c7b" alt="A presentation slide titled &#x22;State Management – Desired vs Current State&#x22; showing &#x22;Drift Detection and Reliability&#x22; with a bullet: &#x22;Controllers detect and fix manual changes automatically.&#x22;" width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/state-management-drift-detection-auto-fix.jpg" />
</Frame>

Design guidance for building custom controllers
If you implement controllers or operators, follow these design principles:

* Make reconciliation idempotent (safe to re-run).
* Reconcile against the current observed state, not just event payloads.
* Report `status` on custom resources to expose progress and health.
* Use informers and a local cache to reduce API load.
* Implement retries, exponential backoff, and graceful error handling.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/resilient-controllers-failure-types.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=080ed364fbc1070bd0b3255d015358f9" alt="A slide titled &#x22;Resilient Controllers — Handling Failures Gracefully.&#x22; It lists four common failure types — Transient Failures, Rate Limiting, Resource Conflicts, and External Dependencies — with brief examples like network issues, API throttling, conflicting controllers, and cloud APIs/databases." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/resilient-controllers-failure-types.jpg" />
</Frame>

Key takeaways

* The Kubernetes API server is the consistent REST interface used by `kubectl`, dashboards, controllers, and automation.
* The reconciliation loop (observe → compare → act → repeat) is the fundamental pattern enabling declarative, self-healing systems.
* Controllers implement reconciliation logic; informers provide efficient event-driven caching and watches.
* Custom controllers and operators let you extend Kubernetes with domain-specific automation and operational expertise.
* Always interact with the API server and design controllers to be idempotent, observable, and resilient.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-api-reconciliation-controllers.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=535f907525c28a7867c904c86040a46c" alt="A slide titled &#x22;Key Takeaways – API and Reconciliation&#x22; showing three colored cards summarizing: Kubernetes API (RESTful interface), Reconciliation Loop (continuous process comparing desired vs current state), and Controllers (software implementing reconciliation logic)." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/kubernetes-api-reconciliation-controllers.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/0r3GTobZImleUlJh/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/api-reconciliation-controllers-operators-monitoring-platform.jpg?fit=max&auto=format&n=0r3GTobZImleUlJh&q=85&s=72a0751634c8298d363913694dbb77e0" alt="A slide titled &#x22;Key Takeaways – API and Reconciliation&#x22; showing four colorful cards numbered 05–08 that summarize: Custom Controllers, Operators, Efficient Monitoring, and Platform Integration. Each card includes a short description about extending Kubernetes, encoding domain expertise, scalable event processing, and declarative infrastructure." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-4-Platform-APIs-and-Provisioning-Infrastructure/Kubernetes-API-Reconciliation/api-reconciliation-controllers-operators-monitoring-platform.jpg" />
</Frame>

This concludes the lecture on API and reconciliation. Keep these patterns in mind — they form the foundation of platform behavior in exams and production Kubernetes operations.

Further reading and references

* [Kubernetes API Concepts](https://kubernetes.io/docs/concepts/overview/kubernetes-api/)
* [Controller Pattern and Operator Frameworks](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
* [Client-go Informers and Caching](https://pkg.go.dev/k8s.io/client-go/informers)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-cloud-native-platform-engineering-associate-cnpa/module/7b8d1069-510d-48c6-b656-7573a193aeff/lesson/1ec64726-d584-4932-825b-1cd3385e3f0b" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.