Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Le système Elastic File System (EFS) est le mécanisme AWS sous-jacent permettant de fournir un espace de stockage (espace disque) à votre cluster.
Une ressource PersistentVolume est une ressource de cluster qui rend le stockage EFS disponible pour vos charges de travail et garantit qu'il persiste même lorsqu'aucune charge de travail n'y est connectée. Cet article explique comment une charge de travail peut accéder à une ressource PersistentVolume avec un objet PersistentVolumeClaim.
GKE sur AWS est compatible avec le provisionnement statique des ressources PersistentVolume pour toutes les versions de Kubernetes compatibles. Pour les clusters de version Kubernetes 1.24 ou ultérieure, GKE sur AWS est également compatible avec le provisionnement dynamique. Pour utiliser le provisionnement dynamique, votre administrateur de cluster doit le configurer. Pour en savoir plus, consultez la page Configurer un objet PersistentVolume.
Créer un objet PersistentVolumeClaim
Choisissez l'onglet approprié ci-dessous selon que vous souhaitez que votre charge de travail se connecte à un volume persistant provisionné de manière statique ou dynamique.
Statique
Ces instructions partent du principe que votre administrateur de cluster a déjà provisionné au moins une ressource PersistentVolume. Pour accéder à cette ressource PersistentVolume et utiliser son EFS sous-jacent avec vos charges de travail, créez un objet PersistentVolumeClaim.
Pour créer un objet PersistentVolumeClaim pour une ressource PersistentVolume provisionnée de manière statique, copiez le fichier manifeste YAML suivant dans un fichier nommé efs-claim.yaml.
CLAIM_NAME : nom que vous avez choisi d'associer à votre PersistentVolumeClaim, par exemple efs-claim1. Laissez ce champ vide pour associer à la classe de stockage par défaut
Appliquez le code YAML à votre cluster.
kubectl apply -f efs-claim.yaml
La sortie confirme la création de l'objet PersistentVolumeClaim.
persistentvolumeclaim/CLAIM_NAME created
Dynamique
Ces instructions supposent que votre administrateur de cluster a déjà provisionné au moins une ressource StorageClass pour le provisionnement dynamique. Pour créer une ressource PersistentVolume provisionnée de manière dynamique avec cette ressource StorageClass et utiliser le point d'accès EFS sous-jacent avec vos charges de travail, créez un objet PersistentVolumeClaim.
Pour créer un objet PersistentVolumeClaim, procédez comme suit : Le pilote CSI EFS utilise cet objet PersistentVolumeClaim avec la ressource StorageClass indiquée pour provisionner de manière dynamique une ressource PersistentVolume.
Copiez le fichier manifeste YAML suivant dans un fichier nommé efs-claim.yaml.
CLAIM_NAME : nom que vous avez choisi pour votre PersistentVolumeClaim, par exemple efs-claim1.
EFS_STORAGE_CLASS_NAME : nom de la ressource StorageClass que vous souhaitez lier à l'objet PersistentVolumeClaim. Laissez ce champ vide pour la lier à la classe de stockage par défaut.
Appliquez le code YAML à votre cluster.
kubectl apply -f efs-claim.yaml
La sortie confirme la création de l'objet PersistentVolumeClaim.
persistentvolumeclaim/CLAIM_NAME created
Créer un StatefulSet
Après avoir créé un objet PersistentVolumeClaim, vous pouvez l'utiliser dans une charge de travail.
Cette section crée un exemple de StatefulSet qui utilise un objet PersistentVolumeClaim.
Vous pouvez également utiliser un objet PersistentVolumeClaim avec d'autres types de charges de travail, comme des pods et des déploiements, en référençant la revendication dans spec.volumes.
Pour créer un StatefulSet qui installe la ressource EFS référencée dans votre objet PersistentVolumeClaim, procédez comme suit :
Copiez le fichier manifeste YAML suivant dans un fichier nommé efs-statefulset.yaml.
Cet exemple de fichier manifeste lance un conteneur Linux Ubuntu qui installe votre ressource EFS dans /efs-data. Le conteneur écrit toutes les cinq secondes dans un fichier de votre ressource EFS nommé out.txt.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2024/07/02 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2024/07/02 (UTC)."],[],[],null,["# Use an EFS resource\n\nThe [Elastic File System](https://aws.amazon.com/efs/) (EFS) is the\nunderlying AWS mechanism for providing storage (disk space) to your cluster.\nA PersistentVolume is a cluster resource that makes EFS\nstorage available to your workloads and ensures that it persists even when no\nworkloads are connected to it. This topic describes how a workload can access a\nPersistentVolume with a PersistentVolumeClaim.\n\nThis page is for Operators and Storage specialists who want to\nconfigure and manage storage. To learn more about common roles and example tasks\nthat we reference in Google Cloud content, see\n[Common GKE user roles and tasks](/kubernetes-engine/enterprise/docs/concepts/roles-tasks).\n\nGKE on AWS supports static provisioning of PersistentVolumes for all\nsupported Kubernetes versions. For clusters at Kubernetes version 1.24 or\nlater, GKE on AWS also supports dynamic provisioning. To use dynamic\nprovisioning, your cluster administrator must configure it. To learn how, see\n[configure a `PersistentVolume`](/kubernetes-engine/multi-cloud/docs/aws/how-to/configure-efs).\n| **Note:** Dynamic provisioning is available in GKE on AWS as a preview feature. Contact Google Cloud your support team for access.\n\nCreate a PersistentVolumeClaim\n------------------------------\n\nChoose the appropriate tab below depending on whether you want your workload to\nconnect to a statically or dynamically-provisioned persistent volume. \n\n### Static\n\nThese instructions assume that your cluster administrator has already provisioned\nat least one PersistentVolume. To access this PersistentVolume and use its\nunderlying EFS with your workloads, create a PersistentVolumeClaim.\n\nTo create a PersistentVolumeClaim for a statically-provisioned PersistentVolume,\ncopy the following YAML manifest into a file named `efs-claim.yaml`. \n\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eCLAIM_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n accessModes:\n - ReadWriteMany\n storageClassName: \"\" # Leave as empty string for static provisioning\n resources:\n requests:\n storage: 5Gi\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eCLAIM_NAME\u003c/var\u003e: a name you choose for your PersistentVolumeClaim to bind to - for example, `efs-claim1`. Leave blank to bind to the default storage class\n\n| **Note:** You must use the same `storageClassName` value for your PersistentVolume and PersistentVolumeClaim resources.\n\n1. Apply the YAML to your cluster.\n\n kubectl apply -f efs-claim.yaml\n\n This output confirms the PersistentVolumeClaim's creation. \n\n persistentvolumeclaim/\u003cvar translate=\"no\"\u003eCLAIM_NAME\u003c/var\u003e created\n\n### Dynamic\n\nThese instructions assume that your cluster administrator has already\nprovisioned at least one StorageClass for dynamic provisioning. To create a\ndynamically-provisioned PersistentVolume with this StorageClass and use the\nunderlying EFS access point with your workloads, create a PersistentVolumeClaim.\n\nTo create a PersistentVolumeClaim, follow these steps. The EFS CSI driver uses\nthis PersistentVolumeClaim with the indicated StorageClass to dynamically\nprovision a PersistentVolume.\n\n1. Copy the following YAML manifest into a file named `efs-claim.yaml`.\n\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eCLAIM_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n accessModes:\n - ReadWriteMany\n storageClassName: \"\u003cvar translate=\"no\"\u003eEFS_STORAGE_CLASS_NAME\u003c/var\u003e\"\n resources:\n requests:\n storage: 5Gi\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eCLAIM_NAME\u003c/var\u003e: a name you choose for your PersistentVolumeClaim - for example, `efs-claim1`\n- \u003cvar translate=\"no\"\u003eEFS_STORAGE_CLASS_NAME\u003c/var\u003e: the name of the StorageClass you want your PersistentVolumeClaim to bind to. Leave this field blank to bind to the default storage class\n\n1. Apply the YAML to your cluster.\n\n kubectl apply -f efs-claim.yaml\n\n The output confirms the PersistentVolumeClaim's creation. \n\n persistentvolumeclaim/\u003cvar translate=\"no\"\u003eCLAIM_NAME\u003c/var\u003e created\n\nCreate a StatefulSet\n--------------------\n\nAfter you have created a PersistentVolumeClaim, you can use it in a workload.\nThis section creates a sample StatefulSet that uses a PersistentVolumeClaim.\nYou can also use a PersistentVolumeClaim with other workload types\nsuch as Pods and Deployments by referencing the claim in `spec.volumes`.\n\nTo create a StatefulSet that mounts the EFS resource referenced in your\nPersistentVolumeClaim, perform the following steps.\n\n1. Copy the following YAML manifest into a file named `efs-statefulset.yaml`.\n This example manifest launches an Ubuntu Linux container that mounts your\n EFS resource at `/efs-data`. The container writes every five seconds to a\n file on your EFS resource named `out.txt`.\n\n apiVersion: apps/v1\n kind: StatefulSet\n metadata:\n name: efs-shell\n spec:\n selector:\n matchLabels:\n app: test-efs\n serviceName: efs-app\n replicas: 1\n template:\n metadata:\n labels:\n app: test-efs\n spec:\n terminationGracePeriodSeconds: 10\n containers:\n - name: linux\n image: ubuntu:bionic\n command: [\"/bin/sh\"]\n args: [\"-c\", \"while true; do echo $(date -u) \u003e\u003e /efs-data/out.txt; sleep 5; done\"]\n volumeMounts:\n - name: efs-volume\n mountPath: /efs-data\n volumes:\n - name: efs-volume\n persistentVolumeClaim:\n claimName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eCLAIM_NAME\u003c/span\u003e\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eCLAIM_NAME\u003c/var\u003e with the name of the PersistentVolumeClaim\n you specified previously - for example, `efs-claim1`.\n2. Apply the YAML to your cluster.\n\n kubectl apply -f efs-statefulset.yaml\n\n The output confirms the StatefulSet's creation. \n\n statefulset.apps/efs-shell created\n\n The StatefulSet might take several minutes to download and launch the container\n image.\n3. Confirm the StatefulSet's Pod is in `Running` status with `kubectl get pods`.\n\n kubectl get pods -l app=test-efs\n\n The output includes the name of the Pod and its status. In the following\n response, the Pod's name is `efs-shell-0`. \n\n NAME READY STATUS RESTARTS AGE\n efs-shell-0 1/1 Running 0 1m\n\n4. After the Pod is in Running status, use `kubectl exec` to connect to\n the Pod hosting the StatefulSet.\n\n kubectl exec -it efs-shell-0 -- bash\n\n The `kubectl` command launches a shell on the Pod.\n5. To confirm that your EFS resource is mounted, check the contents of\n the `out.txt` file with the `tail` command.\n\n tail /efs-data/out.txt\n\n The output contains recent times in UTC.\n6. Disconnect from the Pod with the `exit` command.\n\n exit\n\n Your shell returns to your local machine.\n\nClean up\n--------\n\nTo remove the StatefulSet, use `kubectl delete`. \n\n kubectl delete -f efs-statefulset.yaml\n\nWhat's next\n-----------\n\n- Learn how to [configure an EFS resource](/kubernetes-engine/multi-cloud/docs/aws/how-to/configure-efs)\n- Learn how to [use StorageClasses with your workloads](/kubernetes-engine/multi-cloud/docs/aws/how-to/storage-class)"]]