> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/netcap/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/netcap/latest/guides/pcap-k8s.md).

# Configure PCAP capturing

Configuring PCAP collection using Kubernetes objects allows you to manage the entire setup in a centralized and declarative way. To do so, you must create and configure these two Kubernetes Custom Resources (CRs):

- [`NetCaptureStorage`](https://docs.cennso.com/cennso/netcap/latest/technical-reference/crds/netcapturestorages.md) - specifies the storage location for collected PCAP files
- [`NetCaptureJob`](https://docs.cennso.com/cennso/netcap/latest/technical-reference/crds/netcapturejobs.md) - defines the traffic capture configuration, including the source interface, start time and duration of traffic capture, and destinations

The configuration below is a simplified example that shows how to set up traffic capturing with NetCap. For a complete description of available configuration options, read [About PCAP capturing](https://docs.cennso.com/cennso/netcap/latest/concepts/pcap-capturing.md).

Depending on your preference, you can configure PCAP collection using either Cennso Management Console (CMC) or CLI.

## Set a storage location

First, create a `NetCaptureStorage` object to configure a storage where PCAP files will be stored:

### Set a storage location (CMC)

### CMC

1. Go to **Cennso Management -> Network Applications -> + New**, and choose the `NetCapture Storage` tile.
2. In the **Metadata** tab of the form, provide the name for your `NetCapture Storage` instance. You can also specify Kubernetes [labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) and [annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/).
3. Switch to the **Specification** tab and choose a storage type for your PCAPs: local, SFTP, or S3. Provide a path if you choose local storage (PCAPs saved on the NetCap Sink pod), or the necessary connection parameters if using SFTP or S3. NetCap supports all the rclone connection parameters. For the full set of fields, refer to the [rclone SFTP documentation](https://rclone.org/sftp/) or [rclone S3 documentation](https://rclone.org/s3/).
4. Click **Create**.

>**NOTE:** If you do not specify a destination in the **Specification** tab, by default PCAPs will be stored on the local disc in the Kubernetes Worker node where the NetCap Sink is running. The default path is `/root/dumps`.

### Set a storage location (CLI)

### CLI

To configure storage using the CLI, create a YAML file (for example: `netcapture-storage.yaml`) defining a `NetCaptureStorage` Custom Resource (CR) and specify the desired storage for your PCAPs:

- To set a local disk as a storage, set **spec.forProvider.local.path** to the local path where you want to store PCAPs. In this example, the PCAPs will be stored in the default `/root/dumps` directory:

  ```yaml
  apiVersion: netcap.cennso.com/v1alpha1
  kind: NetCaptureStorage
  metadata:
    name: storage-local
  spec:
    forProvider:
      local:
        path: dumps
  ```

- To set a storage accessible through SFTP, use the **spec.forProvider.sftp** configuration option. See the example:

  ```yaml
  apiVersion: netcap.cennso.com/v1alpha1
  kind: NetCaptureStorage
  metadata:
    name: storage-sftp
  spec:
    forProvider:
      sftp:
        host: "sftp-service.sftp"
        path: "/upload"
        port: 22
        credentials:
          user: "username"
          pass: "password"
  ```

- To set S3 as a storage, use the **spec.forProvider.s3** configuration option. See the example:

  ```yaml
  apiVersion: netcap.cennso.com/v1alpha1
  kind: NetCaptureStorage
  metadata:
    name: storage-s3
  spec:
    forProvider:
      s3:
        bucket:            "testbucket"
        endpoint:          "http://minio.minio:9000"
        provider:          "Minio"
        # credentials
        access_key_id:     "minio"
        secret_access_key: "minio123"
        region:            "Europe"
        acl:               "private"
  ```

Then, apply the `NetCaptureStorage` CR to your cluster using this command:

   ```bash
   kubectl apply -f netcapture-storage.yaml
   ```

For more details on the `NetCaptureStorage` configuration, see the dedicated sections:
- [Local storage](https://docs.cennso.com/cennso/netcap/latest/concepts/netcapturestorage.md#local-storage)
- [S3 storage](https://docs.cennso.com/cennso/netcap/latest/concepts/netcapturestorage.md#s3-storage)
- [SFTP storage](https://docs.cennso.com/cennso/netcap/latest/concepts/netcapturestorage.md#sftp-server)

## Provide traffic capture configuration

Now that you configured the storage for PCAPs, you can specify other PCAP configuration options using `NetCaptureJob`:

### Provide traffic capture configuration (CMC)

### CMC

1. Go to **Cennso Management -> Network Applications -> + New**, and choose the `NetCapture Job` tile.
2. In the **Metadata** tab of the form, provide the name for your `NetCapture Job` instance. You can also specify Kubernetes [labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) and [annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/).
3. Switch to the **Specification** tab and fill out the form:
   - In the **Cluster** field, choose the cluster to which this configuration should be applied.
   - In the **Selector** field, specify a name and a namespaces of the VPP pod to target.
   - In the **Capture time schedule** section, choose whether your traffic capture should occur one-time or periodically. For a one-time capture, specify the start and end time. For a periodic capture, define the schedule and duration.
   - In the **Traffic stream source** section, specify whether you want to capture traffic passing through the specified interface, or based on the specified IMSI. Here you can also provide all the configuration options you would like to apply to your traffic capture.
   - In the **Traffic stream destination** section, provide parameters that define a PCAP file and storage information including a reference to the `NetCaptureStorage` object created before.
4. Click **Create**.

### Provide traffic capture configuration (CLI)

### CLI

Create a YAML file with the `NetCaptureJob` CR (for example: `netcapture-job.yaml`). Make sure to fill all the necessary fields and references. See the example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    streamTemplate:
      spec:
        cluster:
          name: test-cluster
          namespace: cennso-infra
        sources:
        - interface:
            name: sgi
            batchingStrategy:
              packetsCount: 100
              duration: 10s
              packetsBytes: 200
            filter: "arp or icmp"
            natsMode: pubsub
            match-labels:
              apn: "test.cennso.com"
              lane: lane-b
        - imsi:
            imsi: "901406000520002"
    destinationTemplate:
      spec:
        destinations:
          - storage:
              name: local-store
              prefix: pfcp
            fileParams:
              compress: zstd
              compressLevel: 20
              max_bytes: 107374182
              max_files: 10
              max_packets: 10000
              rotate: true
              schedule: @hourly
```

>**NOTE:** Make sure the **destinationTemplate.spec.destinations.storage** parameter contains proper reference to the `NetCaptureStorage` object.

After that, apply the `NetCaptureJob` CR to your cluster using this command:

```bash
kubectl apply -f netcapture-job.yaml
```

## See the `NetCaptureJob` status

You can see the status of your `NetCaptureJob` to check if the stream was created successfully, packets were captured and forwarded, and whether any errors occurred during stream or destination setup.

To see the `NetCaptureJob` status:

### See the NetCaptureJob status (CMC)

### CMC

1. Go to **Cennso Management -> Network Applications** and choose your `NetCaptureJob` from the list of resources.
2. The status of the selected `NetCaptureJob` is visible on the **Overview -> Status** tab.
3. Click **Details** to see detailed information about `NetCaptureJob`.

### See the NetCaptureJob status (CLI)

### CLI

Run this command:

```bash
kubectl get netcapturejob -oyaml
```

See the status example after object creation:

```yaml
  status:
    atProvider:
      conditions:
      - lastTransitionTime: "2025-06-20T08:41:32Z"
        reason: StreamCreated
        status: "True"
        type: NetCapture
      errors: {}
      phase: Running
      scheduledEnd: 1h
      scheduledStart: "2025-06-20T08:41:30Z"
      scheduledTime: "2025-06-20T08:41:30Z"
      streamCreatedBy:
      - name: netcap-collector-5bhsr
        namespace: cennso-system
      - name: netcap-collector-vfzh4
        namespace: cennso-system
      - name: netcap-sink-0
        namespace: cennso-system
      - name: upg-prox01
        namespace: pgw-ocs
    conditions:
    - lastTransitionTime: "2025-06-20T08:41:30Z"
      reason: ReconcileSuccess
      status: "True"
      type: Synced
    - lastTransitionTime: "2025-06-20T08:41:32Z"
      reason: Available
      status: "True"
      type: Ready
    - lastTransitionTime: "2025-06-20T08:41:32Z"
      reason: StreamCreated
      status: "True"
      type: NetCapture
```

See the status example after the packets are sent:

```yaml
  status:
    atProvider:
      conditions:
      - lastTransitionTime: "2025-06-20T08:44:05Z"
        reason: PacketSent
        status: "True"
        type: NetCapture
      errors: {}
      packetReceivedBy:
      - name: netcap-sink-0
        namespace: cennso-system
      packetsSentBy:
      - name: netcap-collector-5bhsr
        namespace: cennso-system
      phase: Running
      scheduledEnd: 1h
      scheduledStart: "2025-06-20T08:43:08Z"
      scheduledTime: "2025-06-20T08:43:08Z"
      streamCollectingBy:
      - name: upg-prox01
        namespace: pgw-ocs
      streamCreatedBy:
      - name: netcap-collector-vfzh4
        namespace: cennso-system
    conditions:
    - lastTransitionTime: "2025-06-20T08:43:08Z"
      reason: ReconcileSuccess
      status: "True"
      type: Synced
    - lastTransitionTime: "2025-06-20T08:44:05Z"
      reason: Available
      status: "True"
      type: Ready
    - lastTransitionTime: "2025-06-20T08:44:05Z"
      reason: PacketSent
      status: "True"
      type: NetCapture
```

See the status example when an error occurs:

```yaml
  status:
    atProvider:
      conditions:
      - lastTransitionTime: "2025-06-20T08:47:47Z"
        message: No netcap-plugin update for the stream capture-example
        reason: StreamCreateError
        status: "False"
        type: NetCapture
      errors: {}
      phase: Failed
      scheduledEnd: 10m
      scheduledStart: "2025-06-20T08:43:08Z"
      scheduledTime: "2025-06-20T08:43:08Z"
      streamCreatedBy:
      - name: netcap-collector-vfzh4
        namespace: cennso-system
      - name: netcap-sink-0
        namespace: cennso-system
    conditions:
    - lastTransitionTime: "2025-06-20T08:43:08Z"
      reason: ReconcileSuccess
      status: "True"
      type: Synced
    - lastTransitionTime: "2025-06-20T08:47:47Z"
      message: No netcap-plugin update for the stream capture-example
      reason: Unavailable
      status: "False"
      type: Ready
    - lastTransitionTime: "2025-06-20T08:47:47Z"
      message: No netcap-plugin update for the stream capture-example
      reason: StreamCreateError
      status: "False"
      type: NetCapture
```

>**NOTE:** Most errors occur due to misconfigured resources. Double-check field values and references if an error appears.

## Next steps

As a next step, you can inspect a live view of captured traffic using Wireshark. See the [Observe real-time traffic in Wireshark](https://docs.cennso.com/cennso/netcap/latest/guides/pcap-livestream.md) document for more details.
