您可以在ACK Window容器上使用云盘存储资源。本文介绍如何在Windows容器上使用云盘。

操作步骤

  1. 部署插件。
    1. 创建YAML文件。

      使用以下模板创建YAML文件在集群中部署Flexvolume组件,创建Windows环境下的StorageClass,以及更新集群中默认安装的alicloud-disk-controller,使其支持Windows云盘PV的创建。

      Flexvolume是Kubernetes支持的一种存储插件扩展方式。详情请参见存储插件说明

      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. 执行kubectl apply -f <YAML文件名称>.yaml部署插件。
  2. 创建应用。
    1. 使用以下YAML模板创建PVC和StatefulSet验证存储组件是否可用。
      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
    如果存储组件成功部署,执行命令kubectl get pv会看到自动创建的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