블록 스토리지 CSI 예제
    • PDF

    블록 스토리지 CSI 예제

    • PDF

    기사 요약

    VPC 환경에서 이용 가능합니다.

    블록 스토리지 CSI에서 설명한 CSI 사용법을 바탕으로 다양한 방식을 통해 볼륨을 할당하는 예제입니다.

    Pod에 복수의 볼륨을 할당

    두 개의 신규 블록 스토리지를 생성하여 Pod에 마운트하고, 생성 요청할 볼륨에 대해 각각 PersistentVolumeClaim을 요청하는 예제는 다음과 같습니다.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: csi-pod-1
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
      storageClassName: nks-block-storage
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: csi-pod-2
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
      storageClassName: nks-block-storage
    ---
    kind: Pod
    apiVersion: v1
    metadata:
      name: my-csi-app
    spec:
      containers:
        - name: my-csi-app
          image: busybox
          volumeMounts:
          - mountPath: "/data/pod-1/"
            name: my-volume-1
          - mountPath: "/data/pod-2/"
            name: my-volume-2
          command: [ "sleep", "1000000" ]
      volumes:
        - name: my-volume-1
          persistentVolumeClaim:
            claimName: csi-pod-1
        - name: my-volume-2
          persistentVolumeClaim:
            claimName: csi-pod-2
    

    Deployment에서 PersistentVolume 이용하기

    PersistentVolumeClaim을 생성하여 신규 볼륨 생성을 요청할 때, Deployment의 template에서 claimName을 명시함으로써 생성된 볼륨을 마운트하는 예제는 다음과 같습니다.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: csi-deployment-pvc
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
      storageClassName: nks-block-storage
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-csi-app
    spec:
      selector:
        matchLabels:
          app: my-csi-app
      replicas: 1
      template:
        metadata:
          labels:
            app: my-csi-app
        spec:
          containers:
            - name: my-frontend
              image: busybox
              volumeMounts:
              - mountPath: "/data"
                name: my-volume
              command: [ "sleep", "1000000" ]
          volumes:
            - name: my-volume
              persistentVolumeClaim:
                claimName: csi-deployment-pvc
    

    StatefulSet에서 PersistentVolume 이용하기

    StatefulSet에서 volumeClaimTemplates를 정의하여 각 replica마다 새로운 PersistentVolumeClaim을 자동으로 생성하는 예제는 다음과 같습니다.

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: my-csi-app
    spec:
      serviceName: my-csi-app
      selector:
        matchLabels:
          app: my-csi-app
      replicas: 1
      template:
        metadata:
          labels:
            app: my-csi-app
        spec:
          containers:
            - name: my-frontend
              image: busybox
              volumeMounts:
              - mountPath: "/data"
                name: my-volume
              command: [ "sleep", "1000000" ]
      volumeClaimTemplates:
        - metadata:
            name: my-volume
          spec:
            accessModes: ["ReadWriteOnce"]
            resources:
              requests:
                storage: 10Gi
    

    이 문서가 도움이 되었습니까?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.