すべてのプロダクト
Search
ドキュメントセンター

:LV の使用

最終更新日:Apr 16, 2025

ボリュームグループ (VG) を使用してディスクを仮想化した後、論理ボリュームマネージャー (LVM) を使用して VG を論理ボリューム (LV) に分割し、LV をポッドにマウントできます。このトピックでは、LV の使用方法について説明します。

背景情報

ポッドがノードのストレージを使用できるようにするには、hostPath ボリュームまたはローカルボリュームを使用できます。ただし、hostPath ボリュームとローカルボリュームには次の制限があります。次の制限に対処するために、Container Service for Kubernetes (ACK) クラスタで LV を使用できます。次のリストは、hostPath ボリュームとローカルボリュームの制限を示しています。

  • Kubernetes は、hostPath ボリュームとローカルボリュームのライフサイクルを管理しません。ボリュームを手動で管理および保守する必要があります。

  • 複数のポッドが同じローカルストレージを使用する場合、これらのポッドは同じディレクトリを共有するか、各ポッドはサブディレクトリを使用します。その結果、これらのポッド間でストレージの分離を実装することはできません。

  • 複数のポッドが同じローカルストレージを使用する場合、各ポッドの 1 秒あたりの入力/出力操作 (IOPS) とスループットはストレージ全体のものと同じになります。各ポッドの IOPS とスループットを制限することはできません。

  • ローカルストレージを使用するポッドを作成する場合、各ノードで使用可能なストレージは不明です。その結果、ノードにマウントされたボリュームを適切にスケジュールできません。

概要

  • LV のライフサイクル管理: 自動作成、削除、マウント、およびマウント解除。

  • LV の拡張。

  • LV の監視。

  • LV の IOPS 制限。

  • VG の自動運用および保守。これにより、ノードのローカルストレージを管理できます。

  • LV を使用するクラスタのストレージ使用状況の監視。

使用上の注意

  • LV は移行できません。したがって、LV は高可用性シナリオには適していません。

  • LV を使用するクラスタのストレージ使用状況の監視はオプションの機能です。VG を初期化するには、ローカルストレージリソースを手動で初期化するか、ローカルストレージリソースを自動的に初期化する必要があります。どちらの方法でも、ローカルストレージリソースに関する知識が必要です。そうでない場合は、Container Network File System (CNFS) によって管理されるディスクやファイルシステムなどのクラウドストレージリソースを使用することをお勧めします。

アーキテクチャ

LV のライフサイクル管理、拡張、マウント、フォーマットなどの LVM の基本機能は、CSI-Provisioner と CSI-Plugin によって実装されます。

コンポーネント

説明

ストレージマネージャー

このコンポーネントは、ノード上のローカルストレージリソースを管理し、ストレージ使用状況を監視するために使用されます。ワーカーを使用して VG を管理および保守することもできます。

カスタムリソース定義

このコンポーネントは、ストレージ容量や VG など、ノードのローカルストレージ情報を保存するために使用されます。

LV スケジューラ

このコンポーネントは、永続ボリューム要求 (PVC) を作成し、クラスタのストレージ容量を監視するために使用されます。

手順 1: CSI-Plugin と CSI-Provisioner にシークレットを管理するための RBAC 権限を付与する

Kubernetes 1.22 以降

次の YAML コンテンツを使用して ServiceAccount を作成し、ServiceAccount に権限を付与します。

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: alibaba-cloud-csi-local
  namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: alibaba-cloud-csi-local
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "update", "create", "delete", "patch"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims/status"]
    verbs: ["get", "list", "watch", "update", "patch"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["csinodes"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "update", "patch", "list", "watch"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["volumeattachments"]
    verbs: ["get", "list", "watch", "update", "patch"]
  - apiGroups: ["coordination.k8s.io"]
    resources: ["leases"]
    verbs: ["get", "create", "list", "watch", "delete", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["volumeattachments/status"]
    verbs: ["patch"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: alibaba-cloud-csi-local
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: alibaba-cloud-csi-local
subjects:
- kind: ServiceAccount
  name: alibaba-cloud-csi-local
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: alibaba-cloud-csi-local
  namespace: kube-system
rules:
- apiGroups: [""]
  resources: ["secrets"]
  resourceNames: ["csi-local-plugin-cert"]
  verbs: ["get"]
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["create"]
- apiGroups: [""]
  resources: ["configmaps"]
  resourceNames: ["csi-plugin", "ack-cluster-profile"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: alibaba-cloud-csi-local
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: alibaba-cloud-csi-local
subjects:
- kind: ServiceAccount
  name: alibaba-cloud-csi-local
  namespace: kube-system

Kubernetes 1.20 以前

CSI-Plugin と同じ ServiceAccount を共有するには、clusterrole/alicloud-csi-plugin にシークレットを管理するためのロールベースアクセス制御 (RBAC) 権限を付与する必要があります。

  1. 次のコマンドを実行して、clusterrole/alicloud-csi-plugin にシークレットを create する権限があるかどうかを確認します。

    echo `JSONPATH='{range .rules[*]}{@.resources}:{@.verbs} \r\n
    {end}' \
     && kubectl get clusterrole  alicloud-csi-plugin -o jsonpath="$JSONPATH";` | grep secrets

    予期される出力:

    ["secrets"]:["get","list"]
  2. clusterrole/alicloud-csi-plugin にシークレットを create する権限がない場合は、次のコマンドを実行して権限を付与します。

     kubectl patch clusterrole alicloud-csi-plugin --type='json' -p='[{"op": "add", "path": "/rules/0", "value":{ "apiGroups": [""], "resources": ["secrets"], "verbs": ["create"]}}]'

    予期される出力:

    clusterrole.rbac.authorization.k8s.io/alicloud-csi-plugin patched
  3. 次のコマンドを実行して、clusterrole/alicloud-csi-plugin にシークレットを create する権限があるかどうかを確認します。

    echo `JSONPATH='{range .rules[*]}{@.resources}:{@.verbs} \r\n
    {end}' \
     && kubectl get clusterrole  alicloud-csi-plugin -o jsonpath="$JSONPATH";` | grep secrets

    予期される出力:

    ["secrets"]:["create"] 
    ["secrets"]:["get","list"]

    出力は、clusterrole/alicloud-csi-plugin にシークレットを create する権限があることを示しています。

ステップ 2: CSI-Plugin と CSI-Provisioner をデプロイする

LV 用の CSI コンポーネントは、CSI-Plugin と CSI-Provisioner で構成されています。CSI-Plugin は LV のマウントとマウント解除に使用されます。CSI-Provisioner は、LV と永続ボリューム (PV) の作成に使用されます。

説明

以下の YAML コンテンツの {{ regionId }} を、クラスターのリージョン ID に置き換えます。

Kubernetes 1.22 以降

  • LVM CSI-Plugin をデプロイする

    apiVersion: storage.k8s.io/v1
    kind: CSIDriver
    metadata:
      name: localplugin.csi.alibabacloud.com
    spec:
      attachRequired: false
      podInfoOnMount: true
    ---
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      labels:
        app: csi-local-plugin
      name: csi-local-plugin
      namespace: kube-system
    spec:
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: csi-local-plugin
      template:
        metadata:
          labels:
            app: csi-local-plugin
        spec:
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                  - matchExpressions:
                      - key: type
                        operator: NotIn
                        values:
                          - virtual-kubelet
          containers:
            - args:
                - '--v=5'
                - '--csi-address=/csi/csi.sock'
                - >-
                  --kubelet-registration-path=/var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com/csi.sock
              env:
                - name: KUBE_NODE_NAME
                  valueFrom:
                    fieldRef:
                      apiVersion: v1
                      fieldPath: spec.nodeName
              image: >-
                registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-node-driver-registrar:v2.3.1-038aeb6-aliyun
              imagePullPolicy: Always
              name: driver-registrar
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
              volumeMounts:
                - mountPath: /csi
                  name: plugin-dir
                - mountPath: /registration
                  name: registration-dir
            - args:
                - '--endpoint=$(CSI_ENDPOINT)'
                - '--v=5'
                - '--nodeid=$(KUBE_NODE_NAME)'
                - '--driver=localplugin.csi.alibabacloud.com'
              env:
                - name: KUBE_NODE_NAME
                  valueFrom:
                    fieldRef:
                      apiVersion: v1
                      fieldPath: spec.nodeName
                - name: SERVICE_PORT
                  value: '11293'
                - name: CSI_ENDPOINT
                  value: >-
                    unix://var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com/csi.sock
              image: >-
                 registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-plugin:v1.24.3-55228c1-aliyun
              imagePullPolicy: Always
              name: csi-localplugin
              resources: {}
              securityContext:
                allowPrivilegeEscalation: true
                capabilities:
                  add:
                    - SYS_ADMIN
                privileged: true
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
              volumeMounts:
                - mountPath: /var/lib/kubelet
                  mountPropagation: Bidirectional
                  name: pods-mount-dir
                - mountPath: /dev
                  mountPropagation: HostToContainer
                  name: host-dev
                - mountPath: /var/log/
                  name: host-log
                - mountPath: /mnt
                  mountPropagation: Bidirectional
                  name: quota-path-dir
                - mountPath: /tls/local/grpc
                  name: tls-token-dir
                  readOnly: true
          dnsPolicy: ClusterFirst
          hostNetwork: true
          hostPID: true
          priorityClassName: system-node-critical
          restartPolicy: Always
          securityContext: {}
          serviceAccountName: alibaba-cloud-csi-local
          terminationGracePeriodSeconds: 30
          tolerations:
            - operator: Exists
          volumes:
            - name: tls-token-dir
              secret:
                defaultMode: 420
                secretName: csi-local-plugin-cert
            - hostPath:
                path: /var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com
                type: DirectoryOrCreate
              name: plugin-dir
            - hostPath:
                path: /var/lib/kubelet/plugins_registry
                type: DirectoryOrCreate
              name: registration-dir
            - hostPath:
                path: /var/lib/kubelet
                type: Directory
              name: pods-mount-dir
            - hostPath:
                path: /dev
                type: ''
              name: host-dev
            - hostPath:
                path: /var/log/
                type: ''
              name: host-log
            - hostPath:
                path: /mnt
                type: Directory
              name: quota-path-dir
      updateStrategy:
        rollingUpdate:
          maxUnavailable: 10%
        type: RollingUpdate
  • LVM CSI-Provisioner をデプロイする

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: csi-local-provisioner
      name: csi-local-provisioner
      namespace: kube-system
    spec:
      progressDeadlineSeconds: 600
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: csi-local-provisioner
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: csi-local-provisioner
        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:
          - args:
            - --csi-address=$(ADDRESS)
            - --feature-gates=Topology=True
            - --volume-name-prefix=local
            - --strict-topology=true
            - --timeout=150s
            - --extra-create-metadata=true
            - --enable-leader-election=true
            - --leader-election-type=leases
            - --retry-interval-start=500ms
            - --default-fstype=ext4
            - --v=5
            env:
            - name: ADDRESS
              value: /socketDir/csi.sock
            image: registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-provisioner:v3.0.0-080f01e64-aliyun
            imagePullPolicy: Always
            name: external-local-provisioner
            resources: {}
            volumeMounts:
            - mountPath: /socketDir
              name: socket-dir
          - args:
            - --endpoint=$(CSI_ENDPOINT)
            - --v=2
            - --driver=localplugin.csi.alibabacloud.com
            env:
            - name: CSI_ENDPOINT
              value: unix://var/lib/kubelet/csi-provisioner/localplugin.csi.alibabacloud.com/csi.sock
            - name: SERVICE_TYPE
              value: provisioner
            - name: SERVICE_PORT
              value: "11290"
            image: registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-plugin:v1.24.3-55228c1-aliyun
            imagePullPolicy: Always
            name: csi-localprovisioner
            resources: {}
            securityContext:
              privileged: true
            volumeMounts:
            - mountPath: /var/lib/kubelet/csi-provisioner/localplugin.csi.alibabacloud.com
              name: socket-dir
            - mountPath: /var/log/
              name: host-log
            - mountPath: /tls/local/grpc/
              name: tls-token-dir
          - args:
            - --v=5
            - --csi-address=$(ADDRESS)
            - --leader-election
            env:
            - name: ADDRESS
              value: /socketDir/csi.sock
            image: registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-resizer:v1.3-ca84e84-aliyun
            imagePullPolicy: Always
            name: external-local-resizer
            resources: {}
            volumeMounts:
            - mountPath: /socketDir/
              name: socket-dir
          dnsPolicy: ClusterFirst
          hostNetwork: true
          restartPolicy: Always
          securityContext: {}
          serviceAccountName: alibaba-cloud-csi-local
          terminationGracePeriodSeconds: 30
          tolerations:
          - operator: Exists
          volumes:
          - emptyDir: {}
            name: socket-dir
          - emptyDir: {}
            name: tls-token-dir
          - hostPath:
              path: /dev
              type: ""
            name: host-dev
          - hostPath:
              path: /var/log/
              type: ""
            name: host-log
          - hostPath:
              path: /mnt
              type: Directory
            name: quota-path-dir
          - hostPath:
              path: /var/lib/kubelet
              type: Directory
            name: pods-mount-dir

Kubernetes 1.20 以前

  • LVM CSI-Plugin をデプロイする

    apiVersion: storage.k8s.io/v1beta1
    kind: CSIDriver
    metadata:
      name: localplugin.csi.alibabacloud.com
    spec:
      attachRequired: false
      podInfoOnMount: true
    ---
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      labels:
        app: csi-local-plugin
      name: csi-local-plugin
      namespace: kube-system
    spec:
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: csi-local-plugin
      template:
        metadata:
          labels:
            app: csi-local-plugin
        spec:
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                  - matchExpressions:
                      - key: type
                        operator: NotIn
                        values:
                          - virtual-kubelet
          containers:
            - args:
                - '--v=5'
                - '--csi-address=/csi/csi.sock'
                - >-
                  --kubelet-registration-path=/var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com/csi.sock
              env:
                - name: KUBE_NODE_NAME
                  valueFrom:
                    fieldRef:
                      apiVersion: v1
                      fieldPath: spec.nodeName
              image: >-
                registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-node-driver-registrar:v1.3.0-6e9fff3-aliyun
              imagePullPolicy: Always
              name: driver-registrar
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
              volumeMounts:
                - mountPath: /csi
                  name: plugin-dir
                - mountPath: /registration
                  name: registration-dir
            - args:
                - '--endpoint=$(CSI_ENDPOINT)'
                - '--v=5'
                - '--nodeid=$(KUBE_NODE_NAME)'
                - '--driver=localplugin.csi.alibabacloud.com'
              env:
                - name: KUBE_NODE_NAME
                  valueFrom:
                    fieldRef:
                      apiVersion: v1
                      fieldPath: spec.nodeName
                - name: SERVICE_PORT
                  value: '11293'
                - name: CSI_ENDPOINT
                  value: >-
                    unix://var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com/csi.sock
              image: >-
                registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-plugin:v1.20.7-aafce42-aliyun
              imagePullPolicy: Always
              name: csi-localplugin
              resources: {}
              securityContext:
                allowPrivilegeEscalation: true
                capabilities:
                  add:
                    - SYS_ADMIN
                privileged: true
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
              volumeMounts:
                - mountPath: /var/lib/kubelet
                  mountPropagation: Bidirectional
                  name: pods-mount-dir
                - mountPath: /dev
                  mountPropagation: HostToContainer
                  name: host-dev
                - mountPath: /var/log/
                  name: host-log
                - mountPath: /mnt
                  mountPropagation: Bidirectional
                  name: quota-path-dir
                - mountPath: /tls/local/grpc
                  name: tls-token-dir
                  readOnly: true
          dnsPolicy: ClusterFirst
          hostNetwork: true
          hostPID: true
          priorityClassName: system-node-critical
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          serviceAccount: csi-admin
          serviceAccountName: csi-admin
          terminationGracePeriodSeconds: 30
          tolerations:
            - operator: Exists
          volumes:
            - name: tls-token-dir
              secret:
                defaultMode: 420
                secretName: csi-local-plugin-cert
            - hostPath:
                path: /var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com
                type: DirectoryOrCreate
              name: plugin-dir
            - hostPath:
                path: /var/lib/kubelet/plugins_registry
                type: DirectoryOrCreate
              name: registration-dir
            - hostPath:
                path: /var/lib/kubelet
                type: Directory
              name: pods-mount-dir
            - hostPath:
                path: /dev
                type: ''
              name: host-dev
            - hostPath:
                path: /var/log/
                type: ''
              name: host-log
            - hostPath:
                path: /mnt
                type: Directory
              name: quota-path-dir
      updateStrategy:
        rollingUpdate:
          maxUnavailable: 10%
        type: RollingUpdate
  • LVM CSI-Provisioner をデプロイする

    apiVersion: apps/v1
    kind: Deployment
    metadata:
     labels:
       app: csi-local-provisioner
     name: csi-local-provisioner
     namespace: kube-system
    spec:
     selector:
       matchLabels:
         app: csi-local-provisioner
     strategy:
       rollingUpdate:
         maxSurge: 25%
         maxUnavailable: 25%
       type: RollingUpdate
     template:
       metadata:
         labels:
           app: csi-local-provisioner
       spec:
         affinity:
           nodeAffinity:
             preferredDuringSchedulingIgnoredDuringExecution:
             - preference:
                 matchExpressions:
                 - key: node-role.kubernetes.io/master
                   operator: Exists
               weight: 1
         containers:
         - args:
           - --csi-address=$(ADDRESS)
           - --feature-gates=Topology=True
           - --volume-name-prefix=local
           - --strict-topology=true
           - --timeout=150s
           - --extra-create-metadata=true
           - --enable-leader-election=true
           - --leader-election-type=leases
           - --retry-interval-start=500ms
           - --v=5
           env:
           - name: ADDRESS
             value: /socketDir/csi.sock
           image: registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-provisioner:v1.6.0-71838bd-aliyun
           imagePullPolicy: Always
           name: external-local-provisioner
           volumeMounts:
           - mountPath: /socketDir
             name: socket-dir
         - name: csi-localprovisioner
           securityContext:
             privileged: true
           image: registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-plugin:v1.20.7-aafce42-aliyun
           imagePullPolicy: "Always"
           args:
             - "--endpoint=$(CSI_ENDPOINT)"
             - "--v=2"
             - "--driver=localplugin.csi.alibabacloud.com"
           env:
           - name: CSI_ENDPOINT
             value: unix://var/lib/kubelet/csi-provisioner/localplugin.csi.alibabacloud.com/csi.sock
           - name: SERVICE_TYPE
             value: "provisioner"
           - name: SERVICE_PORT
             value: "11290"
           volumeMounts:
           - name: socket-dir
             mountPath: /var/lib/kubelet/csi-provisioner/localplugin.csi.alibabacloud.com
           - mountPath: /var/log/
             name: host-log
           - mountPath: /tls/local/grpc/
             name: tls-token-dir
         - args:
           - --v=5
           - --csi-address=$(ADDRESS)
           - --leader-election
           env:
           - name: ADDRESS
             value: /socketDir/csi.sock
           image: registry-vpc.{{ regionId }}.aliyuncs.com/acs/csi-resizer:v1.1.0-7b30758-aliyun
           imagePullPolicy: Always
           name: external-local-resizer
           volumeMounts:
           - mountPath: /socketDir/
             name: socket-dir
         hostNetwork: true
         serviceAccount: csi-admin
         tolerations:
         - effect: NoSchedule
           operator: Exists
           key: node-role.kubernetes.io/master
         - effect: NoSchedule
           operator: Exists
           key: node.cloudprovider.kubernetes.io/uninitialized
         volumes:
         - name: socket-dir
           emptyDir: {}
         - name: tls-token-dir
           emptyDir: {}
         - hostPath:
             path: /dev
             type: ""
           name: host-dev
         - hostPath:
             path: /var/log/
             type: ""
           name: host-log
         - hostPath:
             path: /mnt
             type: Directory
           name: quota-path-dir
         - hostPath:
             path: /var/lib/kubelet
             type: Directory
           name: pods-mount-dir

ステップ 3: LV を使用する

CSI-Provisioner を使用して PV を作成する場合は、次の制限事項に注意してください。

  • StorageClass で VG の名前を指定する必要があります。

  • 指定したノードに PV を作成する場合、関連する PVC に volume.kubernetes.io/selected-node: nodeName アノテーションを追加する必要があります。

  1. 次の YAML テンプレートを使用して、StorageClass を作成します。

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
        name: csi-local
    provisioner: localplugin.csi.alibabacloud.com
    parameters:
        volumeType: LVM
        vgName: volumegroup1
        fsType: ext4
        lvmType: "striping"
        writeIOPS: "10000"
        writeBPS: "1M"
    reclaimPolicy: Delete
    volumeBindingMode: WaitForFirstConsumer
    allowVolumeExpansion: true

    パラメーター

    説明

    volumeType

    ボリュームのタイプ。 LVM の値は LV を示します。

    vgName

    VG の名前。このパラメーターは必須です。

    fsType

    ファイルシステムのタイプ。

    lvmType

    LV のタイプ。有効な値: linear および striping。

    writeIOPS

    StorageClass を使用して作成された LV の書き込み IOPS。

    writeBPS

    StorageClass を使用して作成された LV に毎秒書き込むことができるデータのサイズ。単位: バイト。

  2. 次の YAML テンプレートを使用して、PVC を作成します。

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: lvm-pvc
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
      storageClassName: csi-local
  3. 次の YAML テンプレートを使用して、アプリケーションを作成します。

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: deployment-lvm
      labels:
        app: nginx
    spec:
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            volumeMounts:
              - name: lvm-pvc
                mountPath: "/data"
          volumes:
            - name: lvm-pvc
              persistentVolumeClaim:
                claimName: lvm-pvc
  4. アプリケーションで使用される PVC と 永続ボリューム (PV) に関する情報をクエリします。

    1. 次のコマンドを実行して、PVC に関する情報をクエリします。

      kubectl get pvc
      NAME      STATUS   VOLUME                                      CAPACITY   ACCESS MODES   STORAGECLASS   AGE
      lvm-pvc   Bound    disk-afacf7a9-3d1a-45da-b443-24f8fb35****   2Gi        RWO            csi-local      16s
    2. 次のコマンドを実行して、PV に関する情報をクエリします。

      kubectl get pv

      予期される出力:

      NAME                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM             STORAGECLASS   REASON   AGE
      disk-afacf7a9-3d1a-45da-b443-24f8fb35****   2Gi        RWO            Delete           Bound    default/lvm-pvc   csi-local               12s
  5. アプリケーションのステータスをクエリします。

    1. 次のコマンドを実行して、アプリケーション用に作成されたポッドに関する情報をクエリします。

      kubectl get pod

      予期される出力:

      NAME                             READY   STATUS    RESTARTS   AGE
      deployment-lvm-9f798687c-m****   1/1     Running   0          9s
    2. 次のコマンドを実行して、ポッドにマウントされているボリュームをクエリします。

      kubectl exec -ti deployment-lvm-9f798687c-m**** sh -- df /data

      予期される出力:

      Filesystem                                                                1K-blocks  Used   Available Use% Mounted on
      /dev/mapper/volumegroup1-disk--afacf7a9--3d1a--45da--b443--24f8fb35****   1998672    6144   1976144   1%   /data
    3. 次のコマンドを実行して、/data ディレクトリ内のすべてのディレクトリをクエリします。

      ls /data

      予期される出力:

      lost+found
  6. LV を使用してデータを永続化できるかどうかをテストします。

    1. 次のコマンドを実行して、/data ディレクトリに test という名前のディレクトリを作成します。

      touch /data/test
      ls /data

      予期される出力:

      lost+found  test
    2. 次のコマンドを実行して、終了します。

      exit
    3. 次のコマンドを実行して、ポッドを削除します。

      kubectl delete pod deployment-lvm-9f798687c-m****

      予期される出力:

      pod "deployment-lvm-9f798687c-m****" deleted
    4. 次のコマンドを実行して、アプリケーション用に作成されたポッドに関する情報をクエリします。

      kubectl get pod

      予期される出力:

      NAME                             READY   STATUS    RESTARTS   AGE
      deployment-lvm-9f798687c-j****   1/1     Running   0          2m19s
    5. 次のコマンドを実行して、ポッドにマウントされているボリュームをクエリします。

      kubectl exec deployment-lvm-9f798687c-j**** -- ls /data

      予期される出力:

      lost+found  
      test
  7. LV を拡張します。

    1. 次のコマンドを実行して、PVC に関する情報をクエリします。

      kubectl get pvc

      予期される出力:

      NAME      STATUS   VOLUME                                      CAPACITY   ACCESS MODES   STORAGECLASS   AGE
      lvm-pvc   Bound    disk-afacf7a9-3d1a-45da-b443-24f8fb35****   2Gi        RWO            csi-local      6m50s
    2. 次のコマンドを実行して、PVC によってリクエストされた容量を 4 GiB に拡張します。

      kubectl patch pvc lvm-pvc -p '{"spec":{"resources":{"requests":{"storage":"4Gi"}}}}'

      予期される出力:

      persistentvolumeclaim/lvm-pvc patched
    3. 次のコマンドを実行して、PVC に関する情報をクエリします。

      kubectl get pvc

      予期される出力:

      NAME      STATUS   VOLUME                                      CAPACITY   ACCESS MODES   STORAGECLASS   AGE
      lvm-pvc   Bound    disk-afacf7a9-3d1a-45da-b443-24f8fb35****   4Gi        RWO            csi-local      7m26s
    4. 次のコマンドを実行して、LV の容量が 4 GiB に拡張されているかどうかを確認します。

      kubectl exec deployment-lvm-9f798687c-j**** -- df /data

      予期される出力:

      Filesystem                                                                1K-blocks  Used   Available Use% Mounted on
      /dev/mapper/volumegroup1-disk--afacf7a9--3d1a--45da--b443--24f8fb35****   4062912    8184   4038344   1%   /data
  8. LV を監視します。

    curl -s localhost:10255/metrics | grep lvm-pvc

    予期される出力:

    kubelet_volume_stats_available_bytes{namespace="default",persistentvolumeclaim="lvm-pvc"} 1.917165568e+09
    kubelet_volume_stats_capacity_bytes{namespace="default",persistentvolumeclaim="lvm-pvc"} 1.939816448e+09
    kubelet_volume_stats_inodes{namespace="default",persistentvolumeclaim="lvm-pvc"} 122400
    kubelet_volume_stats_inodes_free{namespace="default",persistentvolumeclaim="lvm-pvc"} 122389
    kubelet_volume_stats_inodes_used{namespace="default",persistentvolumeclaim="lvm-pvc"} 11
    kubelet_volume_stats_used_bytes{namespace="default",persistentvolumeclaim="lvm-pvc"} 5.873664e+06

    上記のモニタリングデータは Prometheus にインポートし、コンソールに表示できます。 詳細については、「オープンソースの Prometheus を使用して ACK クラスタを監視する」をご参照ください。