Mount an Apsara File Storage NAS (NAS) file system to a Container Service for Kubernetes (ACK) cluster using the FlexVolume plug-in. This topic covers the YAML-based and console-based methods for creating a persistent volume (PV), then walks you through creating a persistent volume claim (PVC) and deploying a pod that uses the NAS-backed storage.
Prerequisites
Before you begin, ensure that you have:
-
A NAS file system with a mount target added. Create one in the NAS console. The mount target and the ACK cluster must be in the same virtual private cloud (VPC).
NAS console -
FlexVolume upgraded to the latest version in your cluster.
-
kubectl configured to connect to the cluster. For details, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
How it works
Mounting a NAS file system to an ACK cluster involves three steps:
-
Create a PV — As a cluster administrator, define a PV backed by the NAS file system. The PV is not yet associated with any workload.
-
Create a PVC — Claim the PV. Kubernetes binds the PVC to a matching PV based on storage class, access mode, and capacity.
-
Deploy a pod — Reference the PVC in your Deployment. The NAS file system is mounted into the container at the specified path.
After FlexVolume is installed in the cluster, it handles the mount and unmount operations using the NFS protocol.
Step 1: Create a PV
Create a PV using a YAML file or the ACK console.
Option 1: YAML file
Save the following as nas-pv.yaml, then run kubectl apply -f nas-pv.yaml.
Replace <mount-target-domain> with your NAS mount target domain name, and <subdirectory> with the path in the NAS file system to mount (for example, /k8s).
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-nas
spec:
capacity:
storage: 5Gi
storageClassName: nas
accessModes:
- ReadWriteMany
flexVolume:
driver: "alicloud/nas"
options:
server: "<mount-target-domain>"
path: "<subdirectory>"
vers: "3"
options: "nolock,tcp,noresvport"
Verify the PV was created and is in the Available state:
kubectl get pv pv-nas
Expected output:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS AGE
pv-nas 5Gi RWX Retain Available nas 5s
Option 2: ACK console
-
Log on to the ACK console.
-
In the left-side navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster or click Details in the Actions column.
-
In the left-side navigation pane, choose Volumes > Persistent Volumes.
-
Click Create in the upper-right corner.
-
In the Create PV dialog box, configure the parameters described in the following table.
| Parameter | Description | Required | Default |
|---|---|---|---|
| PV type | Select NAS. | Yes | — |
| Volume name | A unique name for the PV within the cluster. For example: pv-nas. |
Yes | — |
| Volume plug-in | Select Flexvolume. | Yes | — |
| Capacity | The capacity of the PV. Cannot exceed the capacity of the NAS file system. | Yes | — |
| Access mode | The access mode. NAS file systems support ReadWriteMany, which allows multiple nodes to read and write simultaneously. | Yes | ReadWriteMany |
| Mount target domain name | The domain name of the NAS mount target. See Manage mount targets. | Yes | — |
| Subdirectory | A subdirectory in the NAS file system, starting with /. If the subdirectory does not exist, it is created automatically. Leave blank to mount the root directory. For Extreme NAS file systems, the path must start with /share. |
No | Root directory |
| Permissions | Access permissions on the mounted directory, such as 755, 644, or 777. Applicable only when mounting a subdirectory. If the directory contains a large number of files, avoid setting this parameter to prevent the chmod command from running for an extended period. |
No | Original permissions |
| chmod (Change Mode) | How permission changes are applied: Non-recursive (affects only the mounted directory) or Recursive (affects the mounted directory and all subdirectories and files). For FlexVolume versions earlier than V1.14.6.15-8d3b7e7-aliyun, permissions are always applied recursively. For V1.14.6.15-8d3b7e7-aliyun and later, use this parameter to control the scope. | No | — |
| Version | The NFS protocol version. NFSv3 is recommended. Extreme NAS file systems support NFSv3 only. | No | NFSv3 |
| Labels | Labels to add to the PV. | No | — |
-
Click Create.
If you select Recursive for a mounted directory with a large number of files, the chmod command may run for an extended time, causing the mount or unmount operation to fail.
Step 2: Create a PVC
Save the following as nas-pvc.yaml, then run kubectl apply -f nas-pvc.yaml.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nas
spec:
accessModes:
- ReadWriteMany
storageClassName: nas
resources:
requests:
storage: 5Gi
Kubernetes binds the PVC to the pv-nas PV based on matching storage class, access mode, and capacity. Verify the binding:
kubectl get pvc pvc-nas
Expected output:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-nas Bound pv-nas 5Gi RWX nas 5s
A STATUS of Bound confirms the PVC is linked to the PV.
Step 3: Deploy a pod
Save the following as nas-pod.yaml, then run kubectl apply -f nas-pod.yaml.
The NAS file system is mounted at /data inside the container.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nas-static
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: pvc-nas
mountPath: /data
volumes:
- name: pvc-nas
persistentVolumeClaim:
claimName: pvc-nas
Verify the pod is running and the volume is mounted:
kubectl get pods -l app=nginx
Expected output:
NAME READY STATUS RESTARTS AGE
nas-static-xxxxxxxxx-xxxxx 1/1 Running 0 30s
To confirm the NAS file system is mounted inside the container, run:
kubectl exec -it <pod-name> -- df -h | grep /data
The output shows the NAS file system mounted at /data.