doc-exports/docs/cce/umn/cce_bestpractice_00281.html
Dong, Qiu Jian 3d9cca138b CCE UMN: Added the support of the OS for features and cluster versions.
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com>
Co-authored-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
Co-committed-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
2023-06-20 14:52:27 +00:00

231 lines
18 KiB
HTML

<a name="cce_bestpractice_00281"></a><a name="cce_bestpractice_00281"></a>
<h1 class="topictitle1">Custom Storage Classes</h1>
<div id="body0000001148435277"><div class="section" id="cce_bestpractice_00281__section13347243125312"><h4 class="sectiontitle">Challenges</h4><p id="cce_bestpractice_00281__p19810642103411">When using storage resources in CCE, the most common method is to specify <strong id="cce_bestpractice_00281__b1439518042014">storageClassName</strong> to define the type of storage resources to be created when creating a PVC. The following configuration shows how to use a PVC to apply for an SAS (high I/O) EVS disk (block storage).</p>
<pre class="screen" id="cce_bestpractice_00281__screen146941631606">apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-evs-example
namespace: default
annotations:
everest.io/disk-volume-type: SAS
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: csi-disk</pre>
<p id="cce_bestpractice_00281__p10416164023811">If you need to specify the EVS disk type, you can set the <strong id="cce_bestpractice_00281__b69097575910">everest.io/disk-volume-type</strong> field. The value <strong id="cce_bestpractice_00281__b149091571397">SAS</strong> is used as an example here, indicating the high I/O EVS disk type. Or you can choose <strong id="cce_bestpractice_00281__b99091957698">SATA</strong> (common I/O) and <strong id="cce_bestpractice_00281__b1790918578914">SSD</strong> (ultra-high I/O).</p>
<p id="cce_bestpractice_00281__p1992812244296">This configuration method may not work if you want to:</p>
<ul id="cce_bestpractice_00281__ul1666681113305"><li id="cce_bestpractice_00281__li26671211203012">Set <strong id="cce_bestpractice_00281__b7751649116">storageClassName</strong> only, which is simpler than specifying the EVS disk type by using <strong id="cce_bestpractice_00281__b147618498116">everest.io/disk-volume-type</strong>.</li><li id="cce_bestpractice_00281__li1430122517314">Avoid modifying YAML files or Helm charts. Some users switch from self-built or other Kubernetes services to CCE and have written YAML files of many applications. In these YAML files, different types of storage resources are specified by different StorageClassNames. When using CCE, they need to modify a large number of YAML files or Helm charts to use storage resources, which is labor-consuming and error-prone.</li><li id="cce_bestpractice_00281__li6714783711">Set the default <strong id="cce_bestpractice_00281__b3414714817">storageClassName</strong> for all applications to use the default storage class. In this way, you can create storage resources of the default type without needing to specify <strong id="cce_bestpractice_00281__b15163103104815">storageClassName</strong> in the YAML file.</li></ul>
</div>
<div class="section" id="cce_bestpractice_00281__section10387181592813"><h4 class="sectiontitle">Solution</h4><p id="cce_bestpractice_00281__p33361127181019">This section describes how to set a custom storage class in CCE and how to set the default storage class. You can specify different types of storage resources by setting <strong id="cce_bestpractice_00281__b15705152195010">storageClassName</strong>.</p>
<ul id="cce_bestpractice_00281__ul1394816541798"><li id="cce_bestpractice_00281__li1494865412920">For the first scenario, you can define custom storageClassNames for SAS and SSD EVS disks. For example, define a storage class named <strong id="cce_bestpractice_00281__b11954204618017">csi-disk-sas</strong> for creating SAS disks. The following figure shows the differences before and after you use a custom storage class.<p id="cce_bestpractice_00281__p1639843625220"><span><img id="cce_bestpractice_00281__image62065521613" src="en-us_image_0000001102275444.png"></span></p>
</li><li id="cce_bestpractice_00281__li112521973108">For the second scenario, you can define a storage class with the same name as that in the existing YAML file without needing to modify <strong id="cce_bestpractice_00281__b13346387104">storageClassName</strong> in the YAML file.</li><li id="cce_bestpractice_00281__li595443471215">For the third scenario, you can set the default storage class as described below to create storage resources without specifying <strong id="cce_bestpractice_00281__b863812014124">storageClassName</strong> in YAML files.<pre class="screen" id="cce_bestpractice_00281__screen22067304183">apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-evs-example
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi</pre>
</li></ul>
</div>
<div class="section" id="cce_bestpractice_00281__section11887112131418"><h4 class="sectiontitle">Storage Classes in CCE</h4><p id="cce_bestpractice_00281__p1633311831410">Run the following command to query the supported storage classes.</p>
<pre class="screen" id="cce_bestpractice_00281__screen207891315121516"># kubectl get sc
NAME PROVISIONER AGE
csi-disk everest-csi-provisioner 17d # Storage class for EVS disks
csi-disk-topology everest-csi-provisioner 17d # Storage class for EVS disks with delayed association
csi-nas everest-csi-provisioner 17d # Storage class for SFS file systems
csi-obs everest-csi-provisioner 17d # Storage Class for OBS buckets
csi-sfsturbo everest-csi-provisioner 17d # Storage class for SFS Turbo file systems</pre>
<p id="cce_bestpractice_00281__p3417711182818">Check the details of <strong id="cce_bestpractice_00281__b08035920551">csi-disk</strong>. You can see that the type of the disk created by <strong id="cce_bestpractice_00281__b138145995512">csi-disk</strong> is SAS by default.</p>
<pre class="screen" id="cce_bestpractice_00281__screen12583162812818"># kubectl get sc csi-disk -oyaml
allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
creationTimestamp: "2021-03-17T02:10:32Z"
name: csi-disk
resourceVersion: "760"
selfLink: /apis/storage.k8s.io/v1/storageclasses/csi-disk
uid: 4db97b6c-853b-443d-b0dc-41cdcb8140f2
parameters:
csi.storage.k8s.io/csi-driver-name: disk.csi.everest.io
csi.storage.k8s.io/fstype: ext4
everest.io/disk-volume-type: SAS
everest.io/passthrough: "true"
provisioner: everest-csi-provisioner
reclaimPolicy: Delete
volumeBindingMode: Immediate</pre>
</div>
<div class="section" id="cce_bestpractice_00281__section179154267162"><h4 class="sectiontitle">Custom Storage Classes</h4><p id="cce_bestpractice_00281__p9601335151617">You can customize a high I/O storage class in a YAML file. For example, the name <strong id="cce_bestpractice_00281__b186185811594">csi-disk-sas</strong> indicates that the disk type is SAS (high I/O).</p>
<pre class="screen" id="cce_bestpractice_00281__screen659210819391">apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-disk-sas # Name of the high I/O storage class, which can be customized.
parameters:
csi.storage.k8s.io/csi-driver-name: disk.csi.everest.io
csi.storage.k8s.io/fstype: ext4
everest.io/disk-volume-type: SAS # High I/O EVS disk type, which cannot be customized.
everest.io/passthrough: "true"
provisioner: everest-csi-provisioner
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true # <strong id="cce_bestpractice_00281__b148711949142017">true</strong> indicates that capacity expansion is allowed.</pre>
<p id="cce_bestpractice_00281__p1281618138471">For an ultra-high I/O storage class, you can set the class name to <strong id="cce_bestpractice_00281__b722754812">csi-disk-ssd</strong> to create SSD EVS disk (ultra-high I/O).</p>
<pre class="screen" id="cce_bestpractice_00281__screen199713432478">apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-disk-ssd # Name of the ultra-high I/O storage class, which can be customized.
parameters:
csi.storage.k8s.io/csi-driver-name: disk.csi.everest.io
csi.storage.k8s.io/fstype: ext4
everest.io/disk-volume-type: SSD # Ultra-high I/O EVS disk type, which cannot be customized.
everest.io/passthrough: "true"
provisioner: everest-csi-provisioner
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true</pre>
<p id="cce_bestpractice_00281__p146067122106"><strong id="cce_bestpractice_00281__b69321846286">reclaimPolicy</strong>: indicates the recycling policies of the underlying cloud storage. The value can be <strong id="cce_bestpractice_00281__b9392322125012">Delete</strong> or <strong id="cce_bestpractice_00281__b91651126105014">Retain</strong>.</p>
<ul id="cce_bestpractice_00281__ul42481619111116"><li id="cce_bestpractice_00281__li1624871911111"><strong id="cce_bestpractice_00281__b1313332805014">Delete</strong>: When a PVC is deleted, both the PV and the EVS disk are deleted.</li><li id="cce_bestpractice_00281__li9248141919118"><strong id="cce_bestpractice_00281__b26601433105212">Retain</strong>: When a PVC is deleted, the PV and underlying storage resources are not deleted. Instead, you must manually delete these resources. After that, the PV resource is in the <strong id="cce_bestpractice_00281__b1956334045518">Released</strong> state and cannot be bound to the PVC again.</li></ul>
<div class="note" id="cce_bestpractice_00281__note8801953114018"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="cce_bestpractice_00281__p178035314020">The reclamation policy set here has no impact on the SFS Turbo storage.</p>
</div></div>
<p id="cce_bestpractice_00281__p778102518503">If high data security is required, you are advised to select <strong id="cce_bestpractice_00281__b1478374995218">Retain</strong> to prevent data from being deleted by mistake.</p>
<p id="cce_bestpractice_00281__p824713561207">After the definition is complete, run the <strong id="cce_bestpractice_00281__b14281158232">kubectl create</strong> commands to create storage resources.</p>
<pre class="screen" id="cce_bestpractice_00281__screen164494218115"># kubectl create -f sas.yaml
storageclass.storage.k8s.io/csi-disk-sas created
# kubectl create -f ssd.yaml
storageclass.storage.k8s.io/csi-disk-ssd created</pre>
<p id="cce_bestpractice_00281__p1412183715488">Query the storage class again. Two more types of storage classes are displayed in the command output, as shown below.</p>
<pre class="screen" id="cce_bestpractice_00281__screen13784148495"># kubectl get sc
NAME PROVISIONER AGE
csi-disk everest-csi-provisioner 17d
csi-disk-sas everest-csi-provisioner 2m28s
csi-disk-ssd everest-csi-provisioner 16s
csi-disk-topology everest-csi-provisioner 17d
csi-nas everest-csi-provisioner 17d
csi-obs everest-csi-provisioner 17d
csi-sfsturbo everest-csi-provisioner 17d</pre>
<p id="cce_bestpractice_00281__p05291082227">Other types of storage resources can be defined in the similar way. You can use kubectl to obtain the YAML file and modify it as required.</p>
<ul id="cce_bestpractice_00281__ul38311130152115"><li id="cce_bestpractice_00281__li18831113072113">File storage<pre class="screen" id="cce_bestpractice_00281__screen181646213295"># kubectl get sc csi-nas -oyaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: csi-nas
provisioner: everest-csi-provisioner
parameters:
csi.storage.k8s.io/csi-driver-name: nas.csi.everest.io
csi.storage.k8s.io/fstype: nfs
everest.io/share-access-level: rw
everest.io/share-access-to: 5e3864c6-e78d-4d00-b6fd-de09d432c632 # ID of the VPC to which the cluster belongs
everest.io/share-is-public: 'false'
everest.io/zone: xxxxx # AZ
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: Immediate</pre>
</li><li id="cce_bestpractice_00281__li4390135712118">Object storage<pre class="screen" id="cce_bestpractice_00281__screen1745353552911"># kubectl get sc csi-obs -oyaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: csi-obs
provisioner: everest-csi-provisioner
parameters:
csi.storage.k8s.io/csi-driver-name: obs.csi.everest.io
csi.storage.k8s.io/fstype: s3fs # Object storage type. <strong id="cce_bestpractice_00281__b581916217422">s3fs</strong> indicates an object bucket, and <strong id="cce_bestpractice_00281__b19130111019424">obsfs</strong> indicates a parallel file system.
everest.io/obs-volume-type: STANDARD # Storage class of the OBS bucket
reclaimPolicy: Delete
volumeBindingMode: Immediate</pre>
</li></ul>
</div>
<div class="section" id="cce_bestpractice_00281__section13586291218"><h4 class="sectiontitle">Setting a Default Storage Class</h4><p id="cce_bestpractice_00281__p163571329132111">You can specify a storage class as the default class. In this way, if you do not specify <strong id="cce_bestpractice_00281__b133883591469">storageClassName</strong> when creating a PVC, the PVC is created using the default storage class.</p>
<p id="cce_bestpractice_00281__p1435710291217">For example, to specify <strong id="cce_bestpractice_00281__b1964515812715">csi-disk-ssd</strong> as the default storage class, edit your YAML file as follows:</p>
<pre class="screen" id="cce_bestpractice_00281__screen5357429172112">apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-disk-ssd
annotations:
storageclass.kubernetes.io/is-default-class: "true" # Specifies the default storage class in a cluster. A cluster can have only one default storage class.
parameters:
csi.storage.k8s.io/csi-driver-name: disk.csi.everest.io
csi.storage.k8s.io/fstype: ext4
everest.io/disk-volume-type: SSD
everest.io/passthrough: "true"
provisioner: everest-csi-provisioner
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true</pre>
<p id="cce_bestpractice_00281__p1135711298213">Delete the created csi-disk-ssd disk, run the <strong id="cce_bestpractice_00281__b152561717817">kubectl create</strong> command to create a csi-disk-ssd disk again, and then query the storage class. The following information is displayed.</p>
<pre class="screen" id="cce_bestpractice_00281__screen135872982120"># kubectl delete sc csi-disk-ssd
storageclass.storage.k8s.io "csi-disk-ssd" deleted
# kubectl create -f ssd.yaml
storageclass.storage.k8s.io/csi-disk-ssd created
# kubectl get sc
NAME PROVISIONER AGE
csi-disk everest-csi-provisioner 17d
csi-disk-sas everest-csi-provisioner 114m
csi-disk-ssd (default) everest-csi-provisioner 9s
csi-disk-topology everest-csi-provisioner 17d
csi-nas everest-csi-provisioner 17d
csi-obs everest-csi-provisioner 17d
csi-sfsturbo everest-csi-provisioner 17d</pre>
</div>
<div class="section" id="cce_bestpractice_00281__section113669814307"><h4 class="sectiontitle">Verification</h4><ul id="cce_bestpractice_00281__ul326513332433"><li id="cce_bestpractice_00281__li1426593312439">Use <strong id="cce_bestpractice_00281__b72318715919">csi-disk-sas</strong> to create a PVC.<pre class="screen" id="cce_bestpractice_00281__screen164121655153014">apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sas-disk
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: csi-disk-sas</pre>
<p id="cce_bestpractice_00281__p1331523183215">Create a storage class and view its details. As shown below, the object can be created and the value of <strong id="cce_bestpractice_00281__b2841103141010">STORAGECLASS</strong> is <strong id="cce_bestpractice_00281__b1290115143103">csi-disk-sas</strong>.</p>
<pre class="screen" id="cce_bestpractice_00281__screen3819181515400"># kubectl create -f sas-disk.yaml
persistentvolumeclaim/sas-disk created
# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
sas-disk Bound pvc-6e2f37f9-7346-4419-82f7-b42e79f7964c 10Gi RWO csi-disk-sas 24s
# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-6e2f37f9-7346-4419-82f7-b42e79f7964c 10Gi RWO Delete Bound default/sas-disk csi-disk-sas 30s</pre>
<p id="cce_bestpractice_00281__p296654417436">View the PVC details on the CCE console. On the PV details page, you can see that the disk type is high I/O.</p>
<p id="cce_bestpractice_00281__p1365215405213"></p>
</li><li id="cce_bestpractice_00281__li16722125154315">If <strong id="cce_bestpractice_00281__b53910164176">storageClassName</strong> is not specified, the default configuration is used, as shown below.<pre class="screen" id="cce_bestpractice_00281__screen623034510524">apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ssd-disk
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi</pre>
<p id="cce_bestpractice_00281__p14101131875619">Create and view the storage resource. You can see that the storage class of PVC ssd-disk is csi-disk-ssd, indicating that csi-disk-ssd is used by default.</p>
<pre class="screen" id="cce_bestpractice_00281__screen133543256569"># kubectl create -f ssd-disk.yaml
persistentvolumeclaim/ssd-disk created
# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
sas-disk Bound pvc-6e2f37f9-7346-4419-82f7-b42e79f7964c 10Gi RWO csi-disk-sas 16m
ssd-disk Bound pvc-4d2b059c-0d6c-44af-9994-f74d01c78731 10Gi RWO csi-disk-ssd 10s
# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-4d2b059c-0d6c-44af-9994-f74d01c78731 10Gi RWO Delete Bound default/ssd-disk csi-disk-ssd 15s
pvc-6e2f37f9-7346-4419-82f7-b42e79f7964c 10Gi RWO Delete Bound default/sas-disk csi-disk-sas 17m</pre>
<p id="cce_bestpractice_00281__p14639104411583">View the PVC details on the CCE console. On the PV details page, you can see that the disk type is ultra-high I/O.</p>
<p id="cce_bestpractice_00281__p76651917155918"></p>
</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="cce_bestpractice_0053.html">Storage</a></div>
</div>
</div>