# Persistent memory storage configuration for Aerospike on Kubernetes

This example creates a cluster where Aerospike data and index both use [Persistent Memory (PMEM)](https://pmem.io/) storage.

## Prerequisites

### Hardware

-   Persistent Memory (PMEM) devices installed on the Kubernetes nodes

### Software

In addition to the Aerospike Kubernetes Operator, install the [PMEM-CSI driver for Kubernetes](https://intel.github.io/pmem-csi/latest/README.html) which makes PMEM available to Aerospike clusters, running on Kubernetes, as filesystem volumes.

Installing PMEM-CSI involves:

-   [Persistent memory pre-provisioning](https://intel.github.io/pmem-csi/latest/docs/install.html#persistent-memory-pre-provisioning)
-   [Installing PMEM-CSI driver](https://intel.github.io/pmem-csi/latest/docs/install.html#installation-and-setup)

We recommend using the [PMEM-CSI Operator](https://intel.github.io/pmem-csi/latest/docs/install.html#install-using-the-operator) to install the PMEM-CSI driver.

## Create the PMEM storage class

Once the PMEM-CSI driver has been installed, create a file `pmem-csi-sc-late-binding.yml` with the following content:

pmem-csi-sc-late-binding.yml

```yaml
apiVersion: storage.k8s.io/v1

kind: StorageClass

metadata:

  name: pmem-csi-sc-late-binding

provisioner: pmem-csi.intel.com

reclaimPolicy: Delete

volumeBindingMode: WaitForFirstConsumer
```

Create the storage class:

Terminal window

```shell
kubectl apply -f pmem-csi-sc-late-binding.yml
```

## Aerospike cluster using PMEM

For more information on PMEM and other storage configurations, see the Aerospike documentation for [namespace storage configuration](https://aerospike.com/docs/database/manage/namespace/storage/config).

To create an Aerospike Cluster that uses PMEM, see the example Aerospike custom resource (CR) file below:

```yaml
apiVersion: asdb.aerospike.com/v1

kind: AerospikeCluster

metadata:

  name: aerocluster

  namespace: aerospike

spec:

  size: 2

  image: aerospike/aerospike-server-enterprise:8.1.1.0

  storage:

    filesystemVolumePolicy:

      initMethod: deleteFiles

      cascadeDelete: true

    blockVolumePolicy:

      cascadeDelete: true

    volumes:

      - name: workdir

        aerospike:

          path: /opt/aerospike

        source:

          persistentVolume:

            storageClass: ssd

            volumeMode: Filesystem

            size: 1Gi

      - name: pmem-data

        aerospike:

          path: /mnt/pmem0

        source:

          persistentVolume:

            storageClass: pmem-csi-sc-late-binding

            volumeMode: Filesystem

            size: 1.5Gi

      - name: pmem-index

        aerospike:

          path: /mnt/pmem1

        source:

          persistentVolume:

            storageClass: pmem-csi-sc-late-binding

            volumeMode: Filesystem

            size: 1.5Gi

      - name: aerospike-config-secret

        source:

          secret:

            secretName: aerospike-secret

        aerospike:

          path: /etc/aerospike/secret

  podSpec:

    multiPodPerHost: false

  aerospikeAccessControl:

    users:

      - name: admin

        secretName: auth-secret

        roles:

          - sys-admin

          - user-admin

          - data-admin

          - read

          - write

  aerospikeConfig:

    service:

      feature-key-file: /etc/aerospike/secret/features.conf

    security: { }

    network:

      service:

        port: 3000

      fabric:

        port: 3001

      heartbeat:

        port: 3002

    namespaces:

      - name: test

        replication-factor: 2

        storage-engine:

          type: pmem

          files:

            - /mnt/pmem0/test.data

          filesize: 1073741824

        index-type:

          type: pmem

          mounts:

            - /mnt/pmem1

          mounts-budget: 1073741824
```

This example create storage volumes for

-   index on PMEM
-   storage on PMEM

Change the allocated PMEM size, namespace memory, and namespace file size limits based on your needs.

For the full CR file, see the [example PMEM cluster CR](https://github.com/aerospike/aerospike-kubernetes-operator/blob/v4.3.0/config/samples/pmem_cluster_cr.yaml).

This and other example CRs are available in [the main Aerospike Kubernetes Operator repository](https://github.com/aerospike/aerospike-kubernetes-operator/tree/v4.3.0/config/samples).

Save and exit the CR file, then use `kubectl` to apply the change.

Terminal window

```shell
kubectl apply -f aerospike-cluster.yaml
```