Create Longhorn Volumes

Before you create Kubernetes volumes, you must first create a storage class. Use following command to create a StorageClass called longhorn.

kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v0.8.0/examples/storageclass.yaml

Now you can create a pod using Longhorn like this:

kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v0.8.0/examples/pvc.yaml

The above yaml file contains two parts:

  1. Create a PVC using Longhorn StorageClass.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: longhorn-volv-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 2Gi
  1. Use it in the Pod as a persistent volume:
apiVersion: v1
kind: Pod
metadata:
  name: volume-test
  namespace: default
spec:
  containers:
  - name: volume-test
    image: nginx:stable-alpine
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: volv
      mountPath: /data
    ports:
    - containerPort: 80
  volumes:
  - name: volv
    persistentVolumeClaim:
      claimName: longhorn-volv-pvc

More examples are available at ../examples/


© 2019-2024 Longhorn Authors | Documentation Distributed under CC-BY-4.0


© 2024 The Linux Foundation. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.