日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

自動擴容云盤存儲卷

隨著業務發展和應用數據增長,當云盤使用空間不足時,您可以通過定義一種或多種擴容策略,在存儲卷的使用率高于某個閾值時自動擴容卷。本文介紹如何實現云盤存儲卷的自動擴容。

前提條件

注意事項

  • 支持在Kubernetes 1.16及以上版本的集群中使用,僅支持云盤擴容,不支持縮容。

  • 只有處于掛載狀態的云盤才支持擴容。

  • 依賴云盤的Resize能力。更多信息,請參見ResizeDisk

  • 觸發擴容的最大時間間隔為2 min,云盤擴容時間為1 min,請勿在3 min內將云盤寫滿。

  • 云盤最大容量為2000 GiB。

步驟一:開啟自動擴容

storage-operator組件中默認的storage-auto-expander負責自動擴容存儲資源。您需要執行以下命令,修改storage-operator的ConfigMap文件,以開啟自動擴容功能。

kubectl patch configmap/storage-operator \
  -n kube-system \
  --type merge \
  -p '{"data":{"storage-auto-expander":"{\"imageRep\":\"acs/storage-auto-expander\",\"imageTag\":\"\",\"install\":\"true\",\"template\":\"/acs/templates/storage-auto-expander/install.yaml\",\"type\":\"deployment\"}"}}'

步驟二:配置云盤自動擴容策略

  1. 在StorageClass存儲類中配置云盤自動擴容策略。

    推薦您使用ACK集群中默認創建的alicloud-disk-topology-alltype類型的StorageClass,該StorageClass能自適應為您選擇云盤類型,避免因實例規格限制、或所在可用區云盤余額不足導致云盤無法創建,增強可用性。

    若您的集群版本較低不支持該類型的StorageClass,您可以通過以下方式手動創建。

    1. 使用以下內容,創建storageclass.yaml文件。

      allowVolumeExpansion: true
      apiVersion: storage.k8s.io/v1
      kind: StorageClass
      metadata:
        name: alicloud-disk-topology-alltype
      parameters:
        type: cloud_essd,cloud_ssd,cloud_efficiency
      provisioner: diskplugin.csi.alibabacloud.com
      reclaimPolicy: Delete
      volumeBindingMode: WaitForFirstConsumer
    2. 執行以下命令,創建StorageClass。

      kubectl create -f storageclass.yaml
  2. 通過CRD(Custom Resource Definitions)創建自動擴容策略。

    1. 使用以下內容,創建StorageAutoScalerPolicy.yaml文件。

      apiVersion: storage.alibabacloud.com/v1alpha1
      kind: StorageAutoScalerPolicy
      metadata:
        name: hybrid-expand-policy
      spec:
        pvcSelector:
          matchLabels:
            app: mysql
        namespaces:
          - default
          - mysql
        conditions:
          - name: condition1
            key: volume-capacity-used-percentage
            operator: Gt
            values:
              - "80"
        actions:
          - name: action1
            type: volume-expand
            params:
              scale: 50Gi
              limits: 100Gi
          - name: action2
            type: volume-expand
            params:
              scale: 50%
              limits: 300Gi

      參數

      說明

      pvcSelector

      目標PVC,通過Label-Selector方式。本示例為mysql

      namespaces

      目標PVC所在的命名空間,多個命名空間時為或邏輯。若不配置,默認為default。本示例為defaultmysql

      conditions

      觸發規則的條件,多個condition時為與邏輯。每個condition包含以下參數:

      • key:定義一個Metric的類型。

      • volume-capacity-used-percentage:表示容量使用百分比。

      • operator:定義規則,包含Gt(大于)、Lt(小于)、Eq(等于)或Ne(不等于),不限制英文字母大小寫。

      • values:規則的具體數值。

      本示例表示當PVC容量的使用率高于80%時會觸發action

      actions

      滿足上述conditions時執行的操作,可以是多個操作。包含以下參數:

      • type:表示行為方式,目前只支持擴容。

      • scale:表示擴容的大小,單位為GiB,或可使用百分比。

      • limits:表示PVC在此action中的最大限制。

      actions中存在多個action時,則從首個action開始匹配,執行首個滿足條件的action,其余action跳過不執行。例如,本示例中的action1如果滿足條件,則執行action1,不會執行action2

      • 本示例的action1表示云盤容量在100 GiB內以50 GiB為單位擴容,最大擴容到100 GiB。

      • 本示例的action2表示當云盤容量大于100 GiB小于300 GiB時,以當前容量的50%擴容,即每次擴容后的總容量為擴容前容量的150%,最大擴容到300 GiB。

    2. 執行以下命令,創建自動擴容策略。

      kubectl create -f StorageAutoScalerPolicy.yaml
  3. 創建工作負載StatefulSet。

    1. 使用以下內容,創建StatefulSet.yaml文件。

       apiVersion: apps/v1
      kind: StatefulSet
      metadata:
        name: mysql
      spec:
        selector:
          matchLabels:
            app: mysql
        serviceName: mysql
        replicas: 3
        template:
          metadata:
            labels:
              app: mysql
          spec:
            containers:
            - name: mysql
              image: mysql:5.7
              env:
              - name: MYSQL_ROOT_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: mysql-pass
                    key: password
              ports:
              - containerPort: 80
                name: mysql
              volumeMounts:
              - name: pvc-disk
                mountPath: /data
        volumeClaimTemplates:
          - metadata:
              name: pvc-disk
              labels:
                app: mysql
            spec:
              accessModes: [ "ReadWriteOnce" ]
              storageClassName: "alicloud-disk-topology-alltype"
              resources:
                requests:
                  storage: 25Gi
      ---
      apiVersion: v1
      kind: Secret
      metadata:
        name: mysql-pass
      type: Opaque
      data:
        username: dGVz****             
        password: dGVzdDEt****     
    2. 執行以下命令,創建工作負載。

      kubectl create -f StatefulSet.yaml

步驟三:驗證云盤的自動擴容

  1. 向掛載目錄寫入數據,使云盤容量使用率高于80%。

    1. 執行以下命令,向掛載目錄寫入數據。

      dd if=<數據路徑> of=<掛載路徑>
    2. 執行以下命令,查看云盤容量詳情。

      df -h | grep d-****1

      預期輸出:

      Filesystem    Size   Used   Avail   Use%    Mounted on
      /dev/vde      25G    24G    1.5G    95%     /var/lib/kubelet/plugins/kubernetes.io/csi/pv/d-****1/globalmount
  2. 執行以下命令,查看擴容事件。

    當云盤容量使用率高于80%時會觸發擴容,此時action1滿足條件,則使用action1作為擴容策略。

    kubectl get events

    預期輸出:

    101s     Warning     StartExpand                persistentvolumeclaim/pvc-disk-mysql-1     Start to expand of pvc pvc-disk-mysql-1 from 25Gi to 75Gi, usedCapacityPercentage:94%, freeSize:1472MB.
    101s     Warning     ExternalExpanding          persistentvolumeclaim/pvc-disk-mysql-1     Ignoring the PVC: did't find a plugin capable of expanding the volume; waiting for an external controller to process this PVC.
    101s     Normal      Resizing                   persistentvolumeclaim/pvc-disk-mysql-1     External resizer is resizing volume d-****1
    97s      Normal      FileSystemResizeRequired   persistentvolumeclaim/pvc-disk-mysql-1     Require file system resize of volume on node
    96s      Warning     SkipExpand                 persistentvolumeclaim/pvc-disk-mysql-1     Pvc pvc-disk-mysql-1 is expanding status from 25Gi to 75Gi, this action action2 will skip.
  3. 執行以下命令,查看PVC的容量。

    kubectl get pvc

    預期輸出:

    NAME               STATUS     VOLUME     CAPACITY     ACCESS MODES     STORAGECLASS                      AGE
    pvc-disk-mysql-0   Bound      d-****0    25Gi         RWO              alicloud-disk-topology-alltype    22m
    pvc-disk-mysql-1   Bound      d-****1    75Gi         RWO              alicloud-disk-topology-alltype    21m
    pvc-disk-mysql-2   Bound      d-****2    25Gi         RWO              alicloud-disk-topology-alltype    21m

    從預期輸出可得,云盤d-****1已擴容到75 GiB。

  4. 根據步驟1,再次使云盤容量使用率高于80%,進行第二次擴容。

    執行以下命令,查看擴容事件。

    kubectl get events

    預期輸出:

    7m22s    Warning     StartExpand                persistentvolumeclaim/pvc-disk-mysql-1     Start to expand of pvc pvc-disk-mysql-1 from 100Gi to 150Gi, usedCapacityPercentage:95%, freeSize:3732MB.
    5m2s     Warning     ExternalExpanding          persistentvolumeclaim/pvc-disk-mysql-1     Ignoring the PVC: did't find a plugin capable of expanding the volume; waiting for an external controller to process this PVC.
    2m4s     Normal      Resizing                   persistentvolumeclaim/pvc-disk-mysql-1     External resizer is resizing volume d-****1
    3m4s     Normal      FileSystemResizeRequired   persistentvolumeclaim/pvc-disk-mysql-1     Require file system resize of volume on node
    5m59s    Warning     SkipExpand                 persistentvolumeclaim/pvc-disk-mysql-1     Pvc pvc-disk-mysql-1 is expanding status from 100Gi to 150Gi, this action action1 will skip.

    由于action1limit為100 GiB,從預期輸出可得,此次只能將云盤從75 GiB擴容到100 GiB。

  5. 根據步驟1,再次使云盤容量使用率高于80%,進行第三次擴容。

    執行以下命令,查看擴容事件。

    kubectl get events

    預期輸出:

    7m22s    Warning     StartExpand                persistentvolumeclaim/pvc-disk-mysql-1     Start to expand of pvc pvc-disk-mysql-1 from 100Gi to 150Gi, usedCapacityPercentage:95%, freeSize:3732MB.
    5m2s     Warning     ExternalExpanding          persistentvolumeclaim/pvc-disk-mysql-1     Ignoring the PVC: did't find a plugin capable of expanding the volume; waiting for an external controller to process this PVC.
    2m4s     Normal      Resizing                   persistentvolumeclaim/pvc-disk-mysql-1     External resizer is resizing volume d-****1
    3m4s     Normal      FileSystemResizeRequired   persistentvolumeclaim/pvc-disk-mysql-1     Require file system resize of volume on node
    5m59s    Warning     SkipExpand                 persistentvolumeclaim/pvc-disk-mysql-1     Pvc pvc-disk-mysql-1 is expanding status from 100Gi to 150Gi, this action action1 will skip.

    由于action1limit為100 GiB,不滿足擴容條件。從預期輸出可得,使用action2策略將云盤從100 GiB擴容到150 GiB。

  6. 根據步驟1,再次使云盤容量使用率高于80%,進行第四次擴容。

    執行以下命令,查看擴容事件。

    kubectl get events

    預期輸出:

    0s     Warning     StartExpand                persistentvolumeclaim/pvc-disk-mysql-1     Start to expand of pvc pvc-disk-mysql-1 from 150Gi to 225Gi, usedCapacityPercentage:94%, freeSize:7637MB.
    0s     Warning     ExternalExpanding          persistentvolumeclaim/pvc-disk-mysql-1     Ignoring the PVC: did't find a plugin capable of expanding the volume; waiting for an external controller to process this PVC.
    0s     Normal      Resizing                   persistentvolumeclaim/pvc-disk-mysql-1     External resizer is resizing volume d-****1
    0s     Normal      FileSystemResizeRequired   persistentvolumeclaim/pvc-disk-mysql-1     Require file system resize of volume on node
    0s     Warning     SkipExpand                 persistentvolumeclaim/pvc-disk-mysql-1     Pvc pvc-disk-mysql-1 is expanding status from 150Gi to 225Gi, this action action1 will skip.

    從預期輸出可得,使用action2策略將云盤從150 GiB擴容到225 GiB。

  7. 根據步驟1,再次使云盤容量使用率高于80%,進行第五次擴容。

    執行以下命令,查看擴容事件。

    kubectl get events

    預期輸出:

    0s     Warning     StartExpand                 persistentvolumeclaim/pvc-disk-mysql-1     Start to expand of pvc pvc-disk-mysql-1 from 225Gi to 300Gi, usedCapacityPercentage:94%, freeSize:7637MB.
    0s     Warning     ExternalExpanding           persistentvolumeclaim/pvc-disk-mysql-1     Ignoring the PVC: did't find a plugin capable of expanding the volume; waiting for an external controller to process this PVC.
    0s     Normal      Resizing                    persistentvolumeclaim/pvc-disk-mysql-1     External resizer is resizing volume d-****1
    0s     Normal      FileSystemResizeRequired    persistentvolumeclaim/pvc-disk-mysql-1     Require file system resize of volume on node
    0s     Warning     FileSystemResizeSuccessful  persistentvolumeclaim/pvc-disk-mysql-1     MountVolume.NodeExpandVolume succeeded for volume "d-****1"

    由于action2limit為300 GiB,從預期輸出可得,此次只能將云盤從225 GiB擴容到300 GiB。

    當云盤容量再次高于80%時,不再觸發擴容。

相關文檔

如在使用云盤存儲卷的過程中遇到相關問題,請參見云盤存儲卷FAQ