Kubernetes Extensibility: CRDs, Operators, Webhooks, and Drivers
Minimal core vs. OpenStack’s “big tent”
Production clusters rarely operate in isolation: they must connect to enterprise authentication, ticketing, logging, monitoring, and team-managed services like databases. During its peak, OpenStack used a “big tent” model that pulled extra services (DBaaS, VPNaaS, DRaaS) directly into core releases—making OpenStack difficult to extend, with many extra components later abandoned.
Kubernetes deliberately takes the opposite approach: keep K8s Core minimal and stable, avoid “vendor code dumps”, and expose clean extension interfaces around the perimeter.
CRDs and the Operator pattern
Custom Resource Definitions (CRDs)
A CRD registers a brand-new declarative resource type on kube-apiserver at /apis/GROUP/VERSION/RESOURCETYPE/NAME, supporting standard REST verbs (GET, CREATE, UPDATE, LIST, DELETE, PATCH, WATCH). By defining a CRD, developers automatically inherit:
- Consistent declarative YAML syntax and built-in API versioning/discovery
- Persistence in
etcdand serving viakube-apiserver - Access control through RBAC
Operators
A CRD only stores data; an Operator is the custom controller application that watches a Custom Resource (CR Spec), reconciles real-world infrastructure (CR State), and reports results back into status. (Operator scaffolding is commonly generated with OperatorSDK [Golang, Ansible, Helm] or Kubebuilder.)
Two examples from the slides show why this matters:
- “Student as a Service” (PDF p. 69 / printed 77): Creating a
StudentCR causes an Operator to add the student to the lab DB, inject SSH public keys into VMs, and create a Kubernetes namespace; deleting the CR revokes access and archives data. - “Add a Database” — separation of concerns (PDF pp. 70–72 / printed 78–80): Application developers declare a
DatabaseCR and read the endpoint from itsstatus. The database team’s Operator decides whether to fulfill it using a Cloud Service, a Kubernetes Deployment, or a Legacy server, decoupling app code from DB implementation.
API Aggregation Layer (APIService)
CRDs support only standard CRUD/WATCH verbs and etcd storage. When a feature requires custom API verbs or non-etcd live backends—such as opening a VM console in KubeVirt or querying real-time metrics for HPA—Kubernetes provides APIService objects via the API Aggregation Layer. kube-apiserver simply forwards matching API requests to a custom server running in Pods behind a Service, leaving API handling and persistence entirely to that extension.
API Lifecycle Hooks and Admission Webhooks
Every request entering kube-apiserver traverses a sequential pipeline before reaching etcd (PDF p. 77 / printed 86):
API HTTP(S) ─► Authn ─► Authz ─► Mutating Admission ─► Schema Validation ─► Validating Admission ─► etcd- External Authn / Authz: Kubernetes provides no built-in User Catalog (such as Keycloak); it integrates with LDAP, OpenID Connect (OIDC), or custom Webhooks (e.g., Auth0).
- Mutating Admission (
MutatingWebhookConfiguration): Modifies objects before persistence (e.g., injecting a sidecar container or enforcing default fields). Runs before Schema Validation. - Validating Admission (
ValidatingWebhookConfiguration): Accepts or rejects objects based on custom policy (e.g., blocking Pods missing required labels). Runs after Schema Validation.- Critical-path warning: Each webhook targets a Kubernetes Service presenting a valid TLS certificate and sits directly in the critical path of the API request, adding latency to every matching API call.
- Custom Finalizers & Audit Webhooks: Finalizers act as asynchronous pre-delete hooks (string markers preventing hard deletion until cleanup completes); Audit Webhooks stream API Server access logs to external analytics systems (such as Elasticsearch).
Custom Schedulers and standard Driver Interfaces (CRI, CSI, CNI)
- Custom Scheduler: Deployed as a normal Deployment in the cluster. Pods opt in via
spec.schedulerName; the custom scheduler watches matching unassigned Pods and setsspec.nodeNameso that node’skubeletstarts them. - Three standardized driver interfaces:
| Interface | Role | Key implementation details |
|---|---|---|
| CRI (Container Runtime Interface) | Runtime execution & image management | Imperative gRPC interface (kubelet → CRI shim → runtime); also supports exec/log/attach. Separates Sandbox (isolation + resource limits: e.g., Kata Containers [VT-x], CRI-O, gVisor) from Container (workload) |
| CSI (Container Storage Interface) | Persistent volume & StorageClass backends | Implemented by storage vendors outside K8s core |
| CNI (Container Network Interface) | Pod networking & NetworkPolicy enforcement | Abstracts underlying cluster networking (overlays, native routes, firewalling) |
Retrieval
- You want to add (a) a declarative
LabStudentobject that provisions namespaces and SSH keys, and (b) a streaming VM console endpoint for KubeVirt. Which uses a CRD + Operator and which usesAPIService, and why?
LabStudentfits a CRD + Operator because standard CRUD/WATCH +etcdstorage suffice for declarative provisioning. The streaming VM console requires custom non-CRUD verbs and live interaction, which exceeds CRD capabilities and requires anAPIService(API Aggregation Layer). - In what order do
MutatingandValidatingAdmission Webhooks execute relative to Schema Validation, and what operational risk must you manage when deploying them?
Mutating Admission runs before Schema Validation (so injected defaults/sidecars are validated), and Validating Admission runs after Schema Validation beforeetcdpersistence. Both sit in the API Server’s critical path and require valid TLS certificates—so a slow or unreachable webhook directly delays or blocks cluster API requests.
Source: Lecture 11 - Kubernetes, PDF pages 58–84 (printed slides 66–95).