OpenShift PersistentVolume Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 9: Line 9:
=Persistent Volume Operations=
=Persistent Volume Operations=


=List Existent Volumes=
==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 15: Line 15:
  oc get pv
  oc get pv


=Delete a Persistent Volume=
==Delete a Persistent Volume==


  oc delete pv <''persistent-volume-name''>
  oc delete pv <''persistent-volume-name''>
Line 21: Line 21:
  oc delete pv metrics-volume
  oc delete pv metrics-volume


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


==NFS==
===NFS===


===Provision the Underlying Storage===
====Provision the Underlying Storage====


===Create the Persistent Volume Definition File===
====Create the Persistent Volume Definition File====


Create a "pv.yaml" file with the following content:
Create a "pv.yaml" file with the following content:
Line 49: Line 49:
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.local" server is accessible from any node that will use the volume, and the /support-nfs-storage/metrics is exported and has sufficient permissions.


===Create the Volume===
====Create the Volume====


  oc create -f pv.yaml
  oc create -f pv.yaml
Line 64: Line 64:
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=
=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 70: Line 72:
  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 93: Line 95:
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:

Revision as of 00:28, 2 November 2017

External

Internal

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

Delete a Persistent Volume

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

Create a Persistent Volume

NFS

Provision the Underlying Storage

Create the Persistent Volume Definition File

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

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

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.

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.

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>
     ...