> For the complete documentation index, see [llms.txt](https://docs-epc.gitbook.io/ncs-documents/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-epc.gitbook.io/ncs-documents/tutorial/kubernetes-on-nipa-cloud-space-with-rancher/kubernetes/storage-class.md).

# การจัดการพื้นที่จัดเก็บข้อมูล (Storage Class)

ใน Cluster ของ Kubernetes จะถูกติดตั้งมาพร้อมกับความสามารถในใช้ block storage ของ NIPA Cloud \
โดยได้มีการติดตั้ง CSI Plugin ไว้บน namespace ncs-system เพื่อทำการ integrate system ไว้เรียบร้อยแล้ว

โดยในรูปเป็น Storage Class ที่ NIPA Cloud มีให้ บริการทั้ง 3 Type รองรับการทำงานเป็น ReadWriteOne

<figure><img src="/files/JBJpHw2KA76h5mJ2x3ms" alt=""><figcaption></figcaption></figure>

ผู้ใช้งานจึงสามารถให้ Kubernetes สั่งสร้าง/ลบ Volume ได้แบบอัตโนมัติ ผ่าน CSI Pluginโดนไม่จำเป็นต้องให้ผู้ดูแลระบบสร้าง Volume รอไว้ล่วงหน้า &#x20;

### ฟีเจอร์ที่รองรับ&#x20;

* Access Mode: ReadWriteOnce (RWO) ✅\
  Volume สามารถถูก Mount และใช้งานได้โดย Node/Pod เดียวเท่านั้น เป็นโหมดพื้นฐานที่ใช้กันทั่วไป
* Dynamic Provisioning ✅\
  Kubernetes สั่งสร้าง/ลบ Volume ได้แบบอัตโนมัติ ผ่าน CSI Plugin
* Volume Snapshots ✅\
  สร้าง Snapshot ของ Persistent Volume (PV) ได้โดยตรงผ่าน Kubernetes API เพื่อบันทึกสถานะของข้อมูล ณ เวลาใดเวลาหนึ่ง
* Volume Cloning ✅\
  สามารถสร้าง PV ใหม่โดยเป็นการโคลนข้อมูลทั้งหมดจาก PV ที่มีอยู่แล้วได้อย่างรวดเร็ว เหมาะสำหรับการสร้างสภาพแวดล้อมทดสอบ
* Volume Expansion ✅\
  เพิ่มขนาด Volume ขณะใช้งาน สามารถขยายขนาดของ PVC ที่ใช้งานอยู่ได้โดยไม่ต้อง Downtime แอปพลิเคชัน

### ทดสอบสร้าง PVC

YAML

```
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-app-data
  namespace: sandbox1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: standard-hdd

```

resource จะถูกสร้างขึ้นมาดังรูป

<figure><img src="/files/KpFf8vnxw8qi8doj7Aa1" alt=""><figcaption></figcaption></figure>

และเมื่อตรวจสอบผ่าน Portal จะพบว่ามี Resource เกิดขึ้นมาตาม PVC Volume โดยที่บริการนี้มีค่าใช้จ่ายตามที่ผู้ให้บริการคลาวด์กำหนด

<figure><img src="/files/x7TRUHZTh9OMoR4aaWE9" alt=""><figcaption></figcaption></figure>

หากลบ PVC โดย default setting volume ที่อยู่บน Portal จะยังไม่ถูกลบ หากต้องการให้ลบ อัตโนมัติ สามารถตั้งค่าได้บน Storage Class
