A machine-readable index of this documentation for AI agents is available at https://kubevela.io/llms.txt. Markdown versions of documentation pages are available by appending .md to their URLs.
Skip to main content
Version: v1.9

The Definition File

A definition is a Kubernetes object: a ComponentDefinition, TraitDefinition, PolicyDefinition, WorkflowStepDefinition or WorkloadDefinition. You can write it in two formats, and the docs use both:

  • Kubernetes YAML, the object as the cluster stores it, with the CUE template as a string under spec.schematic.cue.template. You apply it with kubectl apply or vela def apply.
  • The CUE format, a .cue file with the metadata in one block and the template as plain CUE. It's easier to write and to check, since the template is real CUE rather than a string. vela def converts it to YAML when you apply it.

One definition, both formats​

Here is the same trait in each format.

The CUE format, my-labels.cue:

"my-labels": {
type: "trait"
description: "Add labels to the workload."
labels: "category": "metadata"
attributes: {
appliesToWorkloads: ["deployments.apps"]
podDisruptive: true
}
}
template: {
patch: spec: template: metadata: labels: parameter.labels
parameter: labels: [string]: string
}

What vela def render my-labels.cue turns it into:

apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: Add labels to the workload.
labels:
custom.definition.oam.dev/category: metadata
name: my-labels
spec:
appliesToWorkloads:
- deployments.apps
podDisruptive: true
schematic:
cue:
template: |
patch: spec: template: metadata: labels: parameter.labels
parameter: labels: [string]: string

How the fields map​

CUE formatKubernetes YAML
The block's name, "my-labels": {...}metadata.name
type (component, trait, policy, workflow-step, workload)kind (ComponentDefinition, TraitDefinition, ...)
descriptionmetadata.annotations["definition.oam.dev/description"]
aliasmetadata.annotations["definition.oam.dev/alias"]
annotationsmetadata.annotations; a key without oam.dev in it gets the prefix custom.definition.oam.dev/
labelsmetadata.labels, prefixed the same way
attributesspec, every field except schematic
templatespec.schematic.cue.template, as a string
import lines at the top of the fileThe top of the template string

Only CUE templates convert this way. A definition with a terraform schematic is written as YAML.

Moving between them​

ToRun
See the YAML a CUE file becomesvela def render my-labels.cue
Apply a CUE file to the clustervela def apply my-labels.cue
Print an installed definition in the CUE formatvela def get my-labels
Start a new definition in the CUE formatvela def init my-labels -t trait

See Manage Definition for the full vela def workflow, and OAM Definition Protocol for the fields each kind of definition has.