--- title: Claims weight: 60 description: "Claims are a way to consume Crossplane resources with namespace scoping" --- Claims represents a set of managed resources as a single Kubernetes object, inside a namespace. Users create claims when they access the custom API, defined in the CompositeResourceDefinition. {{< hint "tip" >}} Claims are like [composite resources]({{}}). The difference between Claims and composite resources is Crossplane can create Claims in a namespace, while composite resources are cluster scoped. {{< /hint >}} {{}} Crossplane has four core components that users commonly mix up: * [Compositions]({{}}) - A template to define how to create resources. * [Composite Resource Definition]({{}}) (`XRD`) - A custom API specification. * [Composite Resources]({{}}) (`XR`) - Created by using the custom API defined in a Composite Resource Definition. XRs use the Composition template to create new managed resources. * Claims (`XRC`) - This page. Like a Composite Resource, but with namespace scoping. {{}} ## Creating a Claim Creating a Claim requires a [Composition]({{}}) and a [CompositeResourceDefinition]({{}}) (`XRD`) already installed. {{}} The XRD must [enable Claims]({{}}). {{< /hint >}} The Composition defines the set of resources to create. The XRD defines the custom API users call to request the set of resources. ![Diagram of the relationship of Crossplane components](/media/composition-how-it-works.svg) For example, this {{}}CompositeResourceDefinition{{}} creates a composite resource API endpoint {{}}xmydatabases.example.org{{}} and enables a Claim API endpoint {{}}database.example.org{{}} ```yaml {label="xrd1",copy-lines="none"} apiVersion: apiextensions.crossplane.io/v1 kind: CompositeResourceDefinition metadata: name: xmydatabases.example.org spec: group: example.org names: kind: XMyDatabase plural: xmydatabases claimNames: kind: Database plural: databases # Removed for brevity ``` The Claim uses the XRD's {{}}kind{{}} API endpoint to request resources. The Claim's {{}}apiVersion{{}} matches the XRD {{}}group{{}} and the {{}}kind{{}} matches the XRD {{}}claimNames.kind{{}} ```yaml {label="claim1",copy-lines="none"} apiVersion: example.org/v1alpha1 kind: database metadata: name: my-claimed-database spec: # Removed for brevity ``` When a user creates a Claim in a namespace Crossplane also creates a composite resource. Use {{}}kubectl describe{{}} on the Claim to view the related composite resource. The {{}}Resource Ref{{}} is the composite resource Crossplane created for this Claim. ```shell {label="claimcomp",copy-lines="1"} kubectl describe database.example.org/my-claimed-database Name: my-claimed-database API Version: example.org/v1alpha1 Kind: database Spec: Resource Ref: API Version: example.org/v1alpha1 Kind: XMyDatabase Name: my-claimed-database-rr4ll # Removed for brevity. ``` Use {{}}kubectl describe{{}} on the composite resource to view the {{}}Claim Ref{{}} linking the composite resource to the original Claim. ```shell {label="getcomp",copy-lines="1"} kubectl describe xmydatabase.example.org/my-claimed-database-rr4ll Name: my-claimed-database-rr4ll API Version: example.org/v1alpha1 Kind: XMyDatabase Spec: Claim Ref: API Version: example.org/v1alpha1 Kind: database Name: my-claimed-database Namespace: default ``` {{}} Crossplane supports directly creating composite resources. Claims allow namespace scoping and isolation for users consuming the custom APIs. If you don't use namespaces in your Kubernetes deployment Claims aren't necessary. {{< /hint >}} ### Claiming existing composite resources By default, creating a Claim creates a new composite resource. Claims can also link to existing composite resources. A use case for claiming existing composite resources may be slow to provision resources. Composite resources can be pre-provisioned and a Claim can use those resources without waiting for their creation. Set the Claim's {{}}resourceRef{{}} and match the pre-existing composite resource {{}}name{{}}. ```yaml {label="resourceref",copy-lines="none"} apiVersion: example.org/v1alpha1 kind: database metadata: name: my-claimed-database spec: resourceRef: apiVersion: example.org/v1alpha1 kind: XMyDatabase name: my-pre-created-xr ``` If a Claim specifies a {{}}resourceRef{{}} that doesn't exist, Crossplane doesn't create a composite resource. {{}} All Claims have a {{}}resourceRef{{}}. Manually defining the {{}}resourceRef{{}} isn't required. Crossplane fills in the {{}}resourceRef{{}} with the information from the composite resource created for the Claim. {{< /hint >}} ## Claim connection secrets If a Claim expects connection secrets the Claim must define a {{}}writeConnectionSecretToRef{{}} object. The {{}}writeConnectionSecretToRef{{}} object defines the name of the Kubernetes secret object where Crossplane saves the connection details. {{}} The Crossplane creates the secret object in the same namespace as the Claim. {{< /hint >}} For example, to a new secret object named {{}}my-claim-secret{{}} use {{}}writeConnectionSecretToRef{{}} with the {{}}name: my-claim-secret{{}}. ```yaml {label="claimSec"} apiVersion: example.org/v1alpha1 kind: database metadata: name: my-claimed-database spec: writeConnectionSecretToRef: name: my-claim-secret ``` For more information on connection secrets read the [Connection Secrets knowledge base article]({{}}).