Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 345 of 8025. Advanced Kubernetes ConfigurationFree lesson

Configuring Local Persistent Volumes for Performance

Optimize I/O throughput for stateful applications by mapping local node storage directly to persistent volume claims using specific affinity rules.

In this lesson, you will learn how to boost your stateful application's I/O performance by bypassing network latency and mapping your application directly to the physical storage media of a specific Kubernetes node.

Why Local Storage Matters

Most Persistent Volumes (PVs) you’ve used so far likely rely on network-attached storage (like AWS EBS or NFS). While convenient, these introduce network overhead that can bottleneck high-performance databases or intensive data-processing workloads. Local Persistent Volumes allow a pod to write directly to a local disk (like an NVMe SSD) physically attached to the node, providing raw hardware performance.

Binding Storage to Nodes

Because local storage is physically trapped on one machine, Kubernetes must ensure your pod always lands on the node where that specific disk resides. We achieve this using Node Affinity.

To configure this, you first define a PersistentVolume that points to a specific directory on a node and restricts its availability to that node:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: fast-local-pv
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /mnt/nvme-disk
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node-worker-01

Critical Implementation Detail

When you bind this PV to a PersistentVolumeClaim (PVC), the Kubernetes scheduler becomes aware of the strict affinity rule. Even if your pod is part of a StatefulSet, the scheduler is forced to place the pod on node-worker-01 to access the disk at /mnt/nvme-disk.

Because local PVs are tied to the node's physical lifecycle, they are not automatically replicated or moved. This makes them ideal for distributed applications (like Cassandra or Elasticsearch) that handle data replication at the software layer, allowing you to achieve maximum disk throughput without the tax of network-attached storage.

Key Takeaway: By combining Local Persistent Volumes with strict Node Affinity rules, you eliminate network I/O bottlenecks and provide your stateful workloads with direct, high-speed access to physical node storage.