OpenShift PersistentVolume Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(32 intermediate revisions by the same user not shown)
Line 7: Line 7:
* [[OpenShift_Operations#Subjects|OpenShift Operations]]
* [[OpenShift_Operations#Subjects|OpenShift Operations]]


=List Existent Volumes=
=Overview=
 
=Persistent Volume Operations=
 
==List Existent Persistent Volumes==


A persistent volume is not a project-specific object, so the following query will return all persistent volumes available to the OpenShift instance.
A persistent volume is not a project-specific object, so the following query will return all persistent volumes available to the OpenShift instance.
Line 13: Line 17:
  oc get pv
  oc get pv


=Delete a Persistent Volume=
==Details about a Specific Persistent Volume==
 
oc describe pv <''persistent-volume-name''>
 
==Delete an Unbound Persistent Volume==


  oc delete pv <''persistent-volume-name''>
  oc delete pv <''persistent-volume-name''>


oc delete pv metrics-volume
==Delete a Bound Persistent Volume==


=Create a Persistent Volume=
{{Warn|This is dangerous, do it only if you know what you're doing.}}


==NFS==
Delete the persistent volume claim first:
 
oc delete pvc <''pvc-name''>
 
The volume becomes "Released".
 
Then disassociate the persistent volume from the persistent volume claim reference, still attached to the volume.
 
This can be done interactively with [[oc edit]] - delete the "claimRef" structure, or with [[oc patch]]:
 
oc patch pv/<''persistent-volume-name''> --patch='{ "spec": { "claimRef": null}}'
 
==Create a NFS Persistent Volume==
<span id='Create_a_Persistent_Volume'></span>


===Provision the Underlying Storage===
===Provision the Underlying Storage===
Provisioning the underlying storage consists in exporting a NFS volume. On the support node:
1. Create a /etc/exports.d/persistent-volumes.exports file, if it does not exist already
2. Add entries similar to:
/nfs/pv1 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)
/nfs/pv2 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)
/nfs/pv3 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)
/nfs/pv4 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)
adjusting for local IP and network mask.
3. Create the corresponding local directories.
mkdir pv1 pv2 pv3 pv4
chown nfsnobody:nfsnobody pv1 pv2 pv3 pv4
chmod a+rwx pv*
3. Export new filesystems:
exportfs -av


===Create the Persistent Volume Definition File===
===Create the Persistent Volume Definition File===
Line 33: Line 77:
kind: PersistentVolume
kind: PersistentVolume
metadata:
metadata:
   name: metrics-volume
   name: pv1
spec:
spec:
   capacity:
   capacity:
Line 41: Line 85:
   persistentVolumeReclaimPolicy: Retain
   persistentVolumeReclaimPolicy: Retain
   nfs:
   nfs:
     path: /support-nfs-storage/metrics
     path: /nfs/pv1
     server: support.local
     server: support.ocp36.local
</pre>
</pre>


Make sure the "support.local" server is accessible from any node that will use the volume, and the /support-nfs-storage/metrics is exported and has sufficient permissions.
Make sure the "support.ocp36.local" server is accessible from any node that will use the volume, and the /nfs/pv1 is exported and has sufficient permissions.
 
Repeat  for all persistent volumes, updating "name", "storage" and "path" accordingly.


===Create the Volume===
===Create the Volume===
Line 62: Line 108:
Note that the volume, even if available, it won't be used until a matching [[OpenShift_Concepts#Persistent_Volume_Claim|persistent volume claim]] is declared.
Note that the volume, even if available, it won't be used until a matching [[OpenShift_Concepts#Persistent_Volume_Claim|persistent volume claim]] is declared.


=List Existent Persistent Volume Claims for the Current Project=
===Use a Template===
 
Alternatively, use this template: https://github.com/NovaOrdis/playground/blob/master/openshift/pv-template.yaml and run it as such:
 
oc process -f ./pv-template.yaml --param NAME=pv9 --param SIZE_GB=2 | oc create -f -
 
=Recycle a "Released" Persistent Volume=
 
See {{Internal|OpenShift_PersistentVolume_Operations#Unbind_a_Pod_from_the_Volume|Unbind a Pod from the Volume}} below.
 
=Persistent Volume Claim Operations=
 
==List Existent Persistent Volume Claims for the Current Project==


A persistent volume claim is project-specific object, so the following query will return all persistent volume claims available in the current project:
A persistent volume claim is project-specific object, so the following query will return all persistent volume claims available in the current project:
Line 68: Line 126:
  oc get pvc
  oc get pvc


=Create a Persistent Volume Claim=
==Create a Persistent Volume Claim==


Create a definition of the [[OpenShift_Concepts#Persistent_Volume_Claim|persistent volume claim]], a "pvc.yaml" file with the following content
Create a definition of the [[OpenShift_Concepts#Persistent_Volume_Claim|persistent volume claim]], a "pvc.yaml" file with the following content
Line 91: Line 149:
Once created, the persistent volume claim is immediately bound to an available persistent volume, if exists and it matches persistent volume claim's criteria.
Once created, the persistent volume claim is immediately bound to an available persistent volume, if exists and it matches persistent volume claim's criteria.


=Associate a Persistent Volume Claim with a Deployment Configuration=
==Associate a Persistent Volume Claim with a Deployment Configuration==


Edit the Deployment Configuration:
Edit the Deployment Configuration:
Line 108: Line 166:
         volumeMounts:
         volumeMounts:
         - mountPath: /some/path/inside/the/container
         - mountPath: /some/path/inside/the/container
           name: volume-1 # this is the name of the container volume referred below
           name: '''volume-1''' <font color=darkgrey># this is the name of the container volume referred below</font>
         ...
         ...
         volumes:
         volumes:
         - name: volume-1
         - name: '''volume-1'''
           persistentVolumeClaim:
           persistentVolumeClaim:
             claimName: gogs-data
             claimName: <''<font color=teal>persistent-volume-claim-name</font>''>
       ...
       ...
The same result can be obtained with:
[[Oc_set#volumes|oc set volumes]]
==Unbind a Pod from the Volume==
Delete the persistent volume claim:
oc delete pvc <''persistent-volume-claim-name''>
The associated [[OpenShift Concepts#Persistent_Volume|persistent volume]] moves to a "Released" state after the persistent volume claim is deleted.
To return the volume to an "Available" state, edit its definition and release the persistent volume claim reference from the volume definition:
oc edit pv pv1
...
kind: PersistentVolume
spec:
  ...
  <font color=orange>claimRef:</font>
    <font color=orange>apiVersion: v1</font>
    <font color=orange>kind: PersistentVolumeClaim</font>
    <font color=orange>name: metrics-1</font>
    <font color=orange>namespace: openshift-infra</font>
    <font color=orange>resourceVersion: "2180"</font>
    <font color=orange>uid: 196343eb-c6b8-11e7-9f09-525400360e56</font>
  ...
{{Warn|Transitioning the persistent volume from "Released" to "Available" state does not clear the storage content - this will have to be done manually.}}
=Volumes with oc set=
{{Internal|Oc_set#volumes|oc set volumes}}

Latest revision as of 22:55, 25 January 2018

External

Internal

Overview

Persistent Volume Operations

List Existent Persistent Volumes

A persistent volume is not a project-specific object, so the following query will return all persistent volumes available to the OpenShift instance.

oc get pv

Details about a Specific Persistent Volume

oc describe pv <persistent-volume-name>

Delete an Unbound Persistent Volume

oc delete pv <persistent-volume-name>

Delete a Bound Persistent Volume


This is dangerous, do it only if you know what you're doing.

Delete the persistent volume claim first:

oc delete pvc <pvc-name>

The volume becomes "Released".

Then disassociate the persistent volume from the persistent volume claim reference, still attached to the volume.

This can be done interactively with oc edit - delete the "claimRef" structure, or with oc patch:

oc patch pv/<persistent-volume-name> --patch='{ "spec": { "claimRef": null}}'

Create a NFS Persistent Volume

Provision the Underlying Storage

Provisioning the underlying storage consists in exporting a NFS volume. On the support node:

1. Create a /etc/exports.d/persistent-volumes.exports file, if it does not exist already

2. Add entries similar to:

/nfs/pv1 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)
/nfs/pv2 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)
/nfs/pv3 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)
/nfs/pv4 192.168.122.0/255.255.255.0(rw,sync,no_root_squash,no_subtree_check)

adjusting for local IP and network mask.

3. Create the corresponding local directories.

mkdir pv1 pv2 pv3 pv4
chown nfsnobody:nfsnobody pv1 pv2 pv3 pv4
chmod a+rwx pv*

3. Export new filesystems:

exportfs -av

Create the Persistent Volume Definition File

Create a "pv.yaml" file with the following content:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv1
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /nfs/pv1
    server: support.ocp36.local

Make sure the "support.ocp36.local" server is accessible from any node that will use the volume, and the /nfs/pv1 is exported and has sufficient permissions.

Repeat for all persistent volumes, updating "name", "storage" and "path" accordingly.

Create the Volume

oc create -f pv.yaml

Once created, it will shows as:

oc get pv

NAME              CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM                    REASON    AGE
...
metrics-volume    10Gi       RWO           Retain          Available                                      25s
...

Note that the volume, even if available, it won't be used until a matching persistent volume claim is declared.

Use a Template

Alternatively, use this template: https://github.com/NovaOrdis/playground/blob/master/openshift/pv-template.yaml and run it as such:

oc process -f ./pv-template.yaml --param NAME=pv9 --param SIZE_GB=2 | oc create -f -

Recycle a "Released" Persistent Volume

See

Unbind a Pod from the Volume

below.

Persistent Volume Claim Operations

List Existent Persistent Volume Claims for the Current Project

A persistent volume claim is project-specific object, so the following query will return all persistent volume claims available in the current project:

oc get pvc

Create a Persistent Volume Claim

Create a definition of the persistent volume claim, a "pvc.yaml" file with the following content

apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
  name: "jenkins-data"
spec:
  accessModes:
    - "ReadWriteOnce"
  resources:
    requests:
      storage: "2Gi"

Create the persistent volume claim:

oc create -f pvc.yaml

Once created, the persistent volume claim is immediately bound to an available persistent volume, if exists and it matches persistent volume claim's criteria.

Associate a Persistent Volume Claim with a Deployment Configuration

Edit the Deployment Configuration:

oc edit dc/<deployment-configuration-name>
...
spec:
  ...
  template:
    ...
    spec:
     containers:
     - name: <container-name>
       ...
       volumeMounts:
       - mountPath: /some/path/inside/the/container
         name: volume-1 # this is the name of the container volume referred below
       ...
       volumes:
       - name: volume-1
         persistentVolumeClaim:
           claimName: <persistent-volume-claim-name>
     ...

The same result can be obtained with:

oc set volumes

Unbind a Pod from the Volume

Delete the persistent volume claim:

oc delete pvc <persistent-volume-claim-name>

The associated persistent volume moves to a "Released" state after the persistent volume claim is deleted.

To return the volume to an "Available" state, edit its definition and release the persistent volume claim reference from the volume definition:

oc edit pv pv1

...
kind: PersistentVolume
spec:
  ...
  claimRef:
   apiVersion: v1
   kind: PersistentVolumeClaim
   name: metrics-1
   namespace: openshift-infra
   resourceVersion: "2180"
   uid: 196343eb-c6b8-11e7-9f09-525400360e56
  ...

Transitioning the persistent volume from "Released" to "Available" state does not clear the storage content - this will have to be done manually.

Volumes with oc set

oc set volumes