Kubernetes
persistent volume
local storage
container orchestration
data management

Kubernetes - use local hard drive as persistent volume

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Kubernetes and Persistent Volumes on Local Hard Drive

Kubernetes, often abbreviated as K8s, is an open-source platform for managing containerized applications across a cluster of machines. It provides tools for deploying applications, scaling them automatically, and managing their lifecycle. One of the essential concepts in Kubernetes is storage management, crucial for applications needing persistent storage across pod restarts. A common storage solution is using the local hard drive as a Persistent Volume (PV).

Understanding Persistent Volumes in Kubernetes

Persistent Volumes in Kubernetes are storage units managed by the Kubernetes API, independent of the individual pod lifecycle. They provide a way to abstract the physical storage layer, allowing applications to decouple from the infrastructure.

Key Concepts

  1. Persistent Volume (PV): A piece of storage in the cluster provisioned by an administrator or dynamically using Storage Classes.
  2. Persistent Volume Claim (PVC): A request for storage by a user that automatically binds to a PV based on certain criteria like size and access modes.
  3. Storage Class: Defines different classes of storage, which can be dynamically provisioned.

Using Local Hard Drive as Persistent Volume

Local persistent volumes offer high-performance storage for pods running on the same node. While they provide excellent performance due to proximity and lack of network latency, they come with limitations like no redundancy and node-affinity constraints.

Setting Up Local Persistent Volumes

  1. Prepare the Local Storage: Ensure that your node has the necessary directories set up with the appropriate permissions. For Linux, you can achieve this using the following:
    • ReadWriteOnce
      • matchExpressions:
        • key: kubernetes.io/hostname
          • `<node-name>`
    • ReadWriteOnce
    • name: test-container
      • mountPath: "/usr/share/nginx/html"
    • name: local-storage
  • Performance: Local PVs provide high performance due to reduced network latency.
  • Cost-Effective: Utilizes existing hardware, eliminating additional infrastructure costs.
  • Node Failure: If a node fails, the local PV becomes unavailable since it is node-specific.
  • Management Complexity: Requires careful node and storage management for redundancy.
  • Dynamic Provisioning: Not natively supported; manual configuration needed.
  • Redundancy and Backups: Always maintain offsite backups to mitigate node failures.
  • Capacity Planning: Regularly monitor and adjust local storage based on application needs.
  • Compliance and Security: Ensure encryption and compliance with industry standards when handling sensitive data on local PVs.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.