This is a cache of https://docs.openshift.com/enterprise/3.0/admin_guide/persistent_storage_nfs.html. It is a snapshot of the page at 2024-11-26T04:43:08.085+0000.
P<strong>e</strong>rsist<strong>e</strong>nt Storag<strong>e</strong> Using NFS | Administration | Op<strong>e</strong>nShift <strong>e</strong>nt<strong>e</strong>rpris<strong>e</strong> 3.0
&times;

Overview

You can provision your OpenShift cluster with persistent storage using NFS. Some familiarity with Kubernetes and NFS is assumed.

The Kubernetes persistent volume framework allows administrators to provision a cluster with persistent storage and gives users a way to request those resources without having any knowledge of the underlying infrastructure.

For a detailed example, see the guide for WordPress and MySQL using NFS.

High-availability of storage in the infrastructure is left to the underlying storage provider.

Provisioning

Storage must exist in the underlying infrastructure before it can be mounted as a volume in OpenShift. All that is required for NFS is a distinct list of servers and paths and the PersistentVolume API.

example 1. Persistent Volume Object Definition
{
  "apiVersion": "v1",
  "kind": "PersistentVolume",
  "metadata": {
    "name": "pv0001"
  },
  "spec": {
    "capacity": {
        "storage": "5Gi"
    },
    "accessModes": [ "ReadWriteOnce" ],
    "nfs": {
        "path": "/tmp",
        "server": "172.17.0.2"
    },
    "persistentVolumeReclaimPolicy": "Recycle"
  }
}

enforcing Disk Quotas

Use disk partitions to enforce disk quotas and size constraints. each partition can be its own export. each export is one persistent volume. Kubernetes enforces unique names for persistent volumes, but the uniqueness of the NFS volume’s server and path is up to the administrator.

enforcing quotas in this way allows the end user to request persistent storage by a specific amount (e.g, 10Gi) and be matched with a corresponding volume of equal or greater capacity.

Volume Security

Users request storage with a PersistentVolumeClaim. This claim only lives in the user’s namespace and can only be referenced by a pod within that same namespace. Any attempt to access a persistent volume across a namespace causes the pod to fail.

each NFS volume must be mountable by all nodes in the cluster.

Reclaiming Resources

NFS implements the Kubernetes Recyclable plug-in interface. Automatic processes handle reclamation tasks based on policies set on each persistent volume.

By default, persistent volumes are set to Retain. NFS volumes which are set to Recycle are scrubbed (i.e., rm -rf is run on the volume) after being released from their claim (i.e, after the user’s PersistentVolumeClaim bound to the volume is deleted). Once recycled, the NFS volume can be bound to a new claim.

Automation

As discussed, clusters can be provisioned with persistent storage using NFS in the following way:

They are many ways that you can use scripts to automate the above tasks. You can use an example Ansible playbook to help you get started.

SeLinux and NFS export Settings

By default, SeLinux does not allow writing from a pod to a remote NFS server. The NFS volume mounts correctly, but is read-only.

To enable writing in SeLinux on each node:

# setsebool -P virt_use_nfs 1

The -P option makes the bool persistent between reboots.

Additionally, in order to enable arbitrary container users to read and write the volume, each exported volume on the NFS server itself should conform to the following:

  • each export must be:

/<example_fs> *(rw,all_squash)
  • each export must be owned by nfsnobody:

chown -R nfsnobody:nfsnobody /<example_fs>
  • each export must have the following permissions:

chmod 777 /<example_fs>

The export definition above allows arbitrary network clients to mount this volume. exports can be restricted to a range of IP addresses for hosts that will access the volume. See man exports for more information.

Starting in OpenShift enterprise 3.1, the export values have changed. See the OpenShift enterprise 3.1 documentation for instructions on ensuring proper security for NFS in 3.1.