You can use Alibaba Cloud disks as the storage resources for Windows containers that run in a Container Service for Kubernetes (ACK) cluster. This topic describes how to mount Alibaba Cloud disks to Windows containers.

Procedure

  1. Deploy the FlexVolume plug-in in the ACK cluster.
    1. Create a YAML file.

      Use the following template to create a YAML file, and deploy the FlexVolume plug-in in the ACK cluster. Then, create a StorageClass in the Windows environment, and update the default component alicloud-disk-controller in the ACK cluster. This allows you to mount Alibaba Cloud disks as Windows persistent volumes (PVs).

      FlexVolume is a storage plug-in that is supported by Kubernetes. For more information, see Volume plug-ins.

      kind: StorageClass
      apiVersion: storage.k8s.io/v1
      metadata:
        name: alicloud-disk-common-windows
      provisioner: alicloud/disk
      parameters:
        type: cloud
        fstype: ntfs
      ---
      kind: StorageClass
      apiVersion: storage.k8s.io/v1
      metadata:
        name: alicloud-disk-efficiency-windows
      provisioner: alicloud/disk
      parameters:
        type: cloud_efficiency
        fstype: ntfs
      ---
      kind: StorageClass
      apiVersion: storage.k8s.io/v1
      metadata:
        name: alicloud-disk-ssd-windows
      provisioner: alicloud/disk
      parameters:
        type: cloud_ssd
        fstype: ntfs
      ---
      kind: StorageClass
      apiVersion: storage.k8s.io/v1
      metadata:
        name: alicloud-disk-available-windows
      provisioner: alicloud/disk
      parameters:
        type: available
        fstype: ntfs
      ---
      apiVersion: extensions/v1beta1
      kind: Deployment
      metadata:
        name: alicloud-disk-controller
        namespace: kube-system
      spec:
        selector:
          matchLabels:
            app: alicloud-disk-controller
        template:
          metadata:
            labels:
              app: alicloud-disk-controller
          spec:
            affinity:
              nodeAffinity:
                preferredDuringSchedulingIgnoredDuringExecution:
                - preference:
                    matchExpressions:
                    - key: node-role.kubernetes.io/master
                      operator: Exists
                  weight: 1
                requiredDuringSchedulingIgnoredDuringExecution:
                  nodeSelectorTerms:
                  - matchExpressions:
                    - key: type
                      operator: NotIn
                      values:
                      - virtual-kubelet
            containers:
            - env:
              - name: OS_PLATFORM
                value: windows
              image: registry-vpc.cn-shenzhen.aliyuncs.com/acs/alicloud-disk-controller:v1.16.9.54-a6c644bd-aliyun
              imagePullPolicy: IfNotPresent
              livenessProbe:
                exec:
                  command:
                  - sh
                  - -c
                  - ls /alicloud-disk-controller
                failureThreshold: 8
                initialDelaySeconds: 15
                periodSeconds: 10
                successThreshold: 1
                timeoutSeconds: 15
              name: alicloud-disk-controller
              resources:
                limits:
                  cpu: 100m
                  memory: 100Mi
                requests:
                  cpu: 100m
                  memory: 100Mi
              volumeMounts:
              - mountPath: /etc/kubernetes/
                name: cloud-config
              - mountPath: /var/log/alicloud/
                name: logdir
              - mountPath: /var/addon
                name: addon-token
                readOnly: true
            nodeSelector:
              beta.kubernetes.io/os: linux
            serviceAccount: admin
            serviceAccountName: admin
            volumes:
            - hostPath:
                path: /etc/kubernetes/
                type: ""
              name: cloud-config
            - hostPath:
                path: /var/log/alicloud/
                type: ""
              name: logdir
            - name: addon-token
              secret:
                defaultMode: 420
                items:
                - key: addon.token.config
                  path: token-config
                secretName: addon.csi.token
      ---
      apiVersion: extensions/v1beta1
      kind: DaemonSet
      metadata:
        labels:
          k8s-volume: flexvolume
        name: flexvolume-windows
        namespace: kube-system
      spec:
        selector:
          matchLabels:
            name: acs-flexvolume
        template:
          metadata:
            labels:
              name: acs-flexvolume
          spec:
            containers:
            - args:
              - -Command
              - /entrypoint-windows.ps1
              command:
              - pwsh.exe
              env:
              - name: ACS_DISK
                value: "true"
              - name: ACS_NAS
                value: "true"
              - name: ACS_SMB
                value: "true"
              image: registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.16.9.7be0fa0-windows1809
              imagePullPolicy: Always
              name: acs-flexvolume
              resources:
                limits:
                  memory: 200Mi
                requests:
                  cpu: 100m
                  memory: 200Mi
              securityContext:
                privileged: true
              volumeMounts:
              - mountPath: C:\host
                name: usrdir
            nodeSelector:
              beta.kubernetes.io/os: windows
            tolerations:
            - effect: NoSchedule
              key: os
              operator: Equal
              value: windows
            volumes:
            - hostPath:
                path: C:\
                type: ""
              name: usrdir
        updateStrategy:
          rollingUpdate:
            maxUnavailable: 1
          type: RollingUpdate	  
      	  

    2. In the command-line interface (CLI), enter kubectl apply -f <YAML file name>.yaml to deploy the plug-in.
  2. Create an application.
    1. Use the following YAML template to create a persistent volume claim (PVC) and a StatefulSet. This allows you to check whether the storage plug-in works as expected.
      apiVersion: v1
      kind: Service
      metadata:
        name: nginx
        labels:
          app: nginx
      spec:
        ports:
        - port: 80
          name: web
        clusterIP: None
        selector:
          app: nginx
      ---
      apiVersion: apps/v1beta2
      kind: StatefulSet
      metadata:
        name: disk-windows
      spec:
        selector:
          matchLabels:
            app: nginx
        serviceName: "nginx"
        replicas: 1
        template:
          metadata:
            labels:
              app: nginx
          spec:
            tolerations:
            - effect: NoSchedule
              key: os
              operator: Equal
              value: windows
            containers:
            - name: nginx
              image: registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.16.9.7be0fa0-windows1809
              command: ["pwsh.exe"]
              args: ["-Command", "start-sleep 10000"]
              volumeMounts:
                - name: disk-essd
                  mountPath: "C:\\data"
        volumeClaimTemplates:
        - metadata:
            name: disk-essd
          spec:
            accessModes: [ "ReadWriteOnce" ]
            storageClassName: alicloud-disk-essd-windows
            resources:
              requests:
                storage: 20Gi
    If the storage plug-in is deployed, after you run the kubectl get pv command, the PV is automatically created.
    The following output is returned:
    NAME                     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM              STORAGECLASS        REASON   AGE
    d-2zeh2yew2t48lu75joy1   20Gi       RWO            Delete           Bound    default/pvc-disk   alicloud-disk-ssd            2m46s