BLOG20c: What is the Function of
BLOG12: What is the function of Controller? What is the concept of watch?
🟦 How does a controller know when a new CRD object is created?
🟩 1. Kubernetes API provides a Watch endpoint for every resource
greetings.example.com/v1GET /apis/example.com/v1/namespaces/<ns>/greetings?watch=true🟧 2. A Controller uses the Watch API to get events (add/update/delete)
Events it receives:
🟦 3. Controllers use “informers” to efficiently watch objects
🟨 4. Does Kubernetes API help? YES — the API server is the hub
The flow:
✔️ Step 1: You apply a CRD
✔️ Step 2: You create a CRD instance
✔️ Step 3: Controller opens a watch request
✔️ Step 4: Controller reconciles
✔️ Step 5: Status updates
🟥 5. Think of the API server as a “Message Broker"
Component
Role
🟩 6. CRDs automatically get WATCH support — no extra code required
🟧 7. In simple words
✔️ API server sends notifications through WATCH streams
✔️ Controller libraries (informers) subscribe to those streams
✔️ CRDs inherit watch behavior from Kubernetes API machinery
✔️ Controller code reacts whenever API server reports an event
⭐ FINAL EXPLANATION (SHORT VERSION)
How does a controller detect new CRD objects?
How do Kubernetes watches differ from generic webhooks?
🟦 1️⃣ Is WATCH like a webhook?
Short answer:
🔵 WATCH (Kubernetes Watch API)
Example:
🔴 Webhook
🟢 WATCH vs Webhook (Simple Comparison)
Feature
WATCH
Webhook
Summary:
🟩 2️⃣ The Reconciliation Loop (The Soul of Kubernetes)
🟧 WHAT does Reconciliation mean?
“Try to make actual state = desired state. Repeat forever.”
🟦 Let’s break it down:
A. USER applies desired state
B. CONTROLLER sees the event via WATCH
C. CONTROLLER checks the cluster
D. CONTROLLER takes action
E. Controller updates STATUS
F. REPEAT FOREVER
🟨 Reconcile Loop: Simple Example (Concept Demo)
🟧 Controller Pattern in One Sentence
🟩 Reconciliation Loop (Diagram)
🟦 ⭐ FINAL SUMMARY
Is Watch like webhook?
What is Reconciliation Loop?
Does the Kubernetes API server open a persistent streaming connection to controllers, and can you directly see this?**
🟦 1. What is the “stream connection” between API server → Controller?
✔️ HTTP/1.1 Chunked Transfer Encoding
✔️ Long-lived HTTP Watch stream
🟧 2. Can you SEE this connection?
❌ You CANNOT normally see the watch connection inside the cluster by default
✔️ You CAN see:
A. API server metrics showing WATCH connections
B. Inspect the controller logs
C. Using tcpdump (advanced)
D. Using lsof inside controller container
lsof inside controller containerE. APIServer access logs (in non-managed clusters)
❗ Important:
🟨 3. How to manually see an API Watch stream (demo)
A. Watch Pods:
B. Raw HTTP Watch using curl:
🟩 4. NOW — Detailed Concept: How Controllers Use Watch + Reconcile Loop
STEP 1 — Open Watch
STEP 2 — Receive event
STEP 3 — Queue the event
STEP 4 — Reconcile
STEP 5 — Fix differences
STEP 6 — Update status
STEP 7 — Repeat forever
🟦 ⭐ Final Summary
✔️ The controller knows new CRD objects through WATCH streams
✔️ This is a long-running HTTP streaming connection
✔️ Implemented by the Kubernetes API server
✔️ Controllers subscribe using client-go informers
✔️ You can observe streams with:
Does HTTPS Support Long-Lived Streaming Connections for Kubernetes Watch?
🟦 1. WATCH is built on top of standard HTTPS (HTTP/1.1 long-lived streaming)
🟩 2. How HTTPS supports this?
✔️ Persistent connections (Connection: keep-alive)
Connection: keep-alive)✔️ Chunked Transfer Encoding (Transfer-Encoding: chunked)
Transfer-Encoding: chunked)✔️ Unlimited response time
✔️ Streaming partial responses
Example raw stream:
SSL/TLS does NOT block this.
🟧 3. Why HTTPS doesn’t break streaming
🟨 4. Let’s see a real WATCH request from API server
HTTP headers:
🟪 5. Why not use WebSockets instead?
❌ WebSockets add protocol overhead
❌ Harder to maintain reconnect logic
❌ Harder to debug and proxy
❌ Not compatible with all HTTP intermediaries
🟥 6. Can we manually observe HTTPS streaming?
🟫 7. How client-go handles streaming under TLS
⭐ FINAL SUMMARY
✔️ Kubernetes WATCH uses HTTP/1.1 streaming over TLS (HTTPS)
✔️ HTTPS fully supports:
✔️ TLS does NOT prevent streaming
Last updated