Das in dieser Dokumentation beschriebene Produkt Anthos-Cluster in AWS (vorherige Generation) befindet sich jetzt im Wartungsmodus. Alle neuen Installationen müssen Anthos-Cluster in AWS der aktuellen Generation verwenden.
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Übersicht
Wenn Sie bereits ein AWS Elastic Block Store-Volume (EBS) zum Importieren in GKE on AWS haben, können Sie ein PersistentVolume-Objekt (PV) erstellen und dieses für einen bestimmten PersistentVolumeClaim (PVC) reservieren.
Auf dieser Seite wird erläutert, wie Sie mithilfe eines vorhandenen, mit Daten gefüllten EBS-Volumes ein PV erstellen und in einem Pod verwenden.
Vorbereitung
Verwenden Sie im anthos-aws-Verzeichnis anthos-gke, um den Kontext zu Ihrem Nutzercluster zu wechseln.
cd anthos-aws
env HTTPS_PROXY=http://localhost:8118 \
anthos-gke aws clusters get-credentials CLUSTER_NAME
Ersetzen Sie CLUSTER_NAME durch den Namen Ihres Nutzerclusters.
PersistentVolume für ein bereits vorhandenes EBS-Volume erstellen
Sie können ein vorhandenes EBS-Volume durch Angabe eines neuen PV importieren.
Kopieren Sie die folgende YAML-Datei in eine Datei mit dem Namen existing-volume.yaml und vervollständigen Sie die Konfiguration. Ersetzen Sie dabei die folgenden Werte:
volume-capacity: Größe des Volumes. Beispiel: 30Gi
Weitere Informationen zum Angeben der Volume-Kapazität in Kubernetes finden Sie unter Bedeutung des Arbeitsspeichers.
storage-class-name: Der Name der StorageClass, die das Volume bereitstellt.
Sie können beispielsweise den Standardwert standard-rwo verwenden.
Die Ausgabe dieses Befehls enthält den Status des PV.
Volume mit einem PersistentVolumeClaim und einem Pod verwenden
Nachdem Sie das Volume importiert haben, können Sie einen PVC und einen Pod erstellen, an den der PVC anhängt wird.
Die folgende YAML-Datei erstellt einen PVC und hängt ihn an einen Pod an, auf dem der Nginx-Webserver ausgeführt wird. Kopieren Sie die Datei in eine Datei mit dem Namen nginx.yaml und vervollständigen Sie die Konfiguration. Ersetzen Sie dabei die folgenden Werte:
storage-class: Der Name der StorageClass aus dem zuvor erstellten PersistentVolume. Beispiel: standard-rwo
volume-name: Der Name des zuvor erstellten Volumes.
volume-capacity: Größe des Volumes. Beispiel: 30Gi
Prüfen Sie den Status der Nginx-Instanz mit kubectl describe. In der Ausgabe sollte Running als STATUS enthalten sein.
kubectldescribepodweb-server
Verschlüsselte EBS-Volumes verwenden
Wenn Ihr EBS-Volume mit dem AWS Key Management Service (KMS) verschlüsselt ist, müssen Sie der GKE on AWS-Steuerungsebene Zugriff auf Ihren KMS-Schlüssel gewähren.
Führen Sie die folgenden Schritte aus, um den Namen der AWS IAM-Rolle abzurufen:
Wechseln Sie in das Verzeichnis mit Ihrer GKE on AWS-Konfiguration.
Sie haben dieses Verzeichnis bei der Installation des Verwaltungsdienstes erstellt.
cd anthos-aws
Wählen Sie aus, ob Sie Ihre GKE on AWS-Umgebung mit dem anthos-gke-Tool oder manuell erstellt haben.
Anthos-gke-Tool
Verwenden Sie den Befehl terraform output und suchen Sie nach dem Wert von iamInstanceProfile.
terraformoutput|grepiamInstanceProfile
Wenn Sie Ihre GKE on AWS-Umgebung mit dem anthos-
gke-Tool erstellt haben, sieht die Ausgabe so aus:
Kopieren Sie den Wert von INSTANCE_PROFILE_NAME für den folgenden Schritt.
Um der Steuerungsebene Zugriff auf Ihre EBS-Volumes zu gewähren, fügen Sie dem AWS KMS-Schlüssel, der zum Verschlüsseln EBS-Volume verwendet wird, das AWS-IAM-Profil gke-xxxxxx-controlplane als Schlüsselnutzer hinzu.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-31 (UTC)."],[],[],null,["# Importing a preexisting EBS volume\n\nOverview\n--------\n\nIf you already have an AWS Elastic Block Store (EBS) volume to import into\nGKE on AWS, you can create a PersistentVolume (PV) object and\nreserve it for a specific PersistentVolumeClaim (PVC).\n\nThis page explains how to create a PV by using an existing EBS volume\npopulated with data, and how to use the PV in a Pod.\n\nBefore you begin\n----------------\n\n- From your `anthos-aws` directory, use `anthos-gke` to switch context to your user cluster. \n\n ```sh\n cd anthos-aws\n env HTTPS_PROXY=http://localhost:8118 \\\n anthos-gke aws clusters get-credentials CLUSTER_NAME\n ```\n Replace \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e with your user cluster name.\n\n### Creating a PersistentVolume for a pre-existing EBS volume\n\nYou can import an existing EBS volume by specifying a new PV.\n\n1. Copy the following YAML into a file named `existing-volume.yaml` and complete\n your configuration by replacing the values:\n\n - \u003cvar translate=\"no\"\u003evolume-capacity\u003c/var\u003e: size of the volume. For example, `30Gi`. For more information on specifying volume capacity in Kubernetes, see the [Meaning of memory](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory).\n - \u003cvar translate=\"no\"\u003estorage-class-name\u003c/var\u003e: the name of the StorageClass that\n provisions the volume.\n For example, you can use the default `standard-rwo`.\n\n | **Note:** A StorageClass is required to reference other attributes like `allowVolumeExpansion`, even if a volume is not dynamically provisioned.\n - \u003cvar translate=\"no\"\u003eebs-id\u003c/var\u003e: EBS [volume id](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-volumes.html#examples).\n For example, `vol-05786ec9ec9526b67`.\n\n - \u003cvar translate=\"no\"\u003efs-type\u003c/var\u003e: The\n [file system](https://github.com/kubernetes-sigs/aws-ebs-csi-driver#createvolume-parameters)\n of the volume. For example, `ext4`.\n\n - \u003cvar translate=\"no\"\u003ezone\u003c/var\u003e: The AWS Availability Zone that hosts the EBS volume.\n For example, `us-east-1c`.\n\n apiVersion: v1\n kind: PersistentVolume\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003evolume-name\u003c/span\u003e\u003c/var\u003e\n annotations:\n pv.kubernetes.io/provisioned-by: ebs.csi.aws.com\n spec:\n capacity:\n storage: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003evolume-capacity\u003c/span\u003e\u003c/var\u003e\n accessModes:\n - ReadWriteOnce\n persistentVolumeReclaimPolicy: Retain\n storageClassName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003estorage-class-name\u003c/span\u003e\u003c/var\u003e\n claimRef:\n name: my-pvc\n namespace: default\n csi:\n driver: ebs.csi.aws.com\n volumeHandle: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eebs-volume-id\u003c/span\u003e\u003c/var\u003e\n fsType: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003efile-system-type\u003c/span\u003e\u003c/var\u003e\n nodeAffinity:\n required:\n nodeSelectorTerms:\n - matchExpressions:\n - key: topology.ebs.csi.aws.com/zone\n operator: In\n values:\n - \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ezone\u003c/span\u003e\u003c/var\u003e\n\n2. Apply the YAML to your cluster\n\n kubectl apply -f existing-volume.yaml\n\n3. Confirm the creation of your PV\n\n kubectl describe pv \u003cvar translate=\"no\"\u003evolume-name\u003c/var\u003e\n\n The output of this command contains the status of the PV.\n\nUsing the volume with a PersistentVolumeClaim and Pod\n-----------------------------------------------------\n\nAfter you have imported your volume, you can create a PVC and a Pod that\nattaches the PVC.\n\nThe YAML below creates a PVC and attaches it to a Pod running the Nginx web\nserver. Copy it into a file named `nginx.yaml` and complete your configuration\nby replacing the values:\n\n- \u003cvar translate=\"no\"\u003estorage-class\u003c/var\u003e: The name of the StorageClass from the PersistentVolume you created previously. For example, `standard-rwo`.\n- \u003cvar translate=\"no\"\u003evolume-name\u003c/var\u003e: The name of the volume you created previously.\n- \u003cvar translate=\"no\"\u003evolume-capacity\u003c/var\u003e: size of the volume. For example, `30Gi`.\n\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: my-pvc\n spec:\n storageClassName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003estorage-class-name\u003c/span\u003e\u003c/var\u003e\n volumeName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003evolume-name\u003c/span\u003e\u003c/var\u003e\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003evolume-capacity\u003c/span\u003e\u003c/var\u003e\n ---\n\n apiVersion: v1\n kind: Pod\n metadata:\n name: web-server\n spec:\n containers:\n - name: web-server\n image: nginx\n volumeMounts:\n - mountPath: /var/lib/www/html\n name: data\n volumes:\n - name: data\n persistentVolumeClaim:\n claimName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003emy-pvc\u003c/span\u003e\u003c/var\u003e\n\n1. Apply the YAML to your cluster\n\n kubectl apply -f nginx.yaml\n\n2. Check the status of your Nginx instance with `kubectl describe`. The output\n should have a `STATUS` of `Running`.\n\n kubectl describe pod web-server\n\nUsing encrypted EBS volumes\n---------------------------\n\nIf your EBS volume is encrypted with the AWS Key Management Service (KMS), you\nneed to grant the GKE on AWS control plane AWS IAM role access to\nyour KMS key.\n\nTo get the AWS IAM role name, perform the following steps:\n\n1. Change to the directory with your GKE on AWS configuration.\n You created this directory when\n [Installing the management service](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/installing-management).\n\n ```sh\n cd anthos-aws\n ```\n\n \u003cbr /\u003e\n\n2. Choose if you created your GKE on AWS environment with the\n `anthos-gke` tool or if you created your AWS IAM profiles manually.\n\n ### anthos-gke tool\n\n Use the `terraform output` command and search for the value of\n `iamInstanceProfile`. \n\n terraform output | grep iamInstanceProfile\n\n If you created your GKE on AWS environment with the `anthos-\n gke` tool, the output looks like the following: \n\n iamInstanceProfile: gke-\u003cvar translate=\"no\"\u003eCLUSTER_ID\u003c/var\u003e-controlplane\n iamInstanceProfile: gke-\u003cvar translate=\"no\"\u003eCLUSTER_ID\u003c/var\u003e-nodepool\n\n Where \u003cvar translate=\"no\"\u003eCLUSTER_ID\u003c/var\u003e is your cluster's ID. Copy the value of\n `gke-`\u003cvar translate=\"no\"\u003eCLUSTER_ID\u003c/var\u003e`-controlplane` for the following step.\n\n ### Manually created\n\n Examine the output of `terraform output` with the following command: \n\n terraform output | less\n\n Scroll through the output and find the iamInstanceProfile after the\n AWSCluster definition. \n\n kind: AWSCluster\n metadata:\n name: cluster-0\n spec:\n ...\n controlPlane:\n ...\n iamInstanceProfile: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eINSTANCE_PROFILE_NAME\u003c/span\u003e\u003c/var\u003e\n\n Copy the value of `INSTANCE_PROFILE_NAME` for the following\n step.\n3. To grant the control plane access to your EBS volumes, add the\n `gke-xxxxxx-controlplane` AWS IAM profile as a\n [Key User](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-default-allow-users)\n to the AWS KMS key used to encrypt your EBS volume.\n\nWhat's next\n-----------\n\n- Use additional [storage drivers](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/storage-drivers) with GKE on AWS."]]