Learn how to use iSCSI for persistent volumes in k3s on a Raspberry Pi, with a Synology NAS as the iSCSI target. This guide will walk you through setting up the iSCSI target and configuring your Kubernetes deployment.

Using iSCSI for Persistent Volumes in k3s on Raspberry Pi

The default option for persistent volumes in k3s is local-path, which provisions storage on the node’s local disk. This ties the container to a specific node. To avoid this, we can use iSCSI. Here’s how to set up iSCSI with a Synology NAS as the target.

Setting up the iSCSI Target

Setting up the iSCSI target on a Synology NAS is straightforward:

  1. Log into the DS211.
  2. Open the main menu and choose “iSCSI Manager” (or “SAN Manager” in DSM 7.x).
  3. On the “Target” page, click “Create”.
  4. Give it a sensible name (e.g., “testing”) and edit the IQN, replacing “Target-1” with “testing”.
  5. Skip CHAP authentication if on a local, trusted network.
  6. Select “Create a new iSCSI LUN”, name it (e.g., “testing-LUN-1”), and choose the default location and capacity (1GB for testing).
  7. Choose between “Thick” and “Thin” provisioning.

Refer to these resources for additional guidance:

Installing the open-iscsi Package

Install the open-iscsi package on all cluster nodes:

sudo apt install open-iscsi

Mounting the Volume

Here’s what the deployment configuration looks like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: testing
  labels:
    app: testing
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testing
  template:
    metadata:
      labels:
        app: testing
        name: testing
    spec:
      containers:
      - name: ubuntu
        image: ubuntu:latest
        command: ["/bin/sleep", "7d"]
        volumeMounts:
        - name: testing-vol
          mountPath: /var/lib/testing
      volumes:
      - name: testing-vol
        iscsi:
          targetPortal: 172.25.22.100:3260
          iqn: iqn.2000-01.com.synology:ds211.testing.88a4c0ddef
          lun: 1
          readOnly: false

Troubleshooting

If the container refuses to mount the volume, ensure the open-iscsi package is installed and configured correctly. Run iscsid in debug mode for more details.

To manually mount the volume on a node, use:

sudo iscsiadm -m discovery -t sendtargets -p 172.25.22.100:3260
sudo iscsiadm -m node --targetname iqn.2000-01.com.synology:ds211.testing.88a4c0ddef --portal 172.25.22.100:3260 --login

Checking the Deployment

Verify the deployment and ensure the volume is mounted correctly:

sudo kubectl get endpoints testing
curl 10.42.1.20:4000

Following these steps, you can set up and use iSCSI for persistent volumes in k3s on a Raspberry Pi.