ACK-Windows节点上使用云盘

环境要求

  • 创建Linux托管集群,添加OS为Windows的节点池来使用Windows节点

在集群上下发flexvolume组件

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
---
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: windows
      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

验证

部署后可以下发下面yaml定义的pvc和deploy来验证存储组件是否已经可用:

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

如果组件正常,可以看到自动创建出的pv:

$ 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
上一篇:《开源容器云OpenShift:构建基于Kubernetes的企业应用云平台》一1.5 OpenShift社区版与企业版


下一篇:[算法系列之九]Karatsuba快速相乘算法