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

Procedure

  1. Use the following template to deploy the Flexvolume plug-in in a cluster.

    FlexVolume is a storage plug-in 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
    provisioner: alicloud/disk
    parameters:
      type: available
      fstype: ntfs
    ---
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: alicloud-disk-controller-runner
    rules:
      - apiGroups: [""]
        resources: ["persistentvolumes"]
        verbs: ["get", "list", "watch", "create", "delete"]
      - apiGroups: [""]
        resources: ["persistentvolumeclaims"]
        verbs: ["get", "list", "watch", "update"]
      - apiGroups: ["storage.k8s.io"]
        resources: ["storageclasses"]
        verbs: ["get", "list", "watch"]
      - apiGroups: [""]
        resources: ["events"]
        verbs: ["list", "watch", "create", "update", "patch"]
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: alicloud-disk-controller
      namespace: kube-system
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: run-alicloud-disk-controller
    subjects:
      - kind: ServiceAccount
        name: alicloud-disk-controller
        namespace: kube-system
    roleRef:
      kind: ClusterRole
      name: alicloud-disk-controller-runner
      apiGroup: rbac.authorization.k8s.io
    ---
    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: alicloud-disk-controller-windows
      namespace: kube-system
    spec:
      replicas: 1
      strategy:
        type: Recreate
      template:
        metadata:
          labels:
            app: alicloud-disk-controller
        spec:
          nodeSelector:
            beta.kubernetes.io/os: windows
          tolerations:
          -key: "os"
            operator: "Equal"
            value: "windows"
            effect: "NoSchedule"
          - effect: NoSchedule
            operator: Exists
            key: node-role.kubernetes.io/master
          - effect: NoSchedule
            operator: Exists
            key: node.cloudprovider.kubernetes.io/uninitialized
          serviceAccount: alicloud-disk-controller
          serviceAccountName: alicloud-disk-controller
          containers:
            - name: alicloud-disk-controller
              image: registry.cn-hangzhou.aliyuncs.com/acs/alicloud-disk-controller:v1.12.6.64f4aa74-windows1809
              env:
              -name: OS_PLATFORM
                value: "windows"
              volumeMounts:
                - name: cloud-config
                  mountPath: 'C:\etc\kubernetes'
                - name: logdir
                  mountPath: 'C:\var\log\alicloud'
          volumes:
            - name: cloud-config
              hostPath:
                path: 'C:\etc\kubernetes'
                type: DirectoryOrCreate
            - name: logdir
              hostPath:
                path: 'C:\var\log\alicloud'
                type: DirectoryOrCreate
    ---
    apiVersion: extensions/v1beta1
    kind: DaemonSet
    metadata:
      name: flexvolume-windows
      namespace: kube-system
      labels:
        k8s-volume: flexvolume
    spec:
      selector:
        matchLabels:
          name: acs-flexvolume
      template:
        metadata:
          labels:
            name: acs-flexvolume
        spec:
          nodeSelector:
            beta.kubernetes.io/os: linux
          tolerations:
          -key: "os"
            operator: "Equal"
            value: "windows"
            effect: "NoSchedule"
          containers:
          - name: acs-flexvolume
            image: registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.12.6.b4d6e53-windows1809
            imagePullPolicy: Always
            command: ["pwsh.exe"]
            args: ["-Command", "/entrypoint-windows.ps1"]
            securityContext:
              privileged: true
            env:
            - name: ACS_DISK
              value: "true"
            resources:
              limits:
                memory: 200Mi
              requests:
                cpu: 100m
                memory: 200Mi
            volumeMounts:
            - name: usrdir
              mountPath: 'C:\host'
          volumes:
          - name: usrdir
            hostPath:
              path: 'C:\'
      updateStrategy:
        type: RollingUpdate
  2. To verify that Flexvolume is deployed, use the following YAML file to create a persistent volume claim (PVC) and a Deployment.
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: pvc-disk
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: alicloud-disk-ssd-windows
      resources:
        requests:
          storage: 20Gi
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: dynamic-create
      labels:
        app: nginx
    spec:
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          nodeSelector:
            beta.kubernetes.io/os: windows
          tolerations:
          -key: "os"
            operator: "Equal"
            value: "windows"
            effect: "NoSchedule"
          containers:
          - name: nginx
            image: registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:1.11.2.2af33e7-windows1809
            command: ["pwsh.exe"]
            args: ["-Command", "start-sleep 1000"]
            volumeMounts:
              - name: disk-pvc
                mountPath: 'C:\data'
          volumes:
            - name: disk-pvc
              persistentVolumeClaim:
                claimName: pvc-disk
    Run the kubectl get pv command to check whether the PV is automatically created.
    $ kubectl get pv
    NAME                     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM              STORAGECLASS        REASON   AGE
    	d-2zeh2yew2t48lu75joy1   20Gi       RWO            Delete           Bound    default/pvc-disk   alicloud-disk-ssd            2m46s