You can mount Server Message Block (SMB) file systems of Apsara File Storage NAS (NAS) to Windows containers that run in a Container Service for Kubernetes (ACK) cluster. This topic describes how to mount SMB file systems to Windows containers.

Prerequisites

Step 1: Deploy the FlexVolume plug-in

For more information, see the Deploy the FlexVolume plug-in in the ACK cluster section of the Mount Alibaba Cloud disks to Windows containers topic.

Step 2: Create a PV and a PVC

  1. Use the following YAML template to create a persistent volume (PV) and a persistent volume claim (PVC).
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      labels:
        alicloud-pvname: pv-smb
      name: pv-smb
    spec:
      accessModes:
      - ReadWriteMany
      capacity:
        storage: 5Gi
      flexVolume:
        driver: alicloud/smb.exe
        options:
          path: \myshare\test
          server: 25f3f4819c-eak52.cn-shenzhen.nas.aliyuncs.com
          user: workshop\administrator
          password: ***
      persistentVolumeReclaimPolicy: Retain	
    	
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvc-smb
    spec:
      accessModes:
      - ReadWriteMany
      resources:
        requests:
          storage: 5Gi
      selector:
        matchLabels:
          alicloud-pvname: pv-smb	
    	

    The following table describes the required parameters in the PV template.
    Parameter Description
    driver The driver that is used to mount the SMB file system. Set the value to alicloud/smb.exe.
    server The domain name of the mount target for the SMB file system. The mount target must be in the same VPC as the ACK cluster.
    path The path where the SMB file system is mounted. Set the value to \myshare or a subdirectory that starts with \myshare.
    user The username that is used to log on to a node. We recommend that you use workshop\administrator.
    password The password that is used to log on to a node.
  2. Run the kubectl get pvc |grep pvc-smb command to view the newly created PVC.
    The following output is returned:
    pvc-smb                    Bound    pv-smb                   5Gi        RWX                                         24h

Step 3: Deploy an application

  1. Use the following YAML template to deploy an application.
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: nginx-smb
      namespace: default
    spec:
      selector:
        matchLabels:
          app: nginx-smb
      template:
        metadata:
          labels:
            app: nginx-smb
        spec:
          replicas: 2
          tolerations:
          - effect: NoSchedule
            key: os
            operator: Equal
            value: windows
          containers:
          - args:
            - -Command
            - start-sleep 10000
            command:
            - pwsh.exe
            image: registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.16.9.7be0fa0-windows1809
            imagePullPolicy: IfNotPresent
            name: nginx
            volumeMounts:
            - mountPath: /data
              name: pvc-nas
          restartPolicy: Always
          volumes:
          - name: pvc-nas
            persistentVolumeClaim:
              claimName: pvc-smb
  2. Run the kubectl get pod command to view the state of the application.
    The following output is returned:
    NAME                        READY   STATUS    RESTARTS   AGE
    nginx-smb-965fb4597-jz6fv   1/1     Running   0          95s
    nginx-smb-965fb4597-zvbhk   1/1     Running   0          42s
    If the application is in the Running state, the application is created.