Persistent storage examples

On platforms that do not provide shareable object storage, the RHOCP Image Registry Operator bootstraps itself as Removed. This allows the installer to complete installations on these platform types. After installation, you must edit the Image Registry Operator configuration to switch the managementState from Removed to Managed.

Persistent Volume Example

apiVersion: v1
kind: PersistentVolume
metadata:
  name: ocp-registry
spec:
  capacity:
    storage: 100Gi
  accessModes:
  - ReadWriteMany
  nfs:
    path: /mnt/ocp4-registry # (1)
    server: 172.17.0.2 # (2)
  1. The nfs path points to the directory where the 100Gi device has been mounted
  2. The nfs server is the IP address of the NFS server in this example
$ oc apply -f registry_pv.yaml -n openshift-image-registry

Persistent Volume Claim example (optional)

The following example shows how to create a Persistent Volume Claim (PVC) with 'ReadWriteMany' access mode and 100Gi of storage.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: registry-claim # (1)
  namespace: openshift-image-registry # (2)
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Gi
  1. This PVC is called registry-claim
  2. This PVC is created in the namespace openshift-image-registry

To create the persistent volume, run the following command:

$ oc apply -f registry_pv.yaml -n openshift-image-registry

The registry operator takes care of creating the required PVC. The only requirement is to edit the operator.

Edit the image registry operator to use the persistent storage

To edit the image registry operator, run the following command:

$ oc edit configs.imageregistry.operator.openshift.io

Replace the storage section with the following values:

...
storage:
  pvc:
    claim:

If you want to control the claim, you can create it manually and use it like in the following example. The section "storage:" must be replaced with the following values:

...
storage:
  pvc:
    claim: registry-claim

The ManagementState must be "Managed":

managementState: Managed # (1)
  1. By default the 'managementState' is se to 'Removed' and must be changed to 'Managed'.

Once that is done, the image registry operator will automatically apply the configuration and it can be verified by running the following command:

$ oc get co

The image-registry cluster operator should look as follows:

$ image-registry           4.2.29    True        False         False      15m #

Dynamic persistent storage using NFS

Define the NFS directories for each persistent storage definition by running the following command:

$ for i in {0..20};domkdir /mnt/nfs/share$i -p; chmod 777 /mnt/nfs/share$i; done

Next, add the new directories to the NFS server exports configuration:

/mnt/nfs *(rw,no_subtree_check,sync,no_wdelay,insecure,no_root_squash)
Warning: Do not use "*" after the directory path, restrict it to the appropriate subnet in production.

The NFS service must be restarted so the changes take effect:

# systemctl restart nfs-server

After preparing the new NFS resources, a new StorageClass is defined in RHOCP:

kind:StorageClassapiVersion:storage.k8s.io/v1metadata:name:nfsprovisioner:no-provisioningparameters:

Save the code as sc.yam by running the following command:

$ oc create -f sc.yaml

Patch the new NFS storage class to indicate that it is the default storage class by running the following command:

$ oc patch storageclass nfs -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "true"}}}'

A file with the definition of the Persistent Storage Volumes is created. This file includes 20 volumes of ReadWriteMany. It can be adjusted as necessary to meet the needs of each case:

$ for i in {01..20}; do \
cat <<EOF >> volumes.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
   name: vol${i}
spec:
   capacity:
      storage: 20Gi
   accessModes:
      - ReadWriteMany
   persistentVolumeReclaimPolicy: Recycle
   storageClassName: nfs
   nfs:
      path: /mnt/nfs/share${i}
      server: <nfs_server_IP_address>
---
EOFdone

The previous code generates a file that is saved as volumes.yaml that can be applied by running the following command:

$ oc create -f volumes.yaml

To verify the creation of the persistent volumes, run the following command:

$ oc get pv

NAME                CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                                             STORAGECLASS   REASON   AGE
image-registry-pv   100Gi      RWX            Retain           Bound       openshift-image-registry/image-registry-storage   nfs                     2d21h
vol01               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol02               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol03               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol04               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol05               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol06               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol07               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol08               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol09               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol10               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol11               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol12               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol13               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol14               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol15               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol16               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol17               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol18               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol19               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h
vol20               20Gi       RWX            Recycle          Available                                                     nfs                     2d21h

The default storage class can be verified by running the following command:

$ oc get storageclass
NAME            PROVISIONER       AGE
nfs (default)   no-provisioning   2d21h