How knative/serving works
Project type and purpose
• Knative Serving is a cloud-native serverless platform built on Kubernetes.
• It provides custom resource definitions (CRDs) for Service, Configuration, Revision, Route, DomainMapping, etc., and control-plane components that reconcile those resources.
• It also includes data-plane sidecars (queue-proxy) and control-plane microservices for autoscaling, activations, webhooks, domain defaulting, and schema tweaks.
File structure for architectural clues
• cmd/… directories each compile into a distinct microservice binary (activator, autoscaler, controller, webhook, default-domain, queue-proxy).
• pkg/reconciler/… contains reconcilers for each CRD type (Configuration, Revision, Route, Service, DomainMapping, etc.).
• pkg/autoscaler/… implements custom autoscaling logic.
• pkg/queue/… implements the queue-proxy sidecar for user workload pods.
• config/… holds Kubernetes YAMLs for CRD definitions, RoleBindings, Deployments, Webhooks.
• Test directories illustrate integration points with Kubernetes API and ingress.
Extract additional insights from the README
• Core features: automatic “scale-to-zero,” container routing, snapshots, custom domain mappings, extensibility via webhooks.
• The spec and documentation folders describe CRD schemas and the control-plane interactions.
Main components
a. Control Plane microservices (deployed as Kubernetes Deployments):
• API Server (Kubernetes) with Serving CRDs.
• Knative Webhook (Validating & Defaulting).
• Knative Controller (reconciles Service, Configuration, Route, ServerlessService, Certificate, etc.).
• Autoscaler / Autoscaler-HPA (monitors metrics, issues scale up/down requests).
• Activator (intercepts HTTP requests when pods are scaled to zero).
• Default-Domain service (injects cluster domain into Routes).
• Schema-Tweak (patches generated YAMLs as needed).
b. Data Plane components:
• User workload Pods, each with a sidecar queue-proxy (pkg/queue) to manage traffic flow, readiness, and observability.
c. External services:
• Ingress/Gateway layer (Istio / Kourier / Contour) for north-south routing.
• Certificate manager (e.g., cert-manager) for TLS provisioning.
• DNS / External domain providers.
d. Storage & state:
• etcd (backing the Kubernetes API Server).
• Kubernetes HPA resources (if using autoscaler-HPA).
Relationships and data flows
• Developers kubectl apply a Service CR → goes to Kubernetes API Server.
• Webhook mutates defaults (e.g., revision timeout, service account) and validates.
• Controller watches CR events → creates/updates Configuration, Revision, Route, ServerlessService, Certificates.
• Controller deploys Revision Pods (with queue-proxy).
• Autoscaler watches Revision metrics (via Prometheus HTTP scrape or custom stats) → decides desired replica count → updates Deployment or HPA.
• Activator stands in front of pods scaled to zero: traffic arrives from ingress → Activator buffers and triggers cold start.
• Ingress/Gateway routes HTTP traffic to either Activator (if no pods) or directly to queue-proxy sidecar.
• Queue-proxy forwards traffic to user container and emits metrics.
• Default-Domain microservice updates domain mappings for Routes.
• Schema-Tweak modifies YAML for config-management pipelines (optional).
Key architectural patterns & design principles
• Controller pattern (event-driven reconciliation loops via informers).
• Sidecar pattern (queue-proxy in each Revision Pod).
• Webhooks for validation & defaulting.
• CRD-based extensibility (each component focuses on its resource).
• Event-driven scaling (Autoscaler responds to metrics, Activator intercepts on cold start).
• Separation of control plane (knative components) vs data plane (queue-proxy & user container).