⎈ k8s knowledge compiler

Custom Resources [page]deterministic

concepts

*Custom resources* are extensions of the Kubernetes API. This page discusses when to add a custom resource to your Kubernetes cluster and when to use a standalone service. It describes the two methods for adding custom resources and how to choose between them.

## Custom resources

A *resource* is an endpoint in the [Kubernetes API](/docs/concepts/overview/kubernetes-api/) that stores a collection of [API objects](#gloss:object) of a certain kind; for example, the built-in *pods* resource contains a collection of Pod objects.

A *custom resource* is an extension of the Kubernetes API that is not necessarily available in a default Kubernetes installation. It represents a customization of a particular Kubernetes installation. However, many core Kubernetes functions are now built using custom resources, making Kubernetes more modular.

Custom resources can appear and disappear in a running cluster through dynamic registration, and cluster admins can update custom resources independently of the cluster itself. Once a custom resource is installed, users can create and access its objects using [kubectl](#gloss:kubectl), just as they do for built-in resources like *Pods*.

## Custom controllers

On their own, custom resources let you store and retrieve structured data. When you combine a custom resource with a *custom controller*, custom resources provide a true _declarative API_.

The Kubernetes [declarative API](/docs/concepts/overview/kubernetes-api/) enforces a separation of responsibilities. You declare the desired state of your resource. The Kubernetes controller keeps the current state of Kubernetes objects in sync with your declared desired state. This is in contrast to an imperative API, where you *instruct* a server what to do.

You can deploy and update a custom controller on a running cluster, independently of the cluster's lifecycle. Custom controllers can work with any kind of resource, but they are especially effective when combined with custom resources. The [Operator pattern](/docs/concepts/extend-kubernetes/operator/) combines custom resources and custom controllers. You can use custom controllers to encode domain knowledge for specific applications into an extension of the Kubernetes API.

## Should I add a custom resource to my Kubernetes cluster?

When creating a new API, consider whether to [aggregate your API with the Kubernetes cluster APIs](/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation/) or let your API stand alone.

| Consider API aggregation if: | Prefer a stand-alone API if: | | ---------------------------- | ---------------------------- | | Your API is [Declarative](#declarative-apis). | Your API does not fit the [Declarative](#declarative-apis) model. | | You want your new types to be readable and writable using `kubectl`.| `kubectl` support is not required | | You want to view your new types in a Kubernetes UI, such as dashboard, alongside built-in types. | Kubernetes UI support is not required. | | You are developing a new API. | You already have a program that serves your API and works well. | | You are willing to accept the format restriction that Kubernetes puts on REST resource paths, such as API Groups and Namespaces. (See the [API Overview](/docs/concepts/overview/kubernetes-api/).) | You need to have specific REST paths to be compatible with an already defined REST API. | | Your resources are naturally scoped to a cluster or namespaces of a cluster. | Cluster or namespace scoped resources are a poor fit; you need control over the specifics of resource paths. | | You want to reuse [Kubernetes API support features](#common-features). | You don't need those features. |

### Declarative APIs

In a Declarative API, typically:

  • Your API consists of a relatively small number of relatively small objects (resources).
  • The objects define configuration of applications or infrastructure.
  • The objects are updated relatively infrequently.
  • Humans often need to read and write th …(trimmed)

Sources

concepts/extend-kubernetes/api-extension/custom-resources.md · docCustom Resources

Related (23)

references ObjectAPI objects conf=1
references Kubectlkubectl conf=1
references CustomResourceDefinitionCustomResourceDefinition conf=1
part_of Custom resourcesdescribes conf=1
part_of Custom controllersdescribes conf=1
part_of Adding custom resourcesdescribes conf=1
part_of CustomResourceDefinitionsdescribes conf=1
part_of API server aggregationdescribes conf=1
part_of Preparing to install a custom resourcedescribes conf=1
part_of Accessing a custom resourcedescribes conf=1
part_of Custom resource field selectorsdescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Declarative APIsdescribes conf=1
part_of Comparing ease of usedescribes conf=1
part_of Advanced features and flexibilitydescribes conf=1
part_of Common Featuresdescribes conf=1
part_of Third party code and new points of failuredescribes conf=1
part_of Storagedescribes conf=1
part_of Authentication, authorization, and auditingdescribes conf=1

← all Docs