StorageAutoScalerPolicy でしきい値を設定すると、storage-operator の storage-auto-expander がディスクボリュームを自動拡張します。
仕組み
storage-auto-expander が PVC のディスク使用率がしきい値を超えたことを検知すると、以下の手順でボリュームを拡張します:
-
ポリシーのラベルセレクターに一致する PVC のディスク使用率を監視します。
-
使用率がしきい値を超えると、最初に一致したアクションを選択し、CSI (Container Storage Interface) ドライバーにリサイズリクエストを送信します。
-
CSI ドライバーがクラウドディスクをリサイズし、Kubernetes にファイルシステムのリサイズを通知します。
-
ファイルシステムのリサイズが完了すると、PVC 容量が更新されます。
タイミングの制約:トリガーのチェック間隔は最大 2 分で、拡張には約 1 分かかります。前回の拡張から 3 分以内にディスクを埋めないでください。
制限事項
| 制限事項 | 詳細 |
|---|---|
| Kubernetes バージョン | Kubernetes 1.16 以降が必要です。必要に応じて クラスターをアップグレード してください。 |
| ディスクタイプ | Basic ディスクはサポートされていません。対象となるディスクタイプについては ResizeDisk をご参照ください。 |
| ストレージクラス | PVC のストレージクラスでは allowVolumeExpansion: true が必要です。ACK が提供するストレージクラスでは、デフォルトでこの設定が有効です。カスタムのストレージクラスの場合は作成時にパラメーターを設定してください。既存のストレージクラスは変更できません。 |
| Pod の状態 | ディスクを使用するアプリケーション Pod が Running 状態である必要があります。 |
storage-auto-expander モジュールの有効化
storage-operator の storage-auto-expander モジュールが自動拡張を担当します。storage-operator がインストールされているかどうか、およびそのバージョンを確認するには、[オペレーション] > [アドオン] > [ボリューム] に移動します。
-
v1.33.1 以降:モジュールはデフォルトで有効です。追加の操作は不要です。
-
v1.33.1 より前:モジュールを有効にします:
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\"}"}}'storage-operatorをアップグレードするには、Upgrade add-ons をご参照ください。
自動拡張ポリシーの設定
手順 1:ストレージクラスでボリューム拡張が有効になっていることの確認
kubectl get sc
ALLOWVOLUMEEXPANSION 列が true である必要があります。出力例:
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
alicloud-disk-efficiency diskplugin.csi.alibabacloud.com Delete Immediate true 26h
alicloud-disk-essd diskplugin.csi.alibabacloud.com Delete Immediate true 26h
alicloud-disk-ssd diskplugin.csi.alibabacloud.com Delete Immediate true 26h
alicloud-disk-topology-alltype diskplugin.csi.alibabacloud.com Delete WaitForFirstConsumer true 26h
可能な場合は alicloud-disk-topology-alltype を使用してください。インスタンスタイプとゾーンの可用性に基づいてディスクタイプを自動選択し、プロビジョニング失敗を減らします。動的にプロビジョニングされたボリュームを使用する をご参照ください。
手順 2:StorageAutoScalerPolicy の作成
StorageAutoScalerPolicy.yaml という名前のファイルを作成します:
apiVersion: storage.alibabacloud.com/v1alpha1
kind: StorageAutoScalerPolicy
metadata:
name: hybrid-expand-policy
spec:
pvcSelector:
matchLabels:
app: nginx
namespaces:
- default
- nginx
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 を選択します。例:app: nginx。 |
namespaces |
対象となる PVC の名前空間です。複数の値は OR 条件で評価されます。デフォルト:default。 |
conditions |
トリガー条件です。複数の条件は AND 条件で評価されます。key:メトリクス (volume-capacity-used-percentage = ディスク使用率 (%))。operator:Gt (より大きい)、Lt (より小さい)、Eq (等しい)、または Ne (等しくない) (大文字と小文字は区別されません)。values:しきい値 (文字列)。 |
actions |
条件を満たしたときに実行するアクションです。最初に一致したアクションが実行され、以降はスキップされます。type:volume-expand である必要があります。params.scale:拡張量 (例:50Gi) または割合 (例:50%)。params.limits:このアクションにおける PVC サイズの上限です。 |
このポリシーは、PVC の使用率が 80% を超えるとトリガーされます:
-
action1:50 GiB を追加 (上限 100 GiB)。PVC が 100 GiB 未満の場合に適用されます。
-
action2:現在サイズの 50% を追加 (上限 300 GiB)。PVC が 100 GiB に達すると適用されます。
手順 3:ポリシーの適用
kubectl create -f StorageAutoScalerPolicy.yaml
自動拡張の確認
次の手順では、上記で定義したポリシーを使用し、テスト用 StatefulSet で 5 回の拡張イベントをトリガーします。
手順 1:テスト用 StatefulSet の作成
StatefulSet.yaml という名前のファイルを作成します:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
serviceName: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
ports:
- containerPort: 80
volumeMounts:
- name: pvc-disk
mountPath: /data
volumes:
- name: pvc-disk
persistentVolumeClaim:
claimName: disk-pvc
volumeClaimTemplates:
- metadata:
name: pvc-disk
labels:
app: nginx
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "alicloud-disk-topology-alltype"
resources:
requests:
storage: 25Gi
適用し、Pod が実行中であることを確認します:
kubectl create -f StatefulSet.yaml
kubectl get pod -l app=nginx
想定される出力:
NAME READY STATUS RESTARTS AGE
nginx-0 1/1 Running 0 99s
初期ディスク容量を確認します:
kubectl exec -it nginx-0 -- df -h /data
想定される出力:
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 25G 24K 25G 1% /data
手順 2:1 回目の拡張のトリガー (25 GiB から 75 GiB)
22 GB のデータを書き込み、使用率を 80% 超にします:
kubectl exec -it nginx-0 -- fallocate -l 22G /data/test1
拡張イベントを確認します:
kubectl get events
ディスクは 25 GiB で使用率が 80% を超えているため、action1 が 50 GiB を追加します:
2m1s Warning StartExpand persistentvolumeclaim/pvc-disk-nginx-0 Start to expand of pvc pvc-disk-nginx-0 from 25Gi to 75Gi, usedCapacityPercentage:90%, freeSize:2498MB.
2m1s Normal ExternalExpanding persistentvolumeclaim/pvc-disk-nginx-0 waiting for an external controller to expand this PVC
2m1s Normal Resizing persistentvolumeclaim/pvc-disk-nginx-0 External resizer is resizing volume d-uf66kkzltnq6xgi9****
118s Normal FileSystemResizeRequired persistentvolumeclaim/pvc-disk-nginx-0 Require file system resize of volume on node
116s Warning SkipExpand persistentvolumeclaim/pvc-disk-nginx-0 Pvc pvc-disk-nginx-0 is expanding status from 25Gi to 75Gi, this action action2 will skip.
PVC 容量を確認します:
kubectl get pvc
想定される出力:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
pvc-disk-nginx-0 Bound d-uf66kkzltnq6xgi9**** 75Gi RWO alicloud-disk-topology-alltype <unset> 26m
手順 3:2 回目の拡張のトリガー (75 GiB から 100 GiB)
40 GB を書き込み、再度使用率を 80% 超にします:
kubectl exec -it nginx-0 -- fallocate -l 40G /data/test2
action1 が再び実行されますが、上限 100 GiB により 100 GiB で拡張が打ち切られます:
kubectl get events
7m4s Warning StartExpand persistentvolumeclaim/pvc-disk-nginx-0 Start to expand of pvc pvc-disk-nginx-0 from 75Gi to 100Gi, usedCapacityPercentage:84%, freeSize:11927MB.
7m4s Normal ExternalExpanding persistentvolumeclaim/pvc-disk-nginx-0 waiting for an external controller to expand this PVC
7m4s Normal Resizing persistentvolumeclaim/pvc-disk-nginx-0 External resizer is resizing volume d-uf66kkzltnq6xgi9****
7m1s Normal FileSystemResizeRequired persistentvolumeclaim/pvc-disk-nginx-0 Require file system resize of volume on node
5m59s Warning SkipExpand persistentvolumeclaim/pvc-disk-nginx-0 Pvc pvc-disk-nginx-0 is expanding status from 75Gi to 100Gi, this action action2 will skip.
手順 4:3 回目の拡張のトリガー (100 GiB から 150 GiB)
100 GiB では action1 の上限に達するため、action2 に切り替わり、現在サイズの 50% を追加します:
kubectl exec -it nginx-0 -- fallocate -l 20G /data/test3
kubectl get events
2m40s Warning StartExpand persistentvolumeclaim/pvc-disk-nginx-0 Start to expand of pvc pvc-disk-nginx-0 from 100Gi to 150Gi, usedCapacityPercentage:83%, freeSize:16637MB.
2m40s Normal ExternalExpanding persistentvolumeclaim/pvc-disk-nginx-0 waiting for an external controller to expand this PVC
2m40s Normal Resizing persistentvolumeclaim/pvc-disk-nginx-0 External resizer is resizing volume d-uf66kkzltnq6xgi9****
2m37s Normal FileSystemResizeRequired persistentvolumeclaim/pvc-disk-nginx-0 Require file system resize of volume on node
手順 5:4 回目の拡張のトリガー (150 GiB から 225 GiB)
action2 が再び実行され、150 GiB の 50% = 75 GiB を追加します:
kubectl exec -it nginx-0 -- fallocate -l 50G /data/test4
kubectl get events
2m42s Warning StartExpand persistentvolumeclaim/pvc-disk-nginx-0 Start to expand of pvc pvc-disk-nginx-0 from 150Gi to 225Gi, usedCapacityPercentage:87%, freeSize:19621MB.
2m42s Normal ExternalExpanding persistentvolumeclaim/pvc-disk-nginx-0 waiting for an external controller to expand this PVC
2m42s Normal Resizing persistentvolumeclaim/pvc-disk-nginx-0 External resizer is resizing volume d-uf66kkzltnq6xgi9****
2m38s Normal FileSystemResizeRequired persistentvolumeclaim/pvc-disk-nginx-0 Require file system resize of volume on node
手順 6:5 回目の拡張のトリガー (225 GiB から 300 GiB)
action2 が最後にもう 1 回実行されますが、上限 300 GiB により 300 GiB で打ち切られます:
kubectl exec -it nginx-0 -- fallocate -l 50G /data/test5
kubectl get events
17m Warning StartExpand persistentvolumeclaim/pvc-disk-nginx-0 Start to expand of pvc pvc-disk-nginx-0 from 225Gi to 300Gi, usedCapacityPercentage:82%, freeSize:40351MB.
17m Normal ExternalExpanding persistentvolumeclaim/pvc-disk-nginx-0 waiting for an external controller to expand this PVC
17m Normal Resizing persistentvolumeclaim/pvc-disk-nginx-0 External resizer is resizing volume d-uf66kkzltnq6xgi9****
17m Normal FileSystemResizeRequired persistentvolumeclaim/pvc-disk-nginx-0 Require file system resize of volume on node
両方のアクションが limits に達しました。これ以上の拡張は行われません。
次のステップ
クラウドディスクボリュームの問題については、Cloud disk volume FAQ をご参照ください。