Persistent Volumes

This document describes the current state of PersistentVolumes in Kubernetes. Familiarity with volumes is suggested.

Introduction

Managing storage is a distinct problem from managing compute instances. The PersistentVolume subsystem provides an API for users and administrators that abstracts details of how storage is provided from how it is consumed. To do this, we introduce two new API resources: PersistentVolume and PersistentVolumeClaim.

A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV. This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.

A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., they can be mounted once read/write or many times read-only).

While PersistentVolumeClaims allow a user to consume abstract storageresources, it is common that users need PersistentVolumes with varyingproperties, such as performance, for different problems. Cluster administratorsneed to be able to offer a variety of PersistentVolumes that differ in moreways than just size and access modes, without exposing users to the details ofhow those volumes are implemented. For these needs, there is the StorageClassresource.

See the detailed walkthrough with working examples.

Lifecycle of a volume and claim

PVs are resources in the cluster. PVCs are requests for those resources and also act as claim checks to the resource. The interaction between PVs and PVCs follows this lifecycle:

Provisioning

There are two ways PVs may be provisioned: statically or dynamically.

Static

A cluster administrator creates a number of PVs. They carry the details of the real storage, which is available for use by cluster users. They exist in the Kubernetes API and are available for consumption.

Dynamic

When none of the static PVs the administrator created match a user’s PersistentVolumeClaim,the cluster may try to dynamically provision a volume specially for the PVC.This provisioning is based on StorageClasses: the PVC must request astorage class andthe administrator must have created and configured that class for dynamicprovisioning to occur. Claims that request the class "" effectively disabledynamic provisioning for themselves.

To enable dynamic storage provisioning based on storage class, the cluster administratorneeds to enable the DefaultStorageClass admission controlleron the API server. This can be done, for example, by ensuring that DefaultStorageClass isamong the comma-delimited, ordered list of values for the —enable-admission-plugins flag ofthe API server component. For more information on API server command-line flags,check kube-apiserver documentation.

Binding

A user creates, or in the case of dynamic provisioning, has already created, a PersistentVolumeClaim with a specific amount of storage requested and with certain access modes. A control loop in the master watches for new PVCs, finds a matching PV (if possible), and binds them together. If a PV was dynamically provisioned for a new PVC, the loop will always bind that PV to the PVC. Otherwise, the user will always get at least what they asked for, but the volume may be in excess of what was requested. Once bound, PersistentVolumeClaim binds are exclusive, regardless of how they were bound. A PVC to PV binding is a one-to-one mapping.

Claims will remain unbound indefinitely if a matching volume does not exist. Claims will be bound as matching volumes become available. For example, a cluster provisioned with many 50Gi PVs would not match a PVC requesting 100Gi. The PVC can be bound when a 100Gi PV is added to the cluster.

Using

Pods use claims as volumes. The cluster inspects the claim to find the bound volume and mounts that volume for a Pod. For volumes that support multiple access modes, the user specifies which mode is desired when using their claim as a volume in a Pod.

Once a user has a claim and that claim is bound, the bound PV belongs to the user for as long as they need it. Users schedule Pods and access their claimed PVs by including a persistentVolumeClaim in their Pod’s volumes block. See below for syntax details.

Storage Object in Use Protection

The purpose of the Storage Object in Use Protection feature is to ensure that Persistent Volume Claims (PVCs) in active use by a Pod and Persistent Volume (PVs) that are bound to PVCs are not removed from the system, as this may result in data loss.

Note: PVC is in active use by a Pod when a Pod object exists that is using the PVC.

If a user deletes a PVC in active use by a Pod, the PVC is not removed immediately. PVC removal is postponed until the PVC is no longer actively used by any Pods. Also, if an admin deletes a PV that is bound to a PVC, the PV is not removed immediately. PV removal is postponed until the PV is no longer bound to a PVC.

You can see that a PVC is protected when the PVC’s status is Terminating and the Finalizers list includes kubernetes.io/pvc-protection:

  1. kubectl describe pvc hostpath
  2. Name: hostpath
  3. Namespace: default
  4. StorageClass: example-hostpath
  5. Status: Terminating
  6. Volume:
  7. Labels: <none>
  8. Annotations: volume.beta.kubernetes.io/storage-class=example-hostpath
  9. volume.beta.kubernetes.io/storage-provisioner=example.com/hostpath
  10. Finalizers: [kubernetes.io/pvc-protection]
  11. ...

You can see that a PV is protected when the PV’s status is Terminating and the Finalizers list includes kubernetes.io/pv-protection too:

  1. kubectl describe pv task-pv-volume
  2. Name: task-pv-volume
  3. Labels: type=local
  4. Annotations: <none>
  5. Finalizers: [kubernetes.io/pv-protection]
  6. StorageClass: standard
  7. Status: Available
  8. Claim:
  9. Reclaim Policy: Delete
  10. Access Modes: RWO
  11. Capacity: 1Gi
  12. Message:
  13. Source:
  14. Type: HostPath (bare host directory volume)
  15. Path: /tmp/data
  16. HostPathType:
  17. Events: <none>

Reclaiming

When a user is done with their volume, they can delete the PVC objects from the API that allows reclamation of the resource. The reclaim policy for a PersistentVolume tells the cluster what to do with the volume after it has been released of its claim. Currently, volumes can either be Retained, Recycled, or Deleted.

Retain

The Retain reclaim policy allows for manual reclamation of the resource. When the PersistentVolumeClaim is deleted, the PersistentVolume still exists and the volume is considered “released”. But it is not yet available for another claim because the previous claimant’s data remains on the volume. An administrator can manually reclaim the volume with the following steps.

  • Delete the PersistentVolume. The associated storage asset in external infrastructure (such as an AWS EBS, GCE PD, Azure Disk, or Cinder volume) still exists after the PV is deleted.
  • Manually clean up the data on the associated storage asset accordingly.
  • Manually delete the associated storage asset, or if you want to reuse the same storage asset, create a new PersistentVolume with the storage asset definition.

Delete

For volume plugins that support the Delete reclaim policy, deletion removes both the PersistentVolume object from Kubernetes, as well as the associated storage asset in the external infrastructure, such as an AWS EBS, GCE PD, Azure Disk, or Cinder volume. Volumes that were dynamically provisioned inherit the reclaim policy of their StorageClass, which defaults to Delete. The administrator should configure the StorageClass according to users’ expectations; otherwise, the PV must be edited or patched after it is created. See Change the Reclaim Policy of a PersistentVolume.

Recycle

Warning: The Recycle reclaim policy is deprecated. Instead, the recommended approach is to use dynamic provisioning.

If supported by the underlying volume plugin, the Recycle reclaim policy performs a basic scrub (rm -rf /thevolume/*) on the volume and makes it available again for a new claim.

However, an administrator can configure a custom recycler Pod template using the Kubernetes controller manager command line arguments as described here. The custom recycler Pod template must contain a volumes specification, as shown in the example below:

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: pv-recycler
  5. namespace: default
  6. spec:
  7. restartPolicy: Never
  8. volumes:
  9. - name: vol
  10. hostPath:
  11. path: /any/path/it/will/be/replaced
  12. containers:
  13. - name: pv-recycler
  14. image: "k8s.gcr.io/busybox"
  15. command: ["/bin/sh", "-c", "test -e /scrub && rm -rf /scrub/..?* /scrub/.[!.]* /scrub/* && test -z \"$(ls -A /scrub)\" || exit 1"]
  16. volumeMounts:
  17. - name: vol
  18. mountPath: /scrub

However, the particular path specified in the custom recycler Pod template in the volumes part is replaced with the particular path of the volume that is being recycled.

Expanding Persistent Volumes Claims

FEATURE STATE: Kubernetes v1.11betaThis feature is currently in a beta state, meaning:

  • The version names contain beta (e.g. v2beta3).
  • Code is well tested. Enabling the feature is considered safe. Enabled by default.
  • Support for the overall feature will not be dropped, though details may change.
  • The schema and/or semantics of objects may change in incompatible ways in a subsequent beta or stable release. When this happens, we will provide instructions for migrating to the next version. This may require deleting, editing, and re-creating API objects. The editing process may require some thought. This may require downtime for applications that rely on the feature.
  • Recommended for only non-business-critical uses because of potential for incompatible changes in subsequent releases. If you have multiple clusters that can be upgraded independently, you may be able to relax this restriction.
  • Please do try our beta features and give feedback on them! After they exit beta, it may not be practical for us to make more changes.

Support for expanding PersistentVolumeClaims (PVCs) is now enabled by default. You can expandthe following types of volumes:

  • gcePersistentDisk
  • awsElasticBlockStore
  • Cinder
  • glusterfs
  • rbd
  • Azure File
  • Azure Disk
  • Portworx
  • FlexVolumes
  • CSI

You can only expand a PVC if its storage class’s allowVolumeExpansion field is set to true.

  1. apiVersion: storage.k8s.io/v1
  2. kind: StorageClass
  3. metadata:
  4. name: gluster-vol-default
  5. provisioner: kubernetes.io/glusterfs
  6. parameters:
  7. resturl: "http://192.168.10.100:8080"
  8. restuser: ""
  9. secretNamespace: ""
  10. secretName: ""
  11. allowVolumeExpansion: true

To request a larger volume for a PVC, edit the PVC object and specify a largersize. This triggers expansion of the volume that backs the underlying PersistentVolume. Anew PersistentVolume is never created to satisfy the claim. Instead, an existing volume is resized.

CSI Volume expansion

FEATURE STATE: Kubernetes v1.16betaThis feature is currently in a beta state, meaning:

  • The version names contain beta (e.g. v2beta3).
  • Code is well tested. Enabling the feature is considered safe. Enabled by default.
  • Support for the overall feature will not be dropped, though details may change.
  • The schema and/or semantics of objects may change in incompatible ways in a subsequent beta or stable release. When this happens, we will provide instructions for migrating to the next version. This may require deleting, editing, and re-creating API objects. The editing process may require some thought. This may require downtime for applications that rely on the feature.
  • Recommended for only non-business-critical uses because of potential for incompatible changes in subsequent releases. If you have multiple clusters that can be upgraded independently, you may be able to relax this restriction.
  • Please do try our beta features and give feedback on them! After they exit beta, it may not be practical for us to make more changes.

Support for expanding CSI volumes is enabled by default but it also requires a specific CSI driver to support volume expansion. Refer to documentation of the specific CSI driver for more information.

Resizing a volume containing a file system

You can only resize volumes containing a file system if the file system is XFS, Ext3, or Ext4.

When a volume contains a file system, the file system is only resized when a new Pod is usingthe PersistentVolumeClaim in ReadWrite mode. File system expansion is either done when a Pod is starting upor when a Pod is running and the underlying file system supports online expansion.

FlexVolumes allow resize if the driver is set with the RequiresFSResize capability to true.The FlexVolume can be resized on Pod restart.

Resizing an in-use PersistentVolumeClaim

FEATURE STATE: Kubernetes v1.15betaThis feature is currently in a beta state, meaning:

  • The version names contain beta (e.g. v2beta3).
  • Code is well tested. Enabling the feature is considered safe. Enabled by default.
  • Support for the overall feature will not be dropped, though details may change.
  • The schema and/or semantics of objects may change in incompatible ways in a subsequent beta or stable release. When this happens, we will provide instructions for migrating to the next version. This may require deleting, editing, and re-creating API objects. The editing process may require some thought. This may require downtime for applications that rely on the feature.
  • Recommended for only non-business-critical uses because of potential for incompatible changes in subsequent releases. If you have multiple clusters that can be upgraded independently, you may be able to relax this restriction.
  • Please do try our beta features and give feedback on them! After they exit beta, it may not be practical for us to make more changes.
Note: Expanding in-use PVCs is available as beta since Kubernetes 1.15, and as alpha since 1.11. The ExpandInUsePersistentVolumes feature must be enabled, which is the case automatically for many clusters for beta features. Refer to the feature gate documentation for more information.

In this case, you don’t need to delete and recreate a Pod or deployment that is using an existing PVC.Any in-use PVC automatically becomes available to its Pod as soon as its file system has been expanded.This feature has no effect on PVCs that are not in use by a Pod or deployment. You must create a Pod thatuses the PVC before the expansion can complete.

Similar to other volume types - FlexVolume volumes can also be expanded when in-use by a Pod.

Note: FlexVolume resize is possible only when the underlying driver supports resize.
Note: Expanding EBS volumes is a time-consuming operation. Also, there is a per-volume quota of one modification every 6 hours.

Types of Persistent Volumes

PersistentVolume types are implemented as plugins. Kubernetes currently supports the following plugins:

  • GCEPersistentDisk
  • AWSElasticBlockStore
  • AzureFile
  • AzureDisk
  • CSI
  • FC (Fibre Channel)
  • FlexVolume
  • Flocker
  • NFS
  • iSCSI
  • RBD (Ceph Block Device)
  • CephFS
  • Cinder (OpenStack block storage)
  • Glusterfs
  • VsphereVolume
  • Quobyte Volumes
  • HostPath (Single node testing only – local storage is not supported in any way and WILL NOT WORK in a multi-node cluster)
  • Portworx Volumes
  • ScaleIO Volumes
  • StorageOS

Persistent Volumes

Each PV contains a spec and status, which is the specification and status of the volume.

  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: pv0003
  5. spec:
  6. capacity:
  7. storage: 5Gi
  8. volumeMode: Filesystem
  9. accessModes:
  10. - ReadWriteOnce
  11. persistentVolumeReclaimPolicy: Recycle
  12. storageClassName: slow
  13. mountOptions:
  14. - hard
  15. - nfsvers=4.1
  16. nfs:
  17. path: /tmp
  18. server: 172.17.0.2

Capacity

Generally, a PV will have a specific storage capacity. This is set using the PV’s capacity attribute. See the Kubernetes Resource Model to understand the units expected by capacity.

Currently, storage size is the only resource that can be set or requested. Future attributes may include IOPS, throughput, etc.

Volume Mode

FEATURE STATE: Kubernetes v1.13betaThis feature is currently in a beta state, meaning:

  • The version names contain beta (e.g. v2beta3).
  • Code is well tested. Enabling the feature is considered safe. Enabled by default.
  • Support for the overall feature will not be dropped, though details may change.
  • The schema and/or semantics of objects may change in incompatible ways in a subsequent beta or stable release. When this happens, we will provide instructions for migrating to the next version. This may require deleting, editing, and re-creating API objects. The editing process may require some thought. This may require downtime for applications that rely on the feature.
  • Recommended for only non-business-critical uses because of potential for incompatible changes in subsequent releases. If you have multiple clusters that can be upgraded independently, you may be able to relax this restriction.
  • Please do try our beta features and give feedback on them! After they exit beta, it may not be practical for us to make more changes.

Prior to Kubernetes 1.9, all volume plugins created a filesystem on the persistent volume.Now, you can set the value of volumeMode to block to use a raw block device, or filesystemto use a filesystem. filesystem is the default if the value is omitted. This is an optional APIparameter.

Access Modes

A PersistentVolume can be mounted on a host in any way supported by the resource provider. As shown in the table below, providers will have different capabilities and each PV’s access modes are set to the specific modes supported by that particular volume. For example, NFS can support multiple read/write clients, but a specific NFS PV might be exported on the server as read-only. Each PV gets its own set of access modes describing that specific PV’s capabilities.

The access modes are:

  • ReadWriteOnce – the volume can be mounted as read-write by a single node
  • ReadOnlyMany – the volume can be mounted read-only by many nodes
  • ReadWriteMany – the volume can be mounted as read-write by many nodes

In the CLI, the access modes are abbreviated to:

  • RWO - ReadWriteOnce
  • ROX - ReadOnlyMany
  • RWX - ReadWriteMany

Important! A volume can only be mounted using one access mode at a time, even if it supports many. For example, a GCEPersistentDisk can be mounted as ReadWriteOnce by a single node or ReadOnlyMany by many nodes, but not at the same time.

Volume PluginReadWriteOnceReadOnlyManyReadWriteMany
AWSElasticBlockStore--
AzureFile
AzureDisk--
CephFS
Cinder--
CSIdepends on the driverdepends on the driverdepends on the driver
FC-
FlexVolumedepends on the driver
Flocker--
GCEPersistentDisk-
Glusterfs
HostPath--
iSCSI-
Quobyte
NFS
RBD-
VsphereVolume-- (works when Pods are collocated)
PortworxVolume-
ScaleIO-
StorageOS--

Class

A PV can have a class, which is specified by setting thestorageClassName attribute to the name of aStorageClass.A PV of a particular class can only be bound to PVCs requestingthat class. A PV with no storageClassName has no class and can only be boundto PVCs that request no particular class.

In the past, the annotation volume.beta.kubernetes.io/storage-class was used insteadof the storageClassName attribute. This annotation is still working; however,it will become fully deprecated in a future Kubernetes release.

Reclaim Policy

Current reclaim policies are:

  • Retain – manual reclamation
  • Recycle – basic scrub (rm -rf /thevolume/*)
  • Delete – associated storage asset such as AWS EBS, GCE PD, Azure Disk, or OpenStack Cinder volume is deleted

Currently, only NFS and HostPath support recycling. AWS EBS, GCE PD, Azure Disk, and Cinder volumes support deletion.

Mount Options

A Kubernetes administrator can specify additional mount options for when a Persistent Volume is mounted on a node.

Note: Not all Persistent Volume types support mount options.

The following volume types support mount options:

  • AWSElasticBlockStore
  • AzureDisk
  • AzureFile
  • CephFS
  • Cinder (OpenStack block storage)
  • GCEPersistentDisk
  • Glusterfs
  • NFS
  • Quobyte Volumes
  • RBD (Ceph Block Device)
  • StorageOS
  • VsphereVolume
  • iSCSI

Mount options are not validated, so mount will simply fail if one is invalid.

In the past, the annotation volume.beta.kubernetes.io/mount-options was used insteadof the mountOptions attribute. This annotation is still working; however,it will become fully deprecated in a future Kubernetes release.

Node Affinity

Note: For most volume types, you do not need to set this field. It is automatically populated for AWS EBS, GCE PD and Azure Disk volume block types. You need to explicitly set this for local volumes.

A PV can specify node affinity to define constraints that limit what nodes this volume can be accessed from. Pods that use a PV will only be scheduled to nodes that are selected by the node affinity.

Phase

A volume will be in one of the following phases:

  • Available – a free resource that is not yet bound to a claim
  • Bound – the volume is bound to a claim
  • Released – the claim has been deleted, but the resource is not yet reclaimed by the cluster
  • Failed – the volume has failed its automatic reclamation

The CLI will show the name of the PVC bound to the PV.

PersistentVolumeClaims

Each PVC contains a spec and status, which is the specification and status of the claim.

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. name: myclaim
  5. spec:
  6. accessModes:
  7. - ReadWriteOnce
  8. volumeMode: Filesystem
  9. resources:
  10. requests:
  11. storage: 8Gi
  12. storageClassName: slow
  13. selector:
  14. matchLabels:
  15. release: "stable"
  16. matchExpressions:
  17. - {key: environment, operator: In, values: [dev]}

Access Modes

Claims use the same conventions as volumes when requesting storage with specific access modes.

Volume Modes

Claims use the same convention as volumes to indicate the consumption of the volume as either a filesystem or block device.

Resources

Claims, like Pods, can request specific quantities of a resource. In this case, the request is for storage. The same resource model applies to both volumes and claims.

Selector

Claims can specify a label selector to further filter the set of volumes. Only the volumes whose labels match the selector can be bound to the claim. The selector can consist of two fields:

  • matchLabels - the volume must have a label with this value
  • matchExpressions - a list of requirements made by specifying key, list of values, and operator that relates the key and values. Valid operators include In, NotIn, Exists, and DoesNotExist.

All of the requirements, from both matchLabels and matchExpressions, are ANDed together – they must all be satisfied in order to match.

Class

A claim can request a particular class by specifying the name of aStorageClassusing the attribute storageClassName.Only PVs of the requested class, ones with the same storageClassName as the PVC, canbe bound to the PVC.

PVCs don’t necessarily have to request a class. A PVC with its storageClassName setequal to "" is always interpreted to be requesting a PV with no class, so itcan only be bound to PVs with no class (no annotation or one set equal to""). A PVC with no storageClassName is not quite the same and is treated differentlyby the cluster, depending on whether theDefaultStorageClass admission pluginis turned on.

  • If the admission plugin is turned on, the administrator may specify adefault StorageClass. All PVCs that have no storageClassName can be bound only toPVs of that default. Specifying a default StorageClass is done by setting theannotation storageclass.kubernetes.io/is-default-class equal to true ina StorageClass object. If the administrator does not specify a default, thecluster responds to PVC creation as if the admission plugin were turned off. Ifmore than one default is specified, the admission plugin forbids the creation ofall PVCs.
  • If the admission plugin is turned off, there is no notion of a defaultStorageClass. All PVCs that have no storageClassName can be bound only to PVs thathave no class. In this case, the PVCs that have no storageClassName are treated thesame way as PVCs that have their storageClassName set to "".

Depending on installation method, a default StorageClass may be deployedto a Kubernetes cluster by addon manager during installation.

When a PVC specifies a selector in addition to requesting a StorageClass,the requirements are ANDed together: only a PV of the requested class and withthe requested labels may be bound to the PVC.

Note: Currently, a PVC with a non-empty selector can’t have a PV dynamically provisioned for it.

In the past, the annotation volume.beta.kubernetes.io/storage-class was used insteadof storageClassName attribute. This annotation is still working; however,it won’t be supported in a future Kubernetes release.

Claims As Volumes

Pods access storage by using the claim as a volume. Claims must exist in the same namespace as the Pod using the claim. The cluster finds the claim in the Pod’s namespace and uses it to get the PersistentVolume backing the claim. The volume is then mounted to the host and into the Pod.

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: mypod
  5. spec:
  6. containers:
  7. - name: myfrontend
  8. image: nginx
  9. volumeMounts:
  10. - mountPath: "/var/www/html"
  11. name: mypd
  12. volumes:
  13. - name: mypd
  14. persistentVolumeClaim:
  15. claimName: myclaim

A Note on Namespaces

PersistentVolumes binds are exclusive, and since PersistentVolumeClaims are namespaced objects, mounting claims with “Many” modes (ROX, RWX) is only possible within one namespace.

Raw Block Volume Support

FEATURE STATE: Kubernetes v1.13betaThis feature is currently in a beta state, meaning:

  • The version names contain beta (e.g. v2beta3).
  • Code is well tested. Enabling the feature is considered safe. Enabled by default.
  • Support for the overall feature will not be dropped, though details may change.
  • The schema and/or semantics of objects may change in incompatible ways in a subsequent beta or stable release. When this happens, we will provide instructions for migrating to the next version. This may require deleting, editing, and re-creating API objects. The editing process may require some thought. This may require downtime for applications that rely on the feature.
  • Recommended for only non-business-critical uses because of potential for incompatible changes in subsequent releases. If you have multiple clusters that can be upgraded independently, you may be able to relax this restriction.
  • Please do try our beta features and give feedback on them! After they exit beta, it may not be practical for us to make more changes.

The following volume plugins support raw block volumes, including dynamic provisioning whereapplicable:

  • AWSElasticBlockStore
  • AzureDisk
  • FC (Fibre Channel)
  • GCEPersistentDisk
  • iSCSI
  • Local volume
  • RBD (Ceph Block Device)
  • VsphereVolume (alpha)
Note: Only FC and iSCSI volumes supported raw block volumes in Kubernetes 1.9.Support for the additional plugins was added in 1.10.

Persistent Volumes using a Raw Block Volume

  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: block-pv
  5. spec:
  6. capacity:
  7. storage: 10Gi
  8. accessModes:
  9. - ReadWriteOnce
  10. volumeMode: Block
  11. persistentVolumeReclaimPolicy: Retain
  12. fc:
  13. targetWWNs: ["50060e801049cfd1"]
  14. lun: 0
  15. readOnly: false

Persistent Volume Claim requesting a Raw Block Volume

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. name: block-pvc
  5. spec:
  6. accessModes:
  7. - ReadWriteOnce
  8. volumeMode: Block
  9. resources:
  10. requests:
  11. storage: 10Gi

Pod specification adding Raw Block Device path in container

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: pod-with-block-volume
  5. spec:
  6. containers:
  7. - name: fc-container
  8. image: fedora:26
  9. command: ["/bin/sh", "-c"]
  10. args: [ "tail -f /dev/null" ]
  11. volumeDevices:
  12. - name: data
  13. devicePath: /dev/xvda
  14. volumes:
  15. - name: data
  16. persistentVolumeClaim:
  17. claimName: block-pvc
Note: When adding a raw block device for a Pod, you specify the device path in the container instead of a mount path.

Binding Block Volumes

If a user requests a raw block volume by indicating this using the volumeMode field in the PersistentVolumeClaim spec, the binding rules differ slightly from previous releases that didn’t consider this mode as part of the spec.Listed is a table of possible combinations the user and admin might specify for requesting a raw block device. The table indicates if the volume will be bound or not given the combinations:Volume binding matrix for statically provisioned volumes:

PV volumeModePVC volumeModeResult
unspecifiedunspecifiedBIND
unspecifiedBlockNO BIND
unspecifiedFilesystemBIND
BlockunspecifiedNO BIND
BlockBlockBIND
BlockFilesystemNO BIND
FilesystemFilesystemBIND
FilesystemBlockNO BIND
FilesystemunspecifiedBIND
Note: Only statically provisioned volumes are supported for alpha release. Administrators should take care to consider these values when working with raw block devices.

Volume Snapshot and Restore Volume from Snapshot Support

FEATURE STATE: Kubernetes v1.12alphaThis feature is currently in a alpha state, meaning:

  • The version names contain alpha (e.g. v1alpha1).
  • Might be buggy. Enabling the feature may expose bugs. Disabled by default.
  • Support for feature may be dropped at any time without notice.
  • The API may change in incompatible ways in a later software release without notice.
  • Recommended for use only in short-lived testing clusters, due to increased risk of bugs and lack of long-term support.

Volume snapshot feature was added to support CSI Volume Plugins only. For details, see volume snapshots.

To enable support for restoring a volume from a volume snapshot data source, enable theVolumeSnapshotDataSource feature gate on the apiserver and controller-manager.

Create Persistent Volume Claim from Volume Snapshot

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. name: restore-pvc
  5. spec:
  6. storageClassName: csi-hostpath-sc
  7. dataSource:
  8. name: new-snapshot-test
  9. kind: VolumeSnapshot
  10. apiGroup: snapshot.storage.k8s.io
  11. accessModes:
  12. - ReadWriteOnce
  13. resources:
  14. requests:
  15. storage: 10Gi

Volume Cloning

FEATURE STATE: Kubernetes v1.16betaThis feature is currently in a beta state, meaning:

  • The version names contain beta (e.g. v2beta3).
  • Code is well tested. Enabling the feature is considered safe. Enabled by default.
  • Support for the overall feature will not be dropped, though details may change.
  • The schema and/or semantics of objects may change in incompatible ways in a subsequent beta or stable release. When this happens, we will provide instructions for migrating to the next version. This may require deleting, editing, and re-creating API objects. The editing process may require some thought. This may require downtime for applications that rely on the feature.
  • Recommended for only non-business-critical uses because of potential for incompatible changes in subsequent releases. If you have multiple clusters that can be upgraded independently, you may be able to relax this restriction.
  • Please do try our beta features and give feedback on them! After they exit beta, it may not be practical for us to make more changes.

Volume clone feature was added to support CSI Volume Plugins only. For details, see volume cloning.

To enable support for cloning a volume from a PVC data source, enable theVolumePVCDataSource feature gate on the apiserver and controller-manager.

Create Persistent Volume Claim from an existing pvc

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. name: cloned-pvc
  5. spec:
  6. storageClassName: my-csi-plugin
  7. dataSource:
  8. name: existing-src-pvc-name
  9. kind: PersistentVolumeClaim
  10. accessModes:
  11. - ReadWriteOnce
  12. resources:
  13. requests:
  14. storage: 10Gi

Writing Portable Configuration

If you’re writing configuration templates or examples that run on a wide range of clustersand need persistent storage, it is recommended that you use the following pattern:

  • Include PersistentVolumeClaim objects in your bundle of config (alongsideDeployments, ConfigMaps, etc).
  • Do not include PersistentVolume objects in the config, since the user instantiatingthe config may not have permission to create PersistentVolumes.
  • Give the user the option of providing a storage class name when instantiatingthe template.
    • If the user provides a storage class name, put that value into thepersistentVolumeClaim.storageClassName field.This will cause the PVC to match the right storageclass if the cluster has StorageClasses enabled by the admin.
    • If the user does not provide a storage class name, leave thepersistentVolumeClaim.storageClassName field as nil. This will cause aPV to be automatically provisioned for the user with the default StorageClassin the cluster. Many cluster environments have a default StorageClass installed,or administrators can create their own default StorageClass.
  • In your tooling, watch for PVCs that are not getting bound after some timeand surface this to the user, as this may indicate that the cluster has nodynamic storage support (in which case the user should create a matching PV)or the cluster has no storage system (in which case the user cannot deployconfig requiring PVCs).

Feedback

Was this page helpful?

Thanks for the feedback. If you have a specific, answerable question about how to use Kubernetes, ask it onStack Overflow.Open an issue in the GitHub repo if you want toreport a problemorsuggest an improvement.