Best Practices

Extending Kubernetes Explained: Custom Resources, Controllers, Operators and Admission Webhooks

November 15, 2026 Kubezilla Team 10 min read
Terminal window showing kubectl get crds with the title Extending Kubernetes: CRDs, Controllers, Operators and Webhooks

Most people meet Kubernetes through Pods, Deployments and Services. Spend a little more time with it and you notice that many of the tools you install, such as Argo CD, cert-manager, Prometheus Operator or Crossplane, add their own object types to the cluster. You run kubectl get on them just like built-in resources. That is not a trick. Kubernetes was designed to be extended, and the same patterns that power the core of the system are open to everyone.

This guide explains the main ways to extend Kubernetes: custom resources, controllers, operators and admission control. You will see how they fit together, when to use each one, and how to try them on a test cluster using examples from the official documentation. If you want a refresher on how the API server, etcd and the control plane work first, read our deep dive into how Kubernetes works.

The extension points at a glance

The Kubernetes documentation groups extensions into a few families. Each one plugs into a different part of the system:

  • Compute, storage and networking plugins. Network plugins (CNI), storage drivers (CSI) and device plugins let nodes use new kinds of networks, disks and hardware such as GPUs.
  • API extensions. Custom resources, defined with a CustomResourceDefinition (CRD), and the API aggregation layer add new object types to the Kubernetes API.
  • Admission control. Admission webhooks and CEL based admission policies inspect, change or reject requests before objects are stored.
  • Scheduling. The scheduling framework lets you add plugins that influence where Pods run.
  • Client side tools. Client libraries let your own programs talk to the API, which is how controllers and operators are built.

Custom resources and CRDs

A resource is an endpoint in the Kubernetes API that stores a collection of objects of one kind, such as Pods. A custom resource is a resource that is not part of a default install. On its own, a custom resource only stores and returns structured data. When you pair it with a custom controller, it becomes a true declarative API: you write down the desired state and the controller keeps the real world in sync with it.

There are two ways to add custom resources. A CRD is the simple route: you create one object that describes the name and schema, and the API server handles storage, validation, RBAC and watch for you. No programming is needed for the resource itself. The aggregation layer is the advanced route: you write and run your own API server, and the main API server proxies requests to it. Aggregation gives you custom storage and extra subresources such as logs or exec, but you must build, run and maintain another service. The docs recommend CRDs for most cases.

Not every piece of configuration needs a custom resource. The official guidance says a ConfigMap is a better fit when there is already a well known file format, the whole configuration fits in one key, and a program in a Pod simply reads it. A custom resource makes sense when you want kubectl and client library support, you are building automation that watches the object and creates other objects, and you want the familiar spec, status and metadata layout. The docs also warn against using custom resources to store application or end user data.

Hands-on: create your first CRD

Prerequisites: a test Kubernetes cluster (kind, minikube or similar) and kubectl configured to talk to it. The example below comes straight from the official CRD task page. It defines a new CronTab kind in the stable.example.com group. Save it as resourcedefinition.yaml:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

Note the naming rule in the comments: metadata.name must be <plural>.<group>, so here it is crontabs.stable.example.com. Create the CRD:

kubectl apply -f resourcedefinition.yaml

Now the API server serves a new endpoint for CronTab objects. Save this custom object as my-crontab.yaml and apply it:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
kubectl apply -f my-crontab.yaml
kubectl get crontab

You can also use the short name ct defined in the CRD. To see the new type among all API resources, filter by its group:

kubectl api-resources --api-group=stable.example.com

CRDs can do much more than this minimal example. The schema must be structural, which means every field declares a type, and unknown fields are pruned by default. Validation rules written in the Common Expression Language (CEL) through x-kubernetes-validations are stable since Kubernetes v1.29, so you can express checks like “minReplicas must not exceed replicas” without a webhook. You can also enable the status and scale subresources and add extra columns to kubectl get output with additionalPrinterColumns.

Keep in mind that nothing happens yet. Kubernetes stores the CronTab object, but no program acts on it. That is the job of a controller.

Controllers: the control loop behind everything

A controller is a loop that never stops. It watches the state of the cluster, compares it to the desired state, and makes or requests changes to close the gap. The Kubernetes docs compare it to a thermostat: you set a target temperature, the thermostat reads the room, and it switches the heating on or off until the two match.

Every built-in object works this way. When you create a Job, the Job controller does not run Pods itself. It asks the API server to create Pods, other components schedule and run them, and when the work is done the controller updates the Job status. Controllers talk to the API server, not to each other, which keeps the design loosely coupled. The same pattern drives the objects covered in our guide to Kubernetes workloads.

Operators: packaging operational knowledge

An operator is a custom resource plus a controller that encodes what a human operator knows about running a specific application. The Kubernetes docs list typical tasks operators automate: deploying an application on demand, taking and restoring backups, handling upgrades together with related changes such as database schemas, publishing a Service for apps that cannot discover the Kubernetes API, and choosing a leader for software that has no leader election of its own.

The docs walk through an imaginary SampleDB operator. When you create a SampleDB object, the controller sets up PersistentVolumeClaims, a StatefulSet and an initial configuration Job. When you delete it, the operator takes a snapshot first and then removes the StatefulSet and volumes. It also runs regular backups and can start upgrade Jobs when it finds an old version. Users only interact with the high level object, for example with kubectl get SampleDB.

You can write operators in many languages. The official page lists third party tools including kubebuilder, the Operator Framework, Java Operator SDK, Kopf for Python, kube-rs for Rust, KubeOps for .NET, Metacontroller and shell-operator. Before writing your own, check OperatorHub.io, a community catalog of ready made operators.

To get a feel for the workflow, the kubebuilder quick start scaffolds a project, generates an API type and controller, installs the CRDs into your cluster and runs the controller locally. It needs Go, Docker, kubectl and access to a cluster. The commands from the kubebuilder book are:

kubebuilder init --domain my.domain --repo my.domain/guestbook
kubebuilder create api --group webapp --version v1 --kind Guestbook
make install
make run

Your job is then to fill in the reconcile function: read the custom object, look at what exists in the cluster, and create, update or delete resources until they match.

Admission control: webhooks and CEL policies

Admission controllers intercept requests to the API server after authentication and authorization, but before the object is saved. They run in two phases. Mutating controllers run first and may change the object, for example to add defaults or inject a sidecar. Validating controllers run second and can only accept or reject. If any controller in either phase rejects the request, the whole request fails.

There are two ways to add your own admission logic:

  • Admission webhooks. The API server sends an AdmissionReview over HTTPS to a service you run, registered with a MutatingWebhookConfiguration or ValidatingWebhookConfiguration. Webhooks can run any code, but they are another service to keep healthy. The docs advise keeping them fast (the timeout is 1 to 30 seconds and defaults to 10), making mutating webhooks idempotent, and choosing failurePolicy carefully. The default, Fail, rejects requests when the webhook cannot be reached.
  • Admission policies in CEL. ValidatingAdmissionPolicy (stable since v1.30) and MutatingAdmissionPolicy (stable since v1.36) run inside the API server with no external call. They are easier to operate and are the first choice for simple rules.

Here is the first example from the ValidatingAdmissionPolicy docs. It rejects Deployments with more than five replicas:

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: "demo-policy.example.com"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:   ["apps"]
      apiVersions: ["v1"]
      operations:  ["CREATE", "UPDATE"]
      resources:   ["deployments"]
  validations:
    - expression: "object.spec.replicas <= 5"

A policy does nothing until a binding applies it. This binding enforces it in namespaces labeled environment: test:

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: "demo-binding-test.example.com"
spec:
  policyName: "demo-policy.example.com"
  validationActions: [Deny]
  matchResources:
    namespaceSelector:
      matchLabels:
        environment: test

Admission control is a key layer in the Kubernetes security best practices checklist.

Choosing the right extension point

A simple way to decide:

  • You only need to pass configuration to an app: use a ConfigMap or Secret, not a CRD.
  • You want a new, declarative object that people manage with kubectl and GitOps: use a CRD, and add CEL validation rules to its schema.
  • You need something to act on that object over time: write a controller, and if it carries real operational knowledge, treat it as an operator.
  • You need custom storage or subresources like logs or exec: consider the aggregation layer.
  • You want to enforce or default rules on any object: try a ValidatingAdmissionPolicy or MutatingAdmissionPolicy first, and use a webhook only when CEL is not enough.
  • Before building anything, check OperatorHub.io and the CNCF Landscape for an existing project.

These building blocks are also the foundation of internal developer platforms, where many tools ship their own CRDs and controllers. See our guide to platform engineering on Kubernetes for how teams put them together.

Key takeaways

  • Kubernetes is extensible by design, and its own built-in resources use the same patterns you can use.
  • A CRD adds a new object type to the API with no extra server to run. It stores data; a controller gives it behavior.
  • Controllers are endless loops that move the current state toward the desired state through the API server.
  • An operator is a CRD plus a controller that automates the work a human would do to run an application.
  • Admission control runs mutating then validating checks before objects are stored. Prefer CEL based admission policies for simple rules and webhooks for complex ones.
  • Start with the simplest tool that works, and look for existing operators before writing your own.

Sources

Kubernetes docs: Extending Kubernetes, Custom Resources, Extend the Kubernetes API with CustomResourceDefinitions, Controllers, Operator pattern, Admission Control, Dynamic Admission Control, Validating Admission Policy, Mutating Admission Policy, kubectl api-resources reference, The Kubebuilder Book: Quick Start, OperatorHub.io.

Leave a comment