Skip to content

Setting Up Persistent Storage for the Connector Pods

Alexandros Tzortzis edited this page Dec 3, 2024 · 1 revision

Setting Up Persistent Storage for the Connector Pods

To persistently store artifacts and ensure they are available even if the connector pod is down, you'll need to configure a Persistent Volume (PV) and a Persistent Volume Claim (PVC). Follow the steps below to set it up.

What are Persistent Volumes (PV) and Persistent Volume Claims (PVC)?

  • Persistent Volume (PV): A PV is a piece of storage in your cluster that has been provisioned by an administrator. It represents a physical or cloud storage resource, such as a disk or network file share. The PV provides a way to abstract storage and make it available to your applications in a Kubernetes cluster.

  • Persistent Volume Claim (PVC): A PVC is a request for storage by a user. It specifies the size and access modes of the storage required. A PVC will bind to a PV that meets its criteria, and once bound, it is used by the application. PVCs are used by pods to store data persistently, even if the pod is deleted or recreated.

Step 1: Check Available Storage Space

Before creating the PV and PVC, you need to verify that there is enough storage available on your host machine.

  1. Use the df -h command to view available storage:

    df -h

    Example output:

    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1        50G   20G   30G  40% /
    /dev/sdb1       100G   10G   90G  10% /mnt/data
  2. Identify a directory or disk with sufficient free space for the persistent volume (e.g., /mnt/data).

  3. Create the directory for the PV:

    sudo mkdir -p /mnt/data/ids-connector-pv
    sudo chmod 777 /mnt/data/ids-connector-pv

Step 2: Create the Persistent Volume (PV)

  1. Create a ids-connector-pv.yaml file with the following content:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: ids-connector-pv
    spec:
      capacity:
        storage: 10Gi                                                # Size for the PV
      accessModes:
        - ReadWriteOnce                                          # Access mode for the PV
      persistentVolumeReclaimPolicy: Retain          #  Keep the PV even if PVC is deleted
      hostPath:
        path: /mnt/data/ids-connector-pv               # Path you created on the host
  2. Apply the ids-connector-pv.yaml configuration to create the PV:

    microk8s kubectl apply -f ids-connector-pv.yaml

Step 3: Create the Persistent Volume Claim (PVC)

  1. Create a ids-connector-pvc.yaml file with the following content:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: ids-connector-pvc
      namespace: provider-namespace              # Same namespace as your connector pods
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi                                         # Must match the PV's size
      volumeName: ids-connector-pv                # Bind this PVC to the existing PV
      storageClassName: ""                                # This ensures it won't try to match a non-existent storage class
  2. Apply the ids-connector-pvc.yaml configuration to create the PVC:

    microk8s kubectl apply -f ids-connector-pvc.yaml
  3. Verify that the PV and PVC have been created and bound successfully:

    microk8s kubectl get pv ids-connector-pv

    Example output:

    NAME               CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                  STORAGECLASS   VOLUMEATTRIBUTESCLASS   REASON   AGE
    ids-connector-pv   10Gi       RWO            Retain           Bound    provider-namespace/ids-connector-pvc                  <unset>                          126m
    microk8s kubectl get pvc ids-connector-pvc -n provider-namespace

    Example output:

    NAME                STATUS   VOLUME             CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
    ids-connector-pvc   Bound    ids-connector-pv   10Gi       RWO                           <unset>                 69m

Step 4: Update the values.yaml for the Connector Pod

To reference the manually created PVC in your connector pod, update the values.yaml file for your connector pod configuration.

  1. Add/Update the ids.persistentVolume section in values.yaml:

    persistentVolume:
      name: ids-connector-pvc            # Reference the manually created PVC
      mountPath: /resources              # Path inside the container where data will be stored (default: /resources)
      storageSize: 10Gi                        # Match the PV and PVC size
      storageClassName: ""                 # Match the PV's storageClassName
      disableClaim: true                       # Prevent Helm from creating new PVCs

Note: The mountPath in the values.yaml should point to /resources or the ids.artifacts.location should point to the mountPath that you require. This is because the application needs to know where to put the artifacts on the disk from the perspective of the container to ensure the PVC is used. You can find more information regarding how the values.yaml is written here: TSG Connector Helm Chart.

Step 5: Verify the Setup

Once the pod is deployed, verify that it can correctly mount the persistent volume by checking the pod status and logs.

Also, try to add artifacts, then uninstall and re-install the connector to ensure that they still are there.