Mount Local Volume With Kubernetes

Kubernetes local volume is a feature that allows you to create and attach storage devices to your clusters nodes. You can use local volumes to store data, applications, or configuration files.

When you create a local volume, Kubernetes creates a Persistent Volume Claim (PVC) and uses it to provide a storage device on one of the cluster nodes. You can then access the storage device from any node in the cluster.

Volumes

Kubernetes Volumes are used to store persistent data in a Kubernetes cluster, and as of writing these lines, Kubernetes offer many types of volumes connected to a cluster. They range from Azure file share, AWS storage and, in our case, local volumes.

In the example below, we are creating a volume mount in our cluster that creates a storage volume directory on the actual Kubernetes node.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-pv
spec:
  capacity:
    storage: 1Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: local-storage
  local:
    path: "/volumes/myvol01"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - my-node

To apply the configuration, I will run the following command.

kubectl apply -f local-volume.yaml

To get more information about the volume, use this command.

kubectl describe pv local-pv

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.