Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
O Elastic File System (EFS) é o
mecanismo subjacente da AWS para fornecer armazenamento (espaço em disco) ao cluster.
Um PersistentVolume é um recurso de cluster que disponibiliza o armazenamento EFS
para suas cargas de trabalho e garante que ele persista mesmo quando nenhuma
carga de trabalho estiver conectada a ele. Neste tópico, descrevemos como uma carga de trabalho pode acessar um
PersistentVolume com uma PersistentVolumeClaim.
O GKE na AWS dá suporte ao provisionamento estático de PersistentVolumes para todas
as versões compatíveis do Kubernetes. Para clusters no Kubernetes 1.24 ou
mais recente, o GKE na AWS também é compatível com o provisionamento dinâmico. Para usar o
provisionamento dinâmico, o administrador do cluster precisa configurá-lo. Saiba como fazer isso em
Configurar um PersistentVolume.
Criar um PersistentVolumeClaim
Escolha a guia apropriada abaixo, de acordo com sua preferência entre conectar a
carga de trabalho a um volume permanente provisionado estaticamente ou dinamicamente.
Estática
Estas instruções presumem que o administrador do cluster já tenha provisionado
pelo menos um PersistentVolume. Para acessar esse PersistentVolume e usar o
EFS subjacente com suas cargas de trabalho, crie um PersistentVolumeClaim.
Para criar um PersistentVolumeClaim para um PersistentVolume provisionado estaticamente,
copie o seguinte manifesto YAML em um arquivo chamado efs-claim.yaml.
CLAIM_NAME: um nome escolhido para a vinculação do PersistentVolumeClaim (por exemplo, efs-claim1). Deixe em branco para vincular à
classe de armazenamento padrão
Aplique o YAML ao cluster.
kubectl apply -f efs-claim.yaml
A saída confirma a criação do PersistentVolumeClaim.
persistentvolumeclaim/CLAIM_NAME created
Dynamic
Estas instruções presumem que o administrador do cluster já tenha provisionado
pelo menos um StorageClass para provisionamento dinâmico. Para criar um
PersistentVolume provisionado dinamicamente com essa StorageClass e usar o
ponto de acesso EFS subjacente com suas cargas de trabalho, crie uma PersistentVolumeClaim.
Para criar um PersistentVolumeClaim, siga estas etapas. O driver CSI do EFS usa
essa PersistentVolumeClaim com a StorageClass indicada para provisionar
dinamicamente um PersistentVolume.
Copie o seguinte manifesto do YAML para um arquivo chamado efs-claim.yaml:
CLAIM_NAME: um nome escolhido para a PersistentVolumeClaim,
por exemplo, efs-claim1
EFS_STORAGE_CLASS_NAME: o nome da StorageClass para a vinculação
da PersistentVolumeClaim. Deixe esse campo em branco para
vincular à classe de armazenamento padrão.
Aplique o YAML ao cluster.
kubectl apply -f efs-claim.yaml
A saída confirma a criação do PersistentVolumeClaim.
persistentvolumeclaim/CLAIM_NAME created
Crie um StatefulSet
Depois de criar um PersistentVolumeClaim, você pode usá-lo em uma carga de trabalho.
Nesta seção, criamos um exemplo de StatefulSet que usa uma PersistentVolumeClaim.
Também é possível usar um PersistentVolumeClaim com outros tipos de carga de trabalho,
como pods e implantações, fazendo referência à declaração em spec.volumes.
Para criar um StatefulSet que monte o recurso de EFS referenciado no PersistentVolumeClaim,
execute as etapas a seguir.
Copie o seguinte manifesto do YAML para um arquivo chamado efs-statefulset.yaml:
Este manifesto de exemplo inicia um contêiner do Ubuntu Linux que monta seu
recurso de EFS em /efs-data. O contêiner grava a cada cinco segundos em um
arquivo no recurso EFS chamado out.txt.
[[["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 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)"]]