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"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["# Use a custom StorageClass with your workloads\n=============================================\n\nGKE on Azure automatically deploys\n[Azure Disk CSI Driver](https://github.com/kubernetes-sigs/azuredisk-csi-driver)\nand\n[Azure File CSI Driver](https://github.com/kubernetes-sigs/azurefile-csi-driver).\n\nThe Azure Disk CSI Driver and Azure File CSI Driver versions are tied to an GKE on Azure Kubernetes\nversion. The driver version is typically the latest available when a\nGKE version is released. When the cluster is upgraded, the\ndrivers update automatically.\n\nUse a custom StorageClass\n-------------------------\n\nYou can create additional StorageClasses for volumes or use\nContainer Storage Interface (CSI) Drivers.\n\n1. Choose if you are using an Azure disk volume or another CSI driver.\n\n ### Azure Disk Volume\n\n You can create your own custom StorageClass that specifies an Azure Disk volume\n type, file system type, and other parameters. You can find additional\n StorageClass parameters on the GKE on Azure Azure Disk CSI Driver\n [GitHub page](https://github.com/kubernetes-sigs/azuredisk-csi-driver/blob/v1.8.0/docs/driver-parameters.md).\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: disk.csi.azure.com\n volumeBindingMode: WaitForFirstConsumer\n allowVolumeExpansion: true\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 volumes in a\n [specific storage account](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-overview) and applies a\n [tag](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources)\n of `group=dev` to each new volume. \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\"\u003emy-custom-class\u003c/span\u003e\u003c/var\u003e\n provisioner: disk.csi.azure.com\n volumeBindingMode: WaitForFirstConsumer\n allowVolumeExpansion: true\n parameters:\n storageAccount: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003emy-storage-account\u003c/span\u003e\u003c/var\u003e\n tags: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003egroup=dev\u003c/span\u003e\u003c/var\u003e\n\n | **Note:** GKE on Azure doesn't support the UltraSSD_LRS account type.\n\n ### CSI Driver\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 values:\n - \u003cvar translate=\"no\"\u003eCLASS_NAME\u003c/var\u003e: the name of the StorageClass (for example, `my-custom-class`).\n - \u003cvar translate=\"no\"\u003eCSI_DRIVER_NAME\u003c/var\u003e: the name of the CSI driver (for example, `csi.example.com`).\n\n Next, configure subfields under `parameters` according to your CSI\n driver's documentation.\n2. Apply the YAML to your cluster.\n\n kubectl apply -f my-custom-class.yaml\n\n3. Create a PersistentVolumeClaim with a custom StorageClass.\n\n After you create a custom StorageClass, you can specify it in a PVC. The\n following example creates a PVC named `my-pvc` that references the\n StorageClass `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\nSet the default StorageClass\n----------------------------\n\nGKE on Azure uses a default StorageClass called `standard-rwo` that\nprovisions standard SSD Azure disks with\n[LRS](https://docs.microsoft.com/en-us/azure/storage/common/storage-redundancy#redundancy-in-the-primary-region). 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 `disk.csi.azure.com` driver. To install another\n storage driver, see\n [Installing a CSI driver](/kubernetes-engine/multi-cloud/docs/azure/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: disk.csi.azure.com\n volumeBindingMode: WaitForFirstConsumer\n parameters:\n skuName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eVOLUME_TYPE\u003c/span\u003e\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCLASS_NAME\u003c/var\u003e: the name of your new StorageClass.\n - \u003cvar translate=\"no\"\u003eVOLUME_TYPE\u003c/var\u003e: the Azure Disk [volume type](https://docs.microsoft.com/en-us/azure/virtual-machines/disks-types) that the StorageClass creates.\n\n For example, the following YAML creates a new default StorageClass that\n provisions\n [Premium SSD](https://docs.microsoft.com/en-us/azure/virtual-machines/disks-types#premium-ssds)\n Azure Disk volumes. \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: disk.csi.azure.com\n volumeBindingMode: WaitForFirstConsumer\n parameters:\n skuName: Premium_LRS\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 Azure 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 can 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- Read the documentation for the\n [Azure Disk CSI driver](https://github.com/kubernetes-sigs/azuredisk-csi-driver/tree/v1.8.0/docs)\n or the\n [Azure File CSI driver](https://github.com/kubernetes-sigs/azurefile-csi-driver/tree/v1.7.0/docs).\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/azure/how-to/storage-drivers) on your GKE on Azure\n cluster.\n\n- Deploy your first workload with the [Quickstart](/kubernetes-engine/multi-cloud/docs/azure/quickstart)."]]