0Pricing
Docker & Kubernetes for Developers · Lektion

Persistente Volumes und Claims

Verstehen Sie, wie Speicher in Kubernetes mithilfe von PVs und PVCs dynamisch bereitgestellt und verwendet wird.

Persistente Volumes und Claims ist eine kostenlose Docker & Kubernetes for Developers-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Docker & Kubernetes for Developers-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Docker & Kubernetes for Developers-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Ephemeral Pods, Persistent Data

In Kubernetes, Pods are designed to be temporary and replaceable. If a Pod crashes or is rescheduled, any data stored directly within it is lost.

This ephemeral nature is great for stateless applications, but what about applications that need to store data persistently, like databases or file servers?

Introducing Persistent Volumes

A Persistent Volume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically by Kubernetes.

It's an abstraction of the underlying storage (like a cloud disk, NFS share, or local disk), making it available for use by Pods without them needing to know the storage's specifics.

PV Capacity & Access Modes

Each PV has specific characteristics:

  • Capacity: The size of the storage, e.g., 10Gi.
  • Access Modes: How the storage can be mounted by Pods.
  • Reclaim Policy: What happens to the volume after a Pod is done using it.

These properties help Kubernetes match storage requests to available volumes.

How Pods Access Storage

PV Access Modes define how the volume can be mounted:

  • ReadWriteOnce (RWO): The volume can be mounted as read-write by a single node.
  • ReadOnlyMany (ROX): The volume can be mounted as read-only by many nodes.
  • ReadWriteMany (RWX): The volume can be mounted as read-write by many nodes.

Not all storage types support all modes. For example, a local disk typically only supports RWO.

Handling Released PVs

A PV's Reclaim Policy dictates what happens to the underlying storage when the PV is released from its claim:

  • Retain: Manual reclamation. Data remains, administrator must manually delete.
  • Delete: The underlying storage is automatically deleted along with the PV. This is common for dynamically provisioned volumes.
  • Recycle: (Deprecated) Wipes the volume and makes it available again.

Retain is useful for critical data that needs manual review before deletion.

Requesting Persistent Storage

A Persistent Volume Claim (PVC) is a request for storage by a user or application.

Think of it like a request for a specific type and size of storage. Instead of directly interacting with PVs, Pods request storage through PVCs.

PVCs provide a layer of abstraction, allowing developers to request storage without knowing the underlying infrastructure details.

Matching Storage Requests

When a PVC is created, Kubernetes tries to find a suitable PV to bind it to. This process is called binding.

It looks for PVs that meet the PVC's requirements:

  • Capacity (size)
  • Access Modes
  • Storage Class (if specified)

Once bound, the PV is exclusively reserved for that PVC.

Defining a Basic PV

Here's how you might define a simple hostPath Persistent Volume. This type uses a directory on the node's filesystem, primarily for single-node testing.

Try running this example (kubectl apply -f pv.yaml):

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 1Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: "/mnt/data"

Requesting Storage with a PVC

Now, let's create a Persistent Volume Claim that requests 1Gi of storage with ReadWriteOnce access. It will bind to our my-pv if available.

Try running this example (kubectl apply -f pvc.yaml):

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

Attaching PVC to a Pod

Finally, let's see how a Pod can use the storage provided by our PVC. We reference the PVC in the Pod's volumes section and then mount it into a container.

Try running this example (kubectl apply -f pod.yaml):

apiVersion: v1
kind: Pod
metadata:
  name: my-app-pod
spec:
  volumes:
    - name: my-storage
      persistentVolumeClaim:
        claimName: my-pvc
  containers:
    - name: my-container
      image: busybox
      command: ["sh", "-c", "echo 'Hello from CoddyKit!' > /data/message.txt && sleep 3600"]
      volumeMounts:
        - mountPath: "/data"
          name: my-storage

PV vs. PVC Roles

Understanding the distinct roles of Persistent Volumes (PVs) and Persistent Volume Claims (PVCs) is crucial for managing storage in Kubernetes.

Which statement accurately describes the primary role of a Persistent Volume (PV)?

Recap: Persistent Storage

Great job! You've learned how Kubernetes manages persistent storage:

  • Persistent Volumes (PVs) abstract physical storage resources.
  • Persistent Volume Claims (PVCs) are user requests for storage.
  • PVs have capacity, access modes (RWO, ROX, RWX), and reclaim policies (Retain, Delete).
  • PVCs bind to available PVs, and Pods then use PVCs to mount storage.

This system allows applications to reliably store data, even when Pods are recreated or moved.

Häufig gestellte Fragen

Ist die Lektion „Persistente Volumes und Claims“ kostenlos?

Ja — der vollständige Text von „Persistente Volumes und Claims“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Docker & Kubernetes for Developers-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Docker & Kubernetes for Developers-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Persistente Volumes und Claims“?

Verstehen Sie, wie Speicher in Kubernetes mithilfe von PVs und PVCs dynamisch bereitgestellt und verwendet wird. Du übst Docker & Kubernetes for Developers mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Docker & Kubernetes for Developers zu starten?

Keine Vorkenntnisse erforderlich. Docker & Kubernetes for Developers auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Persistente Volumes und Claims“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Docker & Kubernetes for Developers-Lektion Code schreiben und ausführen?

Ja. Jede Docker & Kubernetes for Developers-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Persistente Volumes und Claims
  2. Zustandsbehaftete Anwendungen mit StatefulSets verwalten
  3. ConfigMaps und Secrets für die Konfiguration
  4. StorageClasses und dynamische Bereitstellung
← Zurück zu Docker & Kubernetes for Developers