apiVersion:apps/v1kind:StatefulSetmetadata:name:webspec:selector:matchLabels:app:nginxtemplate:metadata:labels:app:nginxspec:containers:-name:nginximage:registry.k8s.io/nginx-slim:0.8volumeMounts:-name:wwwmountPath:/usr/share/nginx/htmlvolumeClaimTemplates:# This is the specification in which you reference the StorageClass-metadata:name:wwwspec:accessModes:["ReadWriteOnce"]resources:requests:storage:1GistorageClassName:my-custom-class# This field references the existing StorageClass
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Use StorageClasses with your workloads\n\nGKE on AWS automatically deploys the\n[Container Storage Interface (CSI) Driver for Amazon Elastic Block Store (EBS)](https://github.com/kubernetes-sigs/aws-ebs-csi-driver)\nto provision and manage Amazon EBS volumes in your clusters.\n\nThe GKE on AWS EBS CSI Driver version is tied to a GKE on AWS Kubernetes\nversion. The driver version is typically the latest available when the\nGKE version is released. When the cluster is upgraded, the\ndrivers update automatically.\n\nHow to use the default StorageClass\n-----------------------------------\n\nCreating a PersistentVolumeClaim without the field `spec.storageClassName` set\nprovisions a\n[`gp2` volume](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html)\nusing the default GKE on AWS EBS CSI Driver StorageClass.\n\nThe following YAML creates a PersistentVolumeClaim (PVC) named `mypvc` with a size\nof 30 gibibytes. \n\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: mypvc\n spec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 30Gi\n\nHow to use a different preinstalled StorageClass\n------------------------------------------------\n\nThe GKE on AWS EBS CSI Driver also includes the `premium-rwo` StorageClass, which\nprovisions higher-throughput\n[`io1` volumes](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html).\n\nYou can use it by specifying it in the `spec.storageclassName` of the\nPVC. \n\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: mypvc\n spec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 30Gi\n storageclassName: premium-rwo\n\nHow to use a custom StorageClass\n--------------------------------\n\nYou can create additional StorageClasses for EBS volumes or use\nContainer Storage Interface (CSI) Drivers.\n\n1. Choose if you are using an EBS volume or a specific CSI driver.\n\n ### EBS Volume\n\n You can create your own custom StorageClass that specifies an EBS volume\n type, file system type, and other parameters. You can find additional\n StorageClass parameters on the GKE on AWS EBS CSI Driver\n [GitHub page](https://github.com/kubernetes-sigs/aws-ebs-csi-driver#createvolume-parameters).\n\n To configure a custom StorageClass, copy the following YAML manifest into\n a file named `my-custom-class.yaml`. \n\n apiVersion: storage.k8s.io/v1\n kind: StorageClass\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eCLASS_NAME\u003c/span\u003e\u003c/var\u003e\n provisioner: ebs.csi.aws.com\n volumeBindingMode: WaitForFirstConsumer\n\n Replace \u003cvar translate=\"no\"\u003eCLASS_NAME\u003c/var\u003e with the name of your new\n StorageClass.\n\n For example, the following YAML creates a new StorageClass that\n provisions\n [Throughput Optimized HDD](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html#EBSVolumeTypes_st1)\n EBS volumes formatted with the\n [XFS](https://en.wikipedia.org/wiki/XFS) file system. \n\n apiVersion: storage.k8s.io/v1\n kind: StorageClass\n metadata:\n name: my-custom-class\n provisioner: ebs.csi.aws.com\n volumeBindingMode: WaitForFirstConsumer\n parameters:\n csi.storage.k8s.io/fsType: xfs\n type: st1\n\n ### CSI Driver\n\n | **Note:** This is an example. Check your CSI driver's documentation for required parameters.\n\n You can specify a different CSI driver in the `provisioner` field.\n\n To create a StorageClass with another CSI driver, you can use the example\n YAML below. \n\n apiVersion: storage.k8s.io/v1\n kind: StorageClass\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eCLASS_NAME\u003c/span\u003e\u003c/var\u003e\n provisioner: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eCSI_DRIVER_NAME\u003c/span\u003e\u003c/var\u003e\n volumeBindingMode: WaitForFirstConsumer\n parameters:\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003e...\u003c/span\u003e\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCSI_DRIVER_NAME\u003c/var\u003e with the name of the CSI driver---for example,`csi.example.com`\n - \u003cvar translate=\"no\"\u003eCLASS_NAME\u003c/var\u003e with the name of the StorageClass---for example, `my-custom-class`\n\n Configure the sub-fields under `parameters` according to your CSI driver.\n2. Apply the YAML to your cluster.\n\n kubectl apply -f my-custom-class.yaml\n\n### How to create a PersistentVolumeClaim with a custom StorageClass\n\n1. Once a custom StorageClass is created, you can specify it in a PVC. The example\n below creates a PVC named `my-pvc` that references the StorageClass\n `my-custom-class`.\n\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: my-pvc\n spec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 30Gi\n storageclassName: my-custom-class\n\nHow to set the default StorageClass\n-----------------------------------\n\nGKE on AWS uses a default StorageClass called\n`standard-rwo` that provisions\n[gp2 EBS volumes](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html#EBSVolumeTypes_gp2). You can change the default to another StorageClass.\n\nTo change the default StorageClass:\n\n1. Update the `is-default-class` annotation for the `standard-rwo`\n StorageClass with `kubectl patch`.\n\n kubectl patch storageclass standard-rwo -p \\\n '{\"metadata\": {\"annotations\":{\"storageclass.kubernetes.io/is-default-class\":\"false\"}}}'\n\n2. Create a new StorageClass that has the annotation\n `storageclass.kubernetes.io/is-default-class: true`.\n\n The following example\n StorageClass uses the `ebs.csi.aws.com` driver. To install another\n storage driver, see\n [Installing a CSI driver](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/storage-drivers).\n\n Copy the following YAML into a file named `my-custom-class.yaml`. \n\n apiVersion: storage.k8s.io/v1\n kind: StorageClass\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eCLASS_NAME\u003c/span\u003e\u003c/var\u003e\n annotations:\n storageclass.kubernetes.io/is-default-class: true\n provisioner: ebs.csi.aws.com\n volumeBindingMode: WaitForFirstConsumer\n parameters:\n type: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eEBS_VOLUME_TYPE\u003c/span\u003e\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eEBS_VOLUME_TYPE\u003c/var\u003e: the AWS [EBS volume type](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html) that the StorageClass creates.\n - \u003cvar translate=\"no\"\u003eCLASS_NAME\u003c/var\u003e with the name of your new StorageClass\n\n For example, the following YAML creates a new default StorageClass that\n provisions\n [Throughput Optimized HDD](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html#EBSVolumeTypes_st1)\n EBS volumes formatted with the\n [XFS](https://en.wikipedia.org/wiki/XFS) file system. \n\n apiVersion: storage.k8s.io/v1\n kind: StorageClass\n metadata:\n name: my-custom-default-class\n annotations:\n storageclass.kubernetes.io/is-default-class: \"true\"\n provisioner: ebs.csi.aws.com\n volumeBindingMode: WaitForFirstConsumer\n parameters:\n csi.storage.k8s.io/fsType: xfs\n type: st1\n\n3. Apply the new custom class to your cluster.\n\n kubectl apply -f my-custom-class.yaml\n\nAfter applying this manifest, GKE on AWS uses the\n`my-custom-default-class` StorageClass for new storage requests.\n\nReference the StorageClass in a StatefulSet\n-------------------------------------------\n\nTo use your new StorageClass, you must reference it in a StatefulSet's\n`volumeClaimTemplates`.\n\nWhen you reference a StorageClass in a StatefulSet's `volumeClaimTemplates`\nspecification, Kubernetes provides stable storage using PersistentVolumes (PVs).\nKubernetes calls the provisioner defined in the StorageClass to create a new\nstorage volume. After the volume is provisioned, Kubernetes automatically\ncreates a PV.\n\nThe following StatefulSet references the `my-custom-class` StorageClass and\nprovisions a 1 gibibyte volume: \n\n apiVersion: apps/v1\n kind: StatefulSet\n metadata:\n name: web\n spec:\n selector:\n matchLabels:\n app: nginx\n template:\n metadata:\n labels:\n app: nginx\n spec:\n containers:\n - name: nginx\n image: registry.k8s.io/nginx-slim:0.8\n volumeMounts:\n - name: www\n mountPath: /usr/share/nginx/html\n volumeClaimTemplates: # This is the specification in which you reference the StorageClass\n - metadata:\n name: www\n spec:\n accessModes: [ \"ReadWriteOnce\" ]\n resources:\n requests:\n storage: 1Gi\n storageClassName: my-custom-class # This field references the existing StorageClass\n\nWhat's next\n-----------\n\n- Learn about\n [Persistent volumes in GKE](/kubernetes-engine/docs/concepts/persistent-volumes).\n\n- Install [Storage drivers](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/storage-drivers) on your GKE on AWS\n cluster.\n\n- Deploy your first workload with the [Quickstart](/kubernetes-engine/multi-cloud/docs/aws/quickstart)."]]