---
title: "Custom Resources | Cosmonic"
description: "Reference guide for Kubernetes custom resources in Cosmonic Control, including Artifacts, Hosts, HTTPTriggers, Workloads, and more."
canonical: "https://cosmonic.com/docs/custom-resources/"
---

# Custom Resources

Core primitives in Cosmonic Control are represented by [**Kubernetes custom resources**](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/). Custom resources may be declaratively provisioned and managed using the API extensions defined in [Custom Resource Definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions).

Cosmonic Control uses CRDs for the following custom resources from the `control.cosmonic.io/v1alpha2`, `control.cosmonic.io/v1alpha1` and `runtime.wasmcloud.dev/v1alpha1` API packages:

- [Artifact](https://cosmonic.com/docs/custom-resources/#artifact) - `runtime.wasmcloud.dev/v1alpha1`
- [Host](https://cosmonic.com/docs/custom-resources/#host) - `runtime.wasmcloud.dev/v1alpha1`
- [HTTPTrigger](https://cosmonic.com/docs/custom-resources/#httptrigger) - `control.cosmonic.io/v1alpha2`
- [ProjectEnvironment](https://cosmonic.com/docs/custom-resources/#projectenvironment) - `control.cosmonic.io/v1alpha1`
- [Workload](https://cosmonic.com/docs/custom-resources/#workload) - `runtime.wasmcloud.dev/v1alpha1`
- [WorkloadDaemonSet](https://cosmonic.com/docs/custom-resources/#workloaddaemonset) - `runtime.wasmcloud.dev/v1alpha1`
- [WorkloadDeployment](https://cosmonic.com/docs/custom-resources/#workloaddeployment) - `runtime.wasmcloud.dev/v1alpha1`
- [WorkloadReplicaSet](https://cosmonic.com/docs/custom-resources/#workloadreplicaset) - `runtime.wasmcloud.dev/v1alpha1`

For complete API specifications, see the API references for [`control.cosmonic.io`](https://cosmonic.com/docs/api-reference/control.cosmonic.io/) and [`runtime.wasmcloud.dev/v1alpha1`](https://cosmonic.com/docs/api-reference/runtime.wasmcloud.dev/).

## Artifact

The [Artifact](https://cosmonic.com/docs/api-reference/runtime.wasmcloud.dev/#artifact) resource represents a WebAssembly component image that can be referenced by workloads. Artifacts define the image location and optional image pull secrets for accessing private registries. The resource can be used to fetch an OCI image and store its contents in a [NATS JetStream Object Store](https://docs.nats.io/nats-concepts/jetstream/obj_store), reducing registry load by downloading artifacts once and distributing them internally. The `Artifact` resource tracks individual revisions, publishing the artifact's location under `Status.ArtifactURL`.

[`WorkloadDeployment`](https://cosmonic.com/docs/custom-resources/#workloaddeployment) can reference Artifacts as their component image. The controller will automatically roll the deployment when a new image is detected.

Example manifest:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: Artifact
metadata:
  name: http-hello-world
  namespace: default
spec:
  image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
  imagePullSecret:
    name: ghcr-secret
```

## Host

The [Host](https://cosmonic.com/docs/api-reference/runtime.wasmcloud.dev/#host) resource represents a [wasmCloud runtime environment called a host](https://wasmcloud.com/docs/concepts/hosts/). Each host has a unique ID and can run workloads.

Example manifest:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: Host
metadata:
  name: host-sample
  namespace: default
  labels:
    hostgroup: default
spec:
  hostId: NABCDEFGHIJKLMNOPQRSTUVWXYZ234567
  hostname: host-sample.default
  httpPort: 4000
```

## HTTPTrigger

The [`HTTPTrigger`](https://cosmonic.com/docs/api-reference/control.cosmonic.io/#httptrigger) resource routes HTTP traffic from Cosmonic Control's ingress to Wasm workloads. Its spec is shaped like the Gateway API [`HTTPRoute`](https://gateway-api.sigs.k8s.io/reference/api-types/httproute/): it lists the hostnames it serves and a set of rules, and each rule sends matching requests to one or more [`WorkloadDeployment`](https://cosmonic.com/docs/custom-resources/#workloaddeployment) s in the same namespace, split by weight. The trigger does not create the workload; deploy the `WorkloadDeployment` alongside it.

As of Cosmonic Control v0.13.0, `HTTPTrigger` is served as `control.cosmonic.io/v1alpha2`. Earlier releases used `v1alpha1`, which embedded the workload in the trigger; see [Upgrading from v0.12.2 to v0.13.0](https://cosmonic.com/docs/operations/upgrading/#httptrigger-v1alpha2-references-a-workloaddeployment) to migrate.

See [Ingress and Workloads](https://cosmonic.com/docs/operations/ingress-and-workloads/) for a full reference and examples.

Example manifest:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: WorkloadDeployment
metadata:
  name: hello-world
  namespace: default
spec:
  replicas: 1
  template:
    spec:
      hostInterfaces:
        - namespace: wasi
          package: http
          interfaces:
            - incoming-handler
          config:
            host: hello.localhost.cosmonic.sh
      components:
        - name: http
          image: ghcr.io/cosmonic-labs/control-demos/hello-world:0.1.2
---
apiVersion: control.cosmonic.io/v1alpha2
kind: HTTPTrigger
metadata:
  name: hello-world
  namespace: default
spec:
  hostnames:
    - hello.localhost.cosmonic.sh
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: hello-world
```

The `WorkloadDeployment` declares the inbound `wasi:http` interface itself: `incoming-handler` for a WASI P2 component, `handler` for a WASI P3 component. `config.host` names the hostname the workload serves; when it is set, Envoy rewrites the `Host` header to it and keeps the client's original host in `X-Forwarded-Host`.

The entry needs no `version`. A `WorkloadDeployment` with no inbound `wasi:http` entry still schedules and reports ready, but it answers every request with `404`.

### Splitting traffic between workloads

A rule can list several backends with a `weight` each. Weights are relative, and `0` sends a backend nothing:

```yaml
spec:
  hostnames:
    - hello.example.com
  rules:
    - backendRefs:
        - name: hello-v1
          weight: 90
        - name: hello-v2
          weight: 10
```

Backends in one rule that set different `config.host` values cannot share the rule; the trigger reports `IncompatibleBackendHosts`.

### Pinning to a host environment

Environment pinning lives on the `WorkloadDeployment`, as `spec.template.spec.environment`. It pins the workloads to hosts reporting that environment in their heartbeat. When unset, the workload is unpinned and the scheduler treats every host as fair game, including shared host groups that serve multiple tenants. Set it to keep workloads on a tenant-scoped host group, or to route them onto a dedicated shared host group such as `infra`:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: WorkloadDeployment
spec:
  template:
    spec:
      environment: team-a
      # ...
```

The `environment` value is matched against the environment HostGroup pods report; see [Installing HostGroups](https://cosmonic.com/docs/operations/deploying-to-cosmonic-control/#installing-hostgroups) for setting it on a HostGroup. An `environment` other than the workload's own namespace is honored only while the control chart's `operator.allowSharedHosts` is `true` (the default).

### Autoscaling

`WorkloadDeployment` exposes the Kubernetes `/scale` subresource, so a stock `HorizontalPodAutoscaler` or KEDA `ScaledObject` can target it directly. As of v0.13.0 `HTTPTrigger` has no replicas and no `/scale` subresource. See [Autoscaling](https://cosmonic.com/docs/operations/autoscaling/).

## ProjectEnvironment

> **Enterprise**
>
> `ProjectEnvironment` is an enterprise feature. It is available with an enterprise license and is not required for free-tier use.

The `ProjectEnvironment` resource defines team membership and roles for a Kubernetes namespace managed as a Cosmonic Control project. It is used in conjunction with the enterprise `Project` grouping type to provide namespace-scoped multi-tenancy with RBAC.

Example manifest:

```yaml
apiVersion: control.cosmonic.io/v1alpha1
kind: ProjectEnvironment
metadata:
  name: my-project
  namespace: my-namespace
spec:
  groups:
    - name: platform-team
      role: admin
    - name: app-team
      role: developer
```

## Workload

The [Workload](https://cosmonic.com/docs/api-reference/runtime.wasmcloud.dev/#workload) resource represents an application composed of one or more WebAssembly components and optional services. Workloads define the components, their configurations, volume mounts, and host interfaces they consume.

Example manifest:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: Workload
metadata:
  name: hello-world
  namespace: default
spec:
  hostSelector:
    hostgroup: default
  components:
    - name: http-component
      image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
      poolSize: 10
      maxInvocations: 1000
      localResources:
        environment:
          config:
            LOG_LEVEL: info
        allowedHosts:
          - https://api.example.com
  hostInterfaces:
    - namespace: wasi
      package: http
      interfaces:
        - incoming-handler
      config:
        address: '0.0.0.0:8080'
  volumes:
    - name: cache
      ephemeral: {}
```

The `poolSize`, `maxConcurrency`, and `maxInvocations` fields on a component set how many calls a warm instance serves at once and how many instances the host keeps. Because instance concurrency drives how many connections a workload needs, size those fields together with the host's per-workload connection quotas. The upstream wasmCloud [Concurrency and connections](https://wasmcloud.com/docs/kubernetes-operator/operator-manual/concurrency-and-connections) guide walks through the interaction and a worked sizing example.

## WorkloadDaemonSet

The [`WorkloadDaemonSet`](https://cosmonic.com/docs/api-reference/runtime.wasmcloud.dev/#workloaddaemonset) resource, added in Cosmonic Control v0.15.0, runs a workload on every host that matches its `template.spec.hostSelector`, the way a Kubernetes DaemonSet runs a pod on every matching node. `replicasPerHost` (default `1`) sets how many Workloads run on each matching host; unlike a `WorkloadDeployment`'s `replicas`, it is not a total. When a matching host joins, the operator starts the workload there, and when a host leaves, its Workloads go with it.

Example manifest:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: WorkloadDaemonSet
metadata:
  name: node-agent
  namespace: default
spec:
  replicasPerHost: 1
  deployPolicy: RollingUpdate
  maxConcurrentHosts: 1
  template:
    labels:
      app: node-agent
    spec:
      hostSelector:
        hostgroup: default
      components:
        - name: agent
          image: ghcr.io/example/node-agent:0.1.0
```

`deployPolicy` sets how a template change reaches the hosts. `RollingUpdate` (the default) starts the new instances on a host before stopping the old ones there, `maxConcurrentHosts` hosts at a time (default `1`). `Recreate` stops every old instance at once.

`HTTPTrigger` routes only to a `WorkloadDeployment`. To reach a `WorkloadDaemonSet` from inside the cluster, name an existing Kubernetes Service in `spec.kubernetes.service`; the operator keeps an EndpointSlice for it that points at the host pods running the workload. Agent sessions and agent run triggers are refused on a `WorkloadDaemonSet`.

## WorkloadDeployment

The [WorkloadDeployment](https://cosmonic.com/docs/api-reference/runtime.wasmcloud.dev/#workloaddeployment) resource manages the deployment and scaling of workloads across hosts. It creates and manages WorkloadReplicaSets to ensure the desired number of workload replicas are running.

Example manifest:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: WorkloadDeployment
metadata:
  name: hello-world
  namespace: default
spec:
  replicas: 3
  deployPolicy: RollingUpdate
  artifacts:
    - name: http-component
      artifactFrom:
        name: http-hello-world
  template:
    labels:
      app: hello-world
    spec:
      hostSelector:
        hostgroup: default
      components:
        - name: http-component
          image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
          poolSize: 10
      hostInterfaces:
        - namespace: wasi
          package: http
          interfaces:
            - incoming-handler
          config:
            address: '0.0.0.0:8080'
```

## WorkloadReplicaSet

The [WorkloadReplicaSet](https://cosmonic.com/docs/api-reference/runtime.wasmcloud.dev/#workloadreplicaset) resource ensures that a specified number of workload replicas are running at any given time. It is typically managed by a WorkloadDeployment but can be used directly for more granular control.

Example manifest:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: WorkloadReplicaSet
metadata:
  name: hello-world-v1
  namespace: default
spec:
  replicas: 5
  template:
    labels:
      app: hello-world
      version: v1
    spec:
      hostSelector:
        hostgroup: default
      components:
        - name: http-component
          image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
          poolSize: 10
      hostInterfaces:
        - namespace: wasi
          package: http
          interfaces:
            - incoming-handler
          config:
            address: '0.0.0.0:8080'
```

Last updated on **Nov 10, 2026** by **Liam Randall**
