6. Create the PersistentVolumeClaim¶
Depending on the settings that you choose in your PVC, you can provision IBM Cloud Object Storage in the following ways:
- Dynamic provisioning: When you create the PVC, the matching persistent volume (PV) and the bucket in your IBM Cloud Object Storage service instance are automatically created.
- Static provisioning: You can reference an existing bucket in your IBM Cloud Object Storage service instance in your PVC. When you create the PVC, only the matching PV is automatically created and linked to your existing bucket in IBM Cloud Object Storage.
In this exercise, you are going to use an existing bucket when assigning persistant storage to IKS container.
-
In the cloud shell connected to your cluster, create a
PersistentVolumeClaim
configuration file.Note: Replace the values for:
ibm.io/bucket
,ibm.io/secret-name
andibm.io/endpoint
.
If your values are not exactly matching with the bucket name you created, the secret name you created and the private endpoint of your bucket, the PVC will remain in state pending and fail to create.
Note: The
secret-name
should be set tocos-write-access
unless you changed the name of the secret we created earlier, Note:ibm.io/endpoint
should be set to the output of commandecho "https://$COS_PRIVATE_ENDPOINT"
Create the file first and then edit the file withvi
if changes are needed, -
You need the bucket name and namespace to configure the PVC,
echo "https://$COS_PRIVATE_ENDPOINT" echo $COS_BUCKET_NAME oc project
-
Create the file,
echo 'kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-iks-pvc
namespace: <your-namespace>
annotations:
ibm.io/auto-create-bucket: "false"
ibm.io/auto-delete-bucket: "false"
ibm.io/bucket: "<your-cos-bucket>"
ibm.io/secret-name: "cos-write-access"
ibm.io/endpoint: "https://s3.private.us-south.cloud-object-storage.appdomain.cloud"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
storageClassName: ibmc-s3fs-standard-regional' > my-iks-pvc.yaml
Note: indentation in YAML is important. If the PVC status remains Pending
, the two usual suspects will be the secret
with its credentials and the indentation in the YAML of the PVC.
- In
Theia
the integrated browser IDE, in the directory/project/cos-with-s3fs
, open the filemy-iks-pvc.yaml
,
and set the right values if changes are still needed,
- change the
namespace
value to the project name found withoc project
, - the
ibm.io/bucket
should be set to the value defined inecho $COS_BUCKET_NAME
, ibm.io/secret-name
should be set to"cos-write-access"
,-
validate the
ibm.io/endpoint
to be set to the private service endpoint for your Object Storage bucket for the correct region, -
Create a
PersistentVolumeClaim
.oc apply -f my-iks-pvc.yaml
outputs,
$ oc apply -f my-iks-pvc.yaml persistentvolumeclaim/my-iks-pvc created
-
Verify the
PersistentVolumeClaim
and through the PVC also thePersistentVolume
or PV was created successfully and that the PVC hasSTATUS
ofBound
.oc get pvc
should output a status of
Bound
,$ oc get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE my-iks-pvc Bound pvc-1a1f4bce-a8fe-4bd8-a160-f9268af2d18a 8Gi RWO ibmc-s3fs-standard-regional 4s
Note: If the state of the PVC remains
Pending
, you can inspect the error for why the PVC remains pending by using thedescribe
command:oc describe pvc <pvc_name>
. For example,oc describe pvc my-iks-pvc
. Note: If the state of the PVC stays asPending
, the problem must be resolved before you move to the next step. -
Verify a new
PersistentVolume
was also created successfully.oc get pv
outputs,
$ oc get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-70ac9454-27d8-43db-807f-d75474b0d61c 100Gi RWX Delete Bound openshift-image-registry/image-registry-storage ibmc-file-gold 36h pvc-86d739c4-86c1-4496-ab4e-c077d947acc0 8Gi RWO Delete Bound remkohdev-project1/my-iks-pvc ibmc-s3fs-standard-regional 4m26s
You're now ready to persist data on the IBM Cloud Object Storage within your containers in your cluster.