Deploying, Scaling, and Monitoring Kubernetes Storage

Introduction to Kubernetes

Frank Heilmann

Platform Architect and Freelance Instructor

Persistent Volumes and Persistent Volume Claims

Persistent Volumes and Persistent Volume Claims

  • Fundamental Objects for storage: Persistent Volumes (PV), maintained in parallel to Pods
  • PVs are mapped to Pods using Persistent Volume Claims (PVC)
  • A mapped PV allows data persistence when the Pod is stopped, killed, or restarted
  • PVs enable the separation of storage and compute
Introduction to Kubernetes

Storage Classes

Storage Classes

  • PVs: provisioned either
    • manually by an Kubernetes admin
    • dynamically by regular user
  • Dynamic provisioning happens via Storage Classes (SC) without human intervention
  • Storage Classes (SC):

    • defined by Kubernetes admin
    • different types (different latency, e.g., SDD vs HDD, different backup strategies)
  • If in doubt, use Storage Classes ;-)

Introduction to Kubernetes

Putting it all together

  • There are only three objects that make storage work:

    • PersistentVolume
    • PersistentVolumeClaim
    • StorageClass
  • A Pod with demand for persisted data uses a PersistentVolumeClaim

  • This PVC has Kubernetes create a PersistentVolume for the Pod
  • This PersistentVolume is mapped to the claiming Pod
  • A named StorageClass is used, which defines details like latency and backup strategy of the PV
  • This PersistentVolume survives (together with stored data), even when the Pod is terminated
Introduction to Kubernetes

Manifest Snippets

Pod with PersistentVolume

apiVersion: v1
kind: Pod
...

spec: containers: ... volumeMounts: - name: pv-mydata mountPath: /mydata
volumes: - name: pv-mydata persistentVolumeClaim: claimName: datacamp-pvc

PersistentVolumeClaim with StorageClass

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: datacamp-pvc

spec: storageClassName: "standard" accessModes: - ReadWriteOnce
resources: requests: storage: 5Gi
Introduction to Kubernetes

"kubectl" Commands For Storage

  • kubectl offers a complete set of commands to create and monitor Kubernetes Storage
  • Examples:
    • kubectl get sc lists all available Storage Classes
    • kubectl get pvc lists all deployed Persistent Volume Claimes
    • kubectl get pv lists all deployed Persistent Volumes
    • As usual, kubectl apply -f <manifest> can be used to deploy storage resources that are declared in Manifests.
Introduction to Kubernetes

Let's practice!

Introduction to Kubernetes

Preparing Video For Download...