Auf dieser Seite wird erläutert, wie Sie Volume-Ressourcen in Ihrem Cluster erstellen. Weitere Informationen finden Sie in der Kubernetes-Dokumentation zu Volume.
Volumes mit Deployments verwenden
Sie können ein Deployment mit Pods erstellen, bei dem jeder Pod ein oder mehrere Volumes enthält. Im folgenden Deployment-Manifest wird ein Deployment mit drei Pods beschrieben, die jeweils über das emptyDir-Volume verfügen.
In diesem Beispiel:
Das Feld metadata: name gibt ein Deployment mit dem Namen volumes-example-deployment an.
Die Spezifikation der Pod-Vorlage enthält das Feld volumes, das ein emptyDir-Volume mit dem Namen cache-volume beschreibt.
Die Containerspezifikation enthält das Feld volumeMounts:. Dieses gibt an, dass das Volume cache-volume unter dem Dateipfad /cache bereitgestellt wird.
Führen Sie den folgenden Befehl aus, um aus dieser Manifestdatei ein Deployment zu erstellen:
kubectlapply-fvolumes-demo.yaml
Mit dem folgenden Befehl, können Sie prüfen, ob das Deployment ordnungsgemäß ausgeführt wird und das erwartete Volume enthält:
kubectldescribepodsvolumes-example-deployment
Hiermit werden zu jedem der drei Pods im Deployment Informationen ausgegeben. In der Ausgabe wird angezeigt, dass jeder Pod einen Test-Container mit der Bereitstellung /cache hat:
Mounts:
/cache from cache-volume (rw)
Die Ausgabe zeigt auch, dass jeder Pod ein Volume mit dem Namen cache-volume enthält:
Volumes:
cache-volume:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Weitere Informationen zum Erstellen von Deployments finden Sie unter Deployment erstellen.
[[["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: 2024-09-03 (UTC)."],[],[],null,["# Creating volumes\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page explains how to create Volume resources in your cluster. For more\ndetails, see the\n[Kubernetes documentation about Volumes](https://kubernetes.io/docs/concepts/storage/volumes/).\n\nUsing Volumes with Deployments\n------------------------------\n\nYou can [create a Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)\nof Pods where each Pod contains one or more\nVolumes. The following Deployment manifest describes a Deployment of three Pods\nthat each have an [emptyDir Volume](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir).\n\nIn this example:\n\n- The `metadata: name` field specifies a Deployment named `volumes-example-deployment`.\n- The [Pod template](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/#pod-templates) specification includes a `volumes` field that describes an emptyDir volume named `cache-volume`.\n- The container specification includes a `volumeMounts:` field that specifies that the Volume named `cache-volume` is mounted at the file path `/cache`.\n- The manifest file is named `volumes-demo.yaml`.\n\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: volumes-example-deployment\n spec:\n replicas: 3\n selector:\n matchLabels:\n app: demo\n template:\n metadata:\n labels:\n app: demo\n spec:\n containers:\n - name: test-container\n image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0\n volumeMounts:\n - mountPath: /cache\n name: cache-volume\n volumes:\n - name: cache-volume\n emptyDir: {}\n\nTo create a Deployment from this manifest file, run the following command: \n\n kubectl apply -f volumes-demo.yaml\n\nVerify that your Deployment is running correctly and has the expected Volume\nwith this command: \n\n kubectl describe pods volumes-example-deployment\n\nThis prints information about each of the three Pods in the Deployment. The\noutput shows that each Pod has a container, test-container, with the `/cache`\nmount: \n\n Mounts:\n /cache from cache-volume (rw)\n\nThe output also shows that each Pod contains a Volume named `cache-volume`: \n\n Volumes:\n cache-volume:\n Type: EmptyDir (a temporary directory that shares a pod's lifetime)\n\nFor more information about creating Deployments, refer to [Creating a\nDeployment](/kubernetes-engine/docs/how-to/stateless-apps#create).\n\nWhat's next\n-----------\n\n- [Learn about PersistentVolumes, PersistentVolumeClaims, and dynamic storage provisioning](/kubernetes-engine/docs/concepts/persistent-volumes).\n- [Learn about using the Compute Engine persistent disk CSI Driver](/kubernetes-engine/docs/how-to/gce-pd-csi-driver)."]]