File and Object Storage

 View Only

Using IBM Spectrum Scale AFM along with CSI driver !

By Madhu Punjabi posted Tue April 12, 2022 10:45 AM



IBM Spectrum Scale CSI driver allows IBM Spectrum Scale to be used as persistent storage for containerised applications. Using the IBM Spectrum Scale CSI driver, Kubernetes persistent volumes (PVs) can be provisioned based on filesets or directories.

IBM Spectrum Scale has an asynchronous caching mechanism, Active File Management (AFM), which can be used to implement multisite use cases. Currently for using an AFM fileset with CSI driver, the AFM fileset can be static provisioned. This will ensure that data in the fileset will be used as is and not deleted after the application pod is deleted.

Let us see how to static provision a persistent volume for AFM when running stateful applications on Kubernetes or Red Hat OpenShift.

Deploying the IBM Spectrum Scale CSI Driver

To install the v2.5.0 of IBM Spectrum Scale CSI Driver, please check the IBM Documentation at

Deploying the IBM Spectrum Scale AFM

To install AFM with IBM Spectrum Scale v5.1.3-0, please check the IBM Documentation at

Let's Get Started !

Let us create sample filesets for AFM at IBM Spectrum Scale cluster. These filesets would be referred further in CSI volume provisioning examples.

Creating a sample AFM target fileset

$ mmcrfileset fs2 afm-target --inode-space new
Fileset afm-target created with id 11 root inode 3670019.

$ mmlinkfileset fs2 afm-target -J /ibm/fs2/afm-target
Fileset afm-target linked at /ibm/fs2/afm-target     

$ mmafmconfig enable /ibm/fs2/afm-target

Creating a sample AFM cache fileset

Before creating an AFM cache fileset, set one of the nodes in the IBM Spectrum Scale cluster as gateway node.

$ mmchnode --gateway -N
Wed Mar 23 01:55:08 PDT 2022: mmchnode: Processing node
mmchnode: Propagating the cluster configuration data to all
affected nodes. This is an asynchronous process.

Create a sample AFM cache fileset

$ mmcrfileset fs1 afm-cache --inode-space new -p afmtarget=gpfs:///ibm/fs2/afm-target -p afmmode=sw 
Fileset afm-cache created with id 140 root inode 16252931.

$ mmlinkfileset fs1 afm-cache -J /ibm/fs1/afm-cache
Fileset afm-cache linked at /ibm/fs1/afm-cache

Verify the the relationship between the AFM cache and target filesets

$ mmafmctl fs1 getstate 
Fileset Name Fileset Target Cache State Gateway Node Queue Length Queue numExec
------------ -------------- ------------- ------------ ------------ -------------
afm-cache gpfs:///ibm/fs2/afm-target Active mt-node-1 0 2

Create a sample directory under the AFM cache fileset

$ mkdir /ibm/fs1/afm-cache/sample
$ ls /ibm/fs2/afm-target/

Creating PV and PVC for using AFM fileset with IBM Spectrum Scale CSI driver

Now let us create static provisioned PV and PVC for using the AFM cache fileset on a Kubernetes or Redhat Openshift cluster.

Sample manifests for static provisioning of fileset based volume
To generate static provisioning manifests (PV and PVC), download the following script:

$ curl -O

To know how to use this script, please check

Below command shows an example to generate manifests for PV and PVC for the fileset 'afm-cache' within the filesystem 'fs1':

$ ./ --filesystem fs1 --fileset afm-cache --size 10 --pvname afmstaticpv --guihost mt-csi-scalegui
GUI Username: admin
GUI Password:
INFO: volumeHandle: 0;2;8809226123290901444;0A0B42BC:60D87CA7;;afm-cache;/ibm/fs1/afm-cache
INFO: Successfully created afmstaticpv.yaml
INFO: Successfully created pvc-afmstaticpv.yaml

Creating a Persistent Volume (PV)
Issue the below command to create a persistent volume (PV) using the manifest created in the previous step

$ kubectl apply -f afmstaticpv.yaml 
persistentvolume/afmstaticpv created

Note: All YAML files presented in this blog can be applied with kubectl apply -f <filename> on Kubernetes. Replace ‘kubectl’ with ‘oc’ for Red Hat OpenShift.

Creating a Persistent Volume Claim (PVC)
Update the manifest generated for creating PVC in a previous step to comment the below line or specify a namespace. When namespace is not specified, the PVC will get created in the current namespace.

# namespace: <PVC namespace>

Issue the below command to create a persistent volume claim (PVC) using the manifest updated in the previous step

$ kubectl apply -f pvc-afmstaticpv.yaml 
persistentvolumeclaim/pvc-afmstaticpv created

Creating a pod
Below example shows a sample pod definition for creating a nginx container using the PVC created for the AFM cache fileset.

$ cat afm-pod.yaml
apiVersion: v1
kind: Pod
name: csi-afm-staticdemo-pod
app: nginx
- name: web-server
image: nginx
- name: mypvc
mountPath: /usr/share/nginx/html/scale
- containerPort: 80
- name: mypvc
claimName: pvc-afmstaticpv
readOnly: false

Issue below command to create the pod.

$ kubectl apply -f afm-pod.yaml

Issue below commands to access the container inside the pod to read and write at the mounted path.

$ kubectl exec -it csi-afm-staticdemo-pod -c web-server -- bash 
root@csi-afm-staticdemo-pod:/# cd /usr/share/nginx/html/scale
root@csi-afm-staticdemo-pod:/usr/share/nginx/html/scale# ls
root@csi-afm-staticdemo-pod:/usr/share/nginx/html/scale# mkdir dirA
root@csi-afm-staticdemo-pod:/usr/share/nginx/html/scale# ls
dirA sample

Now verify the contents of the AFM cache fileset and AFM target fileset at the Spectrum Scale cluster.

$ cd /ibm/fs1/afm-cache
[root@mt-csi-scalegui 2022_04_05-18:18:36 afm-cache]$ ls
dirA sample

$ ls /ibm/fs2/afm-target
dirA sample

For more information on static provisioning of fileset or directory please refer
For information on creating pods referencing the persistent volume claim (PVC) check


1. IBM Spectrum Scale Container Storage Interface Driver Documentation

2. IBM Spectrum Scale AFM Documentation

#afm #csi#spectrumscale #redhatopenshift