---
title: "Custom Resource Definition | Speedscale Docs"
description: "Explore the Custom Resource Definition for Speedscale to enable traffic replay in Kubernetes, allowing API traffic testing and validation against workloads."
canonical: "https://docs.speedscale.com/reference/replay-crd/"
---

[Documentation index](https://docs.speedscale.com/reference/llms.txt) | [Markdown](https://docs.speedscale.com/reference/replay-crd/index.md) | [Canonical page](https://docs.speedscale.com/reference/replay-crd/)

# Custom Resource Definition

<a id="overview"></a>

## Overview

The `TrafficReplay` CRD enables traffic replay functionality within Kubernetes clusters managed by the Speedscale operator. It allows users to replay captured API traffic against target workloads for testing and validation purposes.

The operator Helm chart installs and upgrades this CRD as a chart-managed resource. See the [CRD lifecycle](https://docs.speedscale.com/reference/helm/#crd-lifecycle) for upgrade ordering, verification commands, and GitOps considerations.

<a id="api-reference"></a>

## API Reference

*   **Group**: `speedscale.com`
*   **Version**: `v1`
*   **Kind**: `TrafficReplay`
*   **Plural**: `trafficreplays`
*   **Singular**: `trafficreplay`
*   **Short Names**: `replay`
*   **Scope**: Namespaced

<a id="resource-structure"></a>

## Resource Structure

<a id="trafficreplay-spec"></a>

### TrafficReplay Spec

The `spec` field defines the desired state of a TrafficReplay resource.

<a id="required-fields"></a>

#### Required Fields

| Field | Type | Description |
| --- | --- | --- |
| `snapshotID` | string | ID of the traffic snapshot for this TrafficReplay |
| `testConfigID` | string | ID of the replay configuration used by generator and responder |

<a id="optional-fields"></a>

#### Optional Fields

| Field | Type | Description |
| --- | --- | --- |
| `buildTag` | string | Links a unique tag, build hash, etc. to the generated traffic replay report |
| `cleanup` | enum | Cleanup mode: `inventory` (default), `all`, or `none` |
| `customURL` | string | Custom URL to send ALL traffic to (overrides workload-specific URLs) |
| `mode` | enum | Replay mode: `full-replay`, `responder-only`, or `generator-only` |
| `needsReport` | boolean | Indicates if replay needs a report even in mocks-only mode |
| `timeout` | string | Time to wait for replay test to finish |
| `ttlAfterReady` | string | TTL for TrafficReplay objects after completion |
| `secretRefs` | \[\]LocalObjectReference | References to secrets containing authorization tokens |
| `workloads` | \[\]Workload | Target workloads for the traffic replay |

<a id="workload-configuration"></a>

### Workload Configuration

The `workloads` field allows targeting multiple Kubernetes workloads during replay.

<a id="workload-fields"></a>

#### Workload Fields

| Field | Type | Description |
| --- | --- | --- |
| `ref` | ObjectReference | Reference to target workload (Deployment, Service, etc.) |
| `customURI` | string | Custom URI target instead of workload (required if `ref` not specified) |
| `tests` | \[\]string | Inbound traffic slice identifiers to target this workload |
| `mocks` | \[\]string | Outbound traffic slice identifiers to mock for this workload |
| `routing` | enum | Traffic routing method: `hostalias` or `nat` |

<a id="objectreference-fields"></a>

#### ObjectReference Fields

| Field | Type | Description |
| --- | --- | --- |
| `name` | string | Name of the referenced object (required) |
| `kind` | string | Kind of referenced object (defaults to "Deployment") |
| `namespace` | string | Namespace of referenced object (defaults to TrafficReplay namespace) |
| `apiVersion` | string | API version of referenced object |

<a id="trafficreplay-status"></a>

### TrafficReplay Status

The `status` field shows the observed state of the TrafficReplay resource.

<a id="status-fields"></a>

#### Status Fields

| Field | Type | Description |
| --- | --- | --- |
| `active` | boolean | Whether traffic replay is currently running |
| `conditions` | \[\]Condition | Current conditions of the TrafficReplay |
| `startedTime` | time | When the traffic replay started |
| `initializedTime` | time | When the test environment was prepared |
| `finishedTime` | time | When the traffic replay finished |
| `reportID` | string | ID of the generated traffic replay report |
| `reportURL` | string | URL to the traffic replay report |
| `observedGeneration` | integer | Last observed generation |
| `reconcileFailures` | integer | Number of controller reconciliation failures |

<a id="examples"></a>

## Examples

<a id="basic-trafficreplay"></a>

### Basic TrafficReplay

```yaml
apiVersion: speedscale.com/v1
kind: TrafficReplay
metadata:
  name: my-app-replay
  namespace: default
spec:
  snapshotID: "snapshot-123"
  testConfigID: "config-456"
  buildTag: "v1.2.3"
  timeout: "10m"
  workloads:
  - ref:
      name: my-app
      kind: Deployment
    tests:
    - "my-app:api.example.com:443"
    mocks:
    - "database.internal:5432"
```

<a id="multi-workload-replay"></a>

### Multi-Workload Replay

```yaml
apiVersion: speedscale.com/v1
kind: TrafficReplay
metadata:
  name: microservices-replay
  namespace: production
spec:
  snapshotID: "snapshot-789"
  testConfigID: "config-101"
  mode: "full-replay"
  cleanup: "inventory"
  workloads:
  - ref:
      name: api-service
      kind: Deployment
    tests:
    - "api.example.com"
    mocks:
    - "database.internal"
  - ref:
      name: worker-service
      kind: Deployment
    tests:
    - "worker.internal"
    mocks:
    - "queue.internal"
```

<a id="custom-url-replay"></a>

### Custom URL Replay

```yaml
apiVersion: speedscale.com/v1
kind: TrafficReplay
metadata:
  name: external-replay
  namespace: testing
spec:
  snapshotID: "snapshot-999"
  testConfigID: "config-888"
  customURL: "https://staging.example.com"
  needsReport: true
  ttlAfterReady: "1h"
```

<a id="kubectl-commands"></a>

## kubectl Commands

<a id="create-a-trafficreplay"></a>

### Create a TrafficReplay

```bash
kubectl apply -f trafficreplay.yaml
```

<a id="list-trafficreplays"></a>

### List TrafficReplays

```bash
kubectl get trafficreplays
kubectl get replay  # using short name
```

<a id="get-trafficreplay-details"></a>

### Get TrafficReplay Details

```bash
kubectl describe trafficreplay my-app-replay
```

<a id="watch-trafficreplay-status"></a>

### Watch TrafficReplay Status

```bash
kubectl get trafficreplay my-app-replay -w
```

<a id="delete-trafficreplay"></a>

### Delete TrafficReplay

```bash
kubectl delete trafficreplay my-app-replay
```

<a id="status-monitoring"></a>

## Status Monitoring

The TrafficReplay resource provides several status indicators through `kubectl get`:

*   **Active**: Shows if the replay is currently running
*   **Mode**: The replay mode being used
*   **Status**: Current status message from conditions
*   **Age**: Time since the resource was created

Monitor replay progress using:

```bash
kubectl get trafficreplay -w
```

<a id="traffic-targeting"></a>

## Traffic Targeting

<a id="inbound-traffic-tests"></a>

### Inbound Traffic (Tests)

Use the `tests` field to specify which inbound traffic slices a workload should receive:

*   Exact match: `"my-service:api.example.com:8080"`
*   Partial match: `"api.example.com"` (if unique)
*   All traffic: `"*"`

<a id="outbound-traffic-mocks"></a>

### Outbound Traffic (Mocks)

Use the `mocks` field to specify which outbound dependencies to mock:

*   Exact match: `"my-service:database.internal:5432"`
*   Partial match: `"database.internal"` (if unique)
*   All traffic: `"*"`

<a id="cleanup-modes"></a>

## Cleanup Modes

*   **`inventory`** (default): Revert environment to pre-replay state
*   **`all`**: Clean up all resources created during replay
*   **`none`**: Leave resources in their post-replay state

<a id="best-practices"></a>

## Best Practices

1.  **Use descriptive names** for TrafficReplay resources
2.  **Set appropriate timeouts** based on expected replay duration
3.  **Configure TTL** to automatically clean up completed replays
4.  **Use build tags** to correlate reports with code versions
5.  **Monitor conditions** for replay status and troubleshooting
6.  **Specify workload tests and mocks** explicitly for multi-workload scenarios
