# Sizing and search nodes

> What search nodes and indexers keep on their volumes on Kubernetes, local NVMe disks on EKS and AKS, and how memory, copies and pools are sized with the Helm chart.

Source: https://docs.corfedo.ai/operate/kubernetes/sizing-and-search-nodes/

Indexes are stored in an S3-compatible bucket, see [Object storage](https://docs.corfedo.ai/operate/kubernetes/prepare-the-cluster/#object-storage). The default memory limits are those of a development stack, so set them and the volume sizes for your index.

## Search node volumes

The volume holds a cache of the index copies the node serves. A missing copy is downloaded from the bucket again, so the volume needs speed, not durability. Searches read what is not in memory from it, fastest from local NVMe disks.

The class and size of a pool's volumes can't change. To use others, add a [pool](#pools).

### Use local NVMe disks

**EKS**

Use nodes with NVMe instance store volumes, such as the I families or `m8id`, and bootstrap commands that format and mount the disks. This StorageClass creates no volumes, so run the Kubernetes local volume static provisioner to publish the mounted disks as filesystem volumes of the class. Without it the search pods stay `Pending`.

```yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-disks
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
```

```yaml
search:
  volume:
    storageClassName: fast-disks
    size: 800Gi
  maxDisk: 700Gi
```

A claim binds a whole disk of at least `volume.size`. After a node is replaced, delete the claim, such as `data-corfedo-search-default-0`, and the pod.

**AKS**

Use nodes with local NVMe disks, such as the Lsv3 series, and [Azure Container Storage](https://learn.microsoft.com/en-us/azure/storage/container-storage/use-container-storage-with-local-disk). It provisions a search node's claim only with the annotation below.

```yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-csi
provisioner: localdisk.csi.acstor.io
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
```

```yaml
search:
  volume:
    storageClassName: local-csi
    size: 800Gi
    annotations:
      localdisk.csi.acstor.io/accept-ephemeral-storage: "true"
  maxDisk: 700Gi
```

## Indexer volumes

The volume holds the builds in progress and the pod's repository cache: a shallow copy of each repository the indexer built, so that a later build fetches only the difference.

The cache exists while `indexer.repositoryCache.maxIdleHours` is set, from 1 to 8760 hours. A pool's `repositoryCache` replaces the whole map.

## Memory and disk budgets

Without a value, a budget follows the memory limit or the volume, as the table shows. Without a memory limit, set the memory budgets.

| Value | Bounds | When unset |
| --- | --- | --- |
| `search.maxMemory` | The memory a search node loads index copies into, less headroom for searches and compaction | 3/4 of the memory limit |
| `search.maxDisk` | The cache | 4/5 of the volume |
| `indexer.maxBuildMemory` | The memory of the `indexer.slots` builds that run at once. A build that needs more fails. | 3/4 of the memory limit |
| `indexer.repositoryCache.maxSize` | The repository cache | 1/2 of the volume |
| `indexer.repositoryCache.minFreeDisk` | Space the cache leaves free | 1/4 of the volume |

## Copies and search nodes

The chart runs two search nodes (`search.replicas`) and serves two copies of each repository, so a node restarts without a gap. The number of copies can't exceed the number of search nodes. To prefer capacity, serve one copy, and a repository cannot be searched while its node restarts and loads it again:

```yaml
servingPolicy:
  replicaCount: 1
```

`servingPolicy.retentionSeconds` is how long a replaced build still answers reads that began on it.

## Pools

A pool is a group of search nodes or indexers that are alike. The values under `search` and `indexer` are every pool's defaults, and a pool set to `null` is not created.

- **Search nodes:** one pool per zone, named by `zone` and placed by `nodeSelector`. A repository's copies prefer different zones and share one when no other has a healthy node with room.
- **Indexers:** one pool per node size.

```yaml
search:
  updateStrategy:
    type: OnDelete
  pools:
    default: null
    zone-a:
      zone: eu-central-1a
      nodeSelector:
        topology.kubernetes.io/zone: eu-central-1a
    zone-b:
      zone: eu-central-1b
      nodeSelector:
        topology.kubernetes.io/zone: eu-central-1b
```

`search.replicas` counts per pool: these two run four search nodes with four claims unless a pool sets `replicas`.

Pools update independently, so two can stop nodes that hold copies of the same repository. Update one search pool at a time: with `OnDelete`, delete its pods, and with `RollingUpdate`, lower its `rollingUpdate.partition`, because a deleted pod below the partition returns at the old revision. Before the next pool, confirm with the `serving-status` operator command that copies serve again, because a pod can be Ready after failed loads.
