Esta documentação é referente à versão mais recente do GKE no Azure, lançada em novembro de 2021. Consulte as Notas de lançamento para mais informações.
As versões dos drivers CSI do Disco do Azure e de Arquivos do Azure estão vinculadas a uma versão do Kubernetes do GKE no Azure. Geralmente, a versão do driver é a mais recente disponível quando a versão do
GKE é lançada. Quando o cluster é atualizado, os
drivers são atualizados automaticamente.
Usar um StorageClass personalizado
É possível criar mais StorageClasses para volumes EBS ou usar
drivers do Container Storage Interface (CSI).
Escolha se você está usando um volume de disco do Azure ou outro driver CSI.
Volume do disco do Azure
É possível criar seu próprio StorageClass personalizado que especifica um tipo
de volume de disco do Azure, um tipo de sistema de arquivos e outros parâmetros. É possível encontrar outros parâmetros StorageClass na página do GitHub do driver CSI do Disco do Azure do GKE do Azure.
Para configurar um StorageClass personalizado, copie o seguinte manifesto YAML em
um arquivo chamado my-custom-class.yaml.
Substitua CLASS_NAME pelo nome do novo
StorageClass.
Por exemplo, o YAML a seguir cria um novo StorageClass que provisiona volumes em uma conta de armazenamento específica e aplica uma tag de group=dev para cada novo volume.
CLASS_NAME: o nome do StorageClass (por exemplo,
my-custom-class).
CSI_DRIVER_NAME: o nome do driver CSI (por exemplo,
csi.example.com).
Em seguida, configure subcampos em parameters de acordo com a documentação
do driver CSI.
Aplique o YAML ao cluster.
kubectl apply -f my-custom-class.yaml
Crie um PersistentVolumeClaim com um StorageClass personalizado.
Depois de criar um StorageClass personalizado, é possível especificá-lo em um PVC. O exemplo a seguir cria um PVC chamado my-pvc que referencia o StorageClass my-custom-class.
O GKE no Azure usa um StorageClass padrão chamado standard-rwo que provisiona discos SSD padrão do Azure com LRS. É possível alterar o padrão para outro StorageClass.
Para alterar o StorageClass padrão:
Atualize a anotação is-default-class do StorageClass standard-rwo
com kubectl patch.
Depois de aplicar esse manifesto, o GKE no Azure usará o StorageClass my-custom-default-class para novas solicitações de armazenamento.
Referenciar o StorageClass em um StatefulSet
Para usar o novo StorageClass, é possível referenciá-lo no volumeClaimTemplates do
StatefulSet.
Quando você se referir a um StorageClass na especificação volumeClaimTemplates
de um StatefulSet, o Kubernetes fornecerá armazenamento estável usando PersistentVolumes (PVs).
O Kubernetes chama o provisionador definido no StorageClass para criar um novo
volume de armazenamento. Depois que o volume for provisionado, o Kubernetes criará
automaticamente um PV.
O StatefulSet a seguir referencia o StorageClass my-custom-class e
provisiona um volume de 1 gibibyte:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.8
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates: # This is the specification in which you reference the StorageClass
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
storageClassName: my-custom-class # This field references the existing StorageClass
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2024-06-26 UTC."],[],[],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)."]]