democratic-csi

repository·master·Indexed 23 days ago

https://github.com/democratic-csi/democratic-csi

A Kubernetes CSI driver framework providing storage via iSCSI, NFS, SMB, and NVMe-oF. It specializes in ZFS-based systems such as FreeNAS, TrueNAS, and ZFS on Linux (ZoL), while also offering local ZFS drivers, hostpath provisioning, and support for other backends like Synology, ObjectiveFS, and Lustre. Version 1.9.0 supports advanced CSI features including resizing, snapshots, and clones.

Tokens
25K
Snippets
27
Records
124
Agent score
79%

What's inside democratic-csi

  1. Overview of democratic-csi drivers and capabilities

    master

    democratic-csi implements the Container Storage Interface (CSI) specification to provide storage for container orchestration systems like Kubernetes. It supports advanced CSI features including resizing, snapshots, and clones.

    The project provides several driver implementations categorized by their backend and protocol:

    ZFS-based Drivers (FreeNAS / TrueNAS)

    • freenas-nfs: Manages ZFS datasets shared over NFS.
    • freenas-iscsi: Manages ZFS zvols shared over iSCSI.
    • freenas-smb: Manages ZFS datasets shared over SMB.
    • freenas-nvmeof: Manages ZFS zvols shared over NVMe-oF.
    • freenas-api-* (experimental, SCALE only): API-based versions of the above drivers.

    ZFS-based Drivers (Generic ZoL, e.g., Ubuntu)

    • zfs-generic-nfs: Works with any ZFS on Linux installation.
    • zfs-generic-iscsi: Works with any ZFS on Linux installation.
    • zfs-generic-smb: Works with any ZFS on Linux installation.
    • zfs-generic-nvmeof: Works with any ZFS on Linux installation.

    Local ZFS Drivers

    • zfs-local-ephemeral-inline: Provisions node-local ZFS datasets.
    • zfs-local-dataset: Provisions node-local volumes as datasets.
    • zfs-local-zvol: Provisions node-local volumes as zvols.

    Other Drivers

    • synology-iscsi (experimental): Manages Synology volumes over iSCSI.
    • objectivefs: Manages ObjectiveFS volumes.
    • lustre-client: Provisions storage using a shared Lustre share/directory.
    • nfs-client: Provisions storage using a shared NFS share/directory.
    • smb-client: Provisions storage using a shared SMB share/directory.
    • local-hostpath: Provisions node-local directories.
    • node-manual: Connects to manually created SMB, NFS, Lustre, OneClient, NVMe-oF, or iSCSI volumes.
    • containerd-oci-ephemeral-inline: Provisions ephemeral RW node-local storage using OCI images.
    • vhd-ephemeral-inline: Provisions ephemeral RW node-local storage using VHD images.
  2. How ZFS and Hostpath drivers work (Topology and Multi-node)

    master

    The zfs-local-ephemeral-inline, zfs-local-{dataset,zvol}, and local-hostpath drivers are designed for node-local storage.

    Key Behaviors:

    • Topology Constraints: Although these drivers report MULTI_NODE (ReadWriteMany/RWX) support for ease of use, they are implicitly single-node. Kubernetes topology constraints ensure that workloads are automatically scheduled on the specific node where the volume was provisioned.
    • ZFS Requirements: For ZFS drivers, each node must have an identically named ZFS pool available to the driver.
    • Hostpath Limitations: The local-hostpath driver requires an identically named folder on each node. Note that this driver does not enforce quotas; requested volume sizes are generally ignored.
  3. Deploy multiple democratic-csi instances in one cluster

    master

    You can install multiple deployments of the same or different drivers in a single cluster. To avoid conflicts, ensure the following:

    1. Helm Release: Use a unique Helm release name for each deployment.
    2. CSI Driver Name: Each deployment must have a unique csiDriver.name in its values file.
    3. Storage Classes: Use unique names for your storage classes per cluster.
    4. Parent Datasets: Use a unique parent dataset for each deployment.
    5. Global Asset Names: For iscsi and smb, asset/share names are global. Use nameTemplate, namePrefix, and nameSuffix configuration options to prevent name collisions.
  4. Prepare ZoL (ZFS on Linux) servers for democratic-csi

    master

    For ZoL drivers (zfs-generic-*), ensure ssh and zfs are installed on the server and that targetcli is present. It is recommended to disable motd details for the SSH user to prevent CPU spikes.

    Package Installation by Protocol

    NFS

    yum install -y nfs-utils
    systemctl enable --now nfs-server.service
    
    # OR for Debian/Ubuntu
    apt-get install -y nfs-kernel-server
    systemctl enable --now nfs-kernel-server.service

    iSCSI

    yum install targetcli -y
    apt-get -y install targetcli-fb

    SMB

    apt-get install -y samba smbclient
    
    # Create a POSIX user
    groupadd -g 1001 smbroot
    useradd -u 1001 -g 1001 -M -N -s /sbin/nologin smbroot
    # Set password (required for client mount options)
    smbpasswd -L -a smbroot

    NVMe-over-Fabrics (nvmeof)

    1. Load modules: nvmet, nvmet-tcp, nvmet-fc, nvmet-rdma.
    2. Install nvmetcli and configshell_fb via pip or setup.py.
    3. Configure a systemd unit (nvmet.service) to manage the service.
    4. Manually create ports using nvmetcli (e.g., TCP port 4420 on 0.0.0.0).
    # Example: NFS setup on RHEL
    yum install -y nfs-utils
    systemctl enable --now nfs-server.service
  5. Enable CHAP Authentication for `synology-iscsi`

    master

    To enable CHAP Authentication, you must provide a Kubernetes Secret referenced by the StorageClass.

    Configuration Steps

    1. Create a Secret containing the lunTemplate, targetTemplate, and lunSnapshotTemplate.
    2. Define Credentials in the targetTemplate section of the secret:
      • user: Client username
      • password: Client password
      • mutualUser: (Optional) Server username for mutual CHAP
      • mutualPassword: (Optional) Server password for mutual CHAP
    3. Reference the Secret in your StorageClass using the following keys:
      • csi.storage.k8s.io/provisioner-secret-name
      • csi.storage.k8s.io/provisioner-secret-namespace

    Usage Patterns

    • Global Credentials: Use a static secret name for all volumes in the StorageClass.
    • Per-PVC Credentials: Use substitution syntax (e.g., ${pvc.name}-chap-secret) to allow different credentials per volume.

    Important Notes

    • CHAP is only enabled if the secret contains both a username and a password. If a password is missing, the volume is still created but without CHAP.
    • You cannot change the password or toggle CHAP after the volume has been created.
    • If the referenced secret is missing, the volume creation will fail.
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: synology-iscsi-chap
    parameters:
      fsType: ext4
      lunTemplate: |
        type: BLUN
        description: iSCSI volumes with CHAP Authentication
    secrets:
      # Use this to configure a single set of credentials for all volumes of this StorageClass
      csi.storage.k8s.io/provisioner-secret-name: chap-secret
      csi.storage.k8s.io/provisioner-secret-namespace: default
      # Use substitutions to use different credentials for volumes based on the PVC
      csi.storage.k8s.io/provisioner-secret-name: "${pvc.name}-chap-secret"
      csi.storage.k8s.io/provisioner-secret-namespace: "${pvc.namespace}"
    ---
    # Use a secret like this to supply CHAP credentials.
    apiVersion: v1
    kind: Secret
    metadata:
      name: chap-secret
    stringData:
      lunTemplate: |
        ...
      targetTemplate: |
        # Client Credentials
        user: client
        password: MySecretPassword
        # Mutual CHAP Credentials. If these are specified mutual CHAP will be enabled.
        mutualUser: server
        mutualPassword: MyOtherPassword
      lunSnapshotTemplate: |
        ...
  6. Configure Multipath for iSCSI on RHEL/CentOS and Ubuntu/Debian

    master

    The iscsi-based drivers support multipath. You should configure multipath on your host nodes to ensure redundancy and performance.

    #### RHEL / CentOS
    # Enable multipathing
    sudo mpathconf --enable --with_multipathd y
    
    # Ensure that iscsid and multipathd are running
    sudo systemctl enable iscsid multipathd
    sudo systemctl start iscsid multipathd
    
    # Start and enable iscsi
    sudo systemctl enable iscsi
    sudo systemctl start iscsi
    
    #### Ubuntu / Debian
    # Enable multipathing
    sudo tee /etc/multipath.conf <<-'EOF'
    defaults {
        user_friendly_names yes
        find_multipaths yes
    }
    EOF
    
    sudo systemctl enable multipath-tools.service
    sudo service multipath-tools restart
    
    # Ensure that open-iscsi and multipath-tools are enabled and running
    sudo systemctl status multipath-tools
    sudo systemctl enable open-iscsi.service
    sudo service open-iscsi start
    sudo systemctl status open-iscsi
  7. Grant privileged access to the democratic-csi namespace

    master

    democratic-csi requires privileged access to the nodes. You must ensure the namespace used for the installation allows privileged pods by applying the appropriate Pod Security Admission label.

    kubectl label --overwrite namespace democratic-csi pod-security.kubernetes.io/enforce=privileged
  8. Register volumes in Nomad using Terraform

    master

    After creating a volume externally, you must register it with Nomad so it can be used in jobs. While the Nomad CLI can do this, using the Terraform nomad_volume resource is recommended.

    When registering, you must map the metadata returned by the csc command (such as node_attach_driver, provisioner_driver, server, and share) into the context block of the Terraform resource.

    provider "nomad" {
      address = "<nomad address>"
    }
    
    resource "nomad_volume" "<volume name>" {
      type                  = "csi"
      plugin_id             = "truenas"
      volume_id             = "<volume name>"
      name                  = "<volume name>"
      external_id           = "<volume name>"
      access_mode           = "single-node-writer"
      attachment_mode       = "file-system"
      deregister_on_destroy = true
    
      mount_options = {
        fs_type = "nfs"
      }
    
      context = {
        node_attach_driver = "nfs"
        provisioner_driver = "freenas-nfs"
        server             = "<server>"
        share              = "<share>"
      }
    }
  9. Configure NVMe-over-Fabrics (nvmeof)

    master

    To use nvmeof drivers, you must ensure the necessary kernel modules are loaded on the host. While tools are included in the democratic-csi images, the host must have the modules available.

    # Load modules immediately
    cat <<EOF > /etc/modules-load.d/nvme.conf
    nvme
    nvme-tcp
    nvme-fc
    nvme-rdma
    EOF
    
    modprobe nvme
    modprobe nvme-tcp
    modprobe nvme-fc
    modprobe nvme-rdma
    
    # RedHat recommends DM multipath
    # kernel arg: nvme_core.multipath=N
  10. Migrate from freenas-provisioner to democratic-csi

    master

    If you are currently using the non-CSI freenas-provisioner or freenas-iscsi-provisioner, you can migrate your existing volumes to democratic-csi.

    The project provides a migration script located at contrib/freenas-provisioner-to-democratic-csi.sh. To use it:

    1. Copy the script to your workstation.
    2. Review the script logic in detail.
    3. Edit the script variables to match your environment.
    4. Execute the script to begin the migration process.
  11. Configure kubelet host path for non-standard distributions

    master

    If you are using distributions like microk8s, pivotal, or k0s, you must provide the correct kubeletHostPath in your Helm installation to ensure the CSI driver can communicate with the kubelet.

    Common paths:

    • microk8s: /var/snap/microk8s/common/var/lib/kubelet
    • pivotal: /var/vcap/data/kubelet
    • k0s: /var/lib/k0s/kubelet
    microk8s helm upgrade \
      --install \
      --values freenas-nfs.yaml \
      --set node.kubeletHostPath="/var/snap/microk8s/common/var/lib/kubelet"  \
      --namespace democratic-csi \
    zfs-nfs democratic-csi/democratic-csi
  12. Enable Volume Snapshot Support

    master

    To use volume snapshots with democratic-csi, you must first install a snapshot controller in your Kubernetes cluster. You can use the democratic-csi charts or the standard Kubernetes external-snapshotter.

    Once the controller is installed, deploy democratic-csi as usual, ensuring you define volumeSnapshotClasses in your configuration to match your storage backend requirements.

    # Option 1: democratic-csi snapshot controller
    https://github.com/democratic-csi/charts/tree/master/stable/snapshot-controller
    
    # Option 2: kubernetes-csi external-snapshotter
    - https://github.com/kubernetes-csi/external-snapshotter/tree/master/client/config/crd
    - https://github.com/kubernetes-csi/external-snapshotter/tree/master/deploy/kubernetes/snapshot-controller