OpenShift in the public cloud graphic

Developers running applications in the cloud have traditionally separated their applications from storage, but recent services such as the Rook Operator for Kubernetes make it easy to create storage in the cloud. This article shows how to use Rook for object storage. Our example runs a single-node Red Hat OpenShift cluster on your laptop or desktop using Red Hat OpenShift Local (previously known as CodeReady Containers). We'll install Rook, create object storage on OpenShift Local, and perform some bucket notifications.

Rook is an open source offering from the Cloud Native Computing Foundation (CNCF). This article creates storage using the Ceph object store.

Install and run Red Hat OpenShift Local

You can download the latest release of OpenShift Local and follow the installation instructions to run it.

Add disk space for Rook

OpenShift Local doesn't provide additional disk space, so users need to create it manually and attach it to the instance. This process is specific to your operating system. The following steps work on GNU/Linux:

$ qemu-img create -f raw /full/path/to/crc-extra-disk 30G
$ sudo virsh attach-disk crc --source /full/path/to/crc-extra-disk --target vdb --cache none

Log in to the OpenShift cluster

Log in as the kubeadmin administrative user:

$ crc console --credentials
$ oc login -u kubeadmin -p <password> https://api.crc.testing:6443
$ oc whoami
kubeadmin

Install Rook resources

Rook requires custom resource definitions (CRDs), an Operator, and other resources that you can install through OpenShift's oc administative commmand:

$ oc apply -f https://raw.githubusercontent.com/rook/rook/master/deploy/examples/crds.yaml
$ oc apply -f https://raw.githubusercontent.com/rook/rook/master/deploy/examples/common.yaml
$ oc apply -f https://raw.githubusercontent.com/rook/rook/master/deploy/examples/operator-openshift.yaml
$ oc apply -f https://raw.githubusercontent.com/rook/rook/master/deploy/examples/cluster-test.yaml

Use a secure port for the object store:

$ cat <<EOF | oc apply -f -
#################################################################################################################
# Create an object store with settings for a test environment. Only a single OSD is required in this example.
#  kubectl create -f object-test.yaml
#################################################################################################################
apiVersion: ceph.rook.io/v1
kind: CephObjectStore
metadata:
  name: my-store
  namespace: rook-ceph # namespace:cluster
spec:
  metadataPool:
    replicated:
      size: 1
  dataPool:
    replicated:
      size: 1
  preservePoolsOnDelete: false
  gateway:
    service:
      annotations:
        service.beta.openshift.io/serving-cert-secret-name: my-store-tls
    securePort: 443
    instances: 1
EOF

Wait until all the pods in the rook-ceph namespace are running. You can check that they are running through the following command:

$ oc get pods -n rook-ceph
NAME                                                READY   STATUS      RESTARTS   AGE
csi-cephfsplugin-provisioner-6f54f6c477-5sp9k       6/6     Running     0          29m
csi-cephfsplugin-z96pz                              3/3     Running     0          29m
csi-rbdplugin-provisioner-6d765b47d5-pkc8j          6/6     Running     0          29m
csi-rbdplugin-ssgc9                                 3/3     Running     0          29m
rook-ceph-mgr-a-5b8f9998c6-vrglx                    1/1     Running     0          27m
rook-ceph-mon-a-7445f49f8-6tfjj                     1/1     Running     0          27m
rook-ceph-operator-5df4d596d5-sfrtw                 1/1     Running     0          31m
rook-ceph-osd-0-5f46f4cb58-498w6                    1/1     Running     0          26m
rook-ceph-osd-prepare-crc-8rwmc-master-0--1-zjcgc   0/1     Completed   0          26m
rook-ceph-rgw-my-store-a-6847bcf96b-cwc9s           1/1     Running     0          17m

Create an object bucket claim

An object bucket claim (OBC) is a CRD that creates a storage class. The following commands create your OBC:

$ oc apply -f https://raw.githubusercontent.com/rook/rook/master/deploy/examples/storageclass-bucket-delete.yaml
$ oc apply -f https://raw.githubusercontent.com/rook/rook/master/deploy/examples/object-bucket-claim-delete.yaml

See the OBC configuration documentation for more information.

Allow external access

OpenShift has a route resource to expose a service externally, which you can use for the rook-ceph-rgw-my-store service:

$ oc create route passthrough --service=rook-ceph-rgw-my-store -n rook-ceph
$ oc get route -n rook-ceph
NAME                     HOST/PORT                                           PATH   SERVICES                 PORT    TERMINATION   WILDCARD
rook-ceph-rgw-my-store   rook-ceph-rgw-my-store-rook-ceph.apps-crc.testing          rook-ceph-rgw-my-store   https   passthrough   None

Upload a file to your object store

Amazon Web Services (AWS) provides a command-line interface (CLI) to carry out just about anything you need to do on AWS. Download the CLI if you don't already have it; you can find the Linux version here. Install it as explained in the accompanying documentation.

To make sure you have the AWS CLI installed, enter:

$ aws --version
aws-cli/1.23.6 Python/3.6.8 Linux/4.18.0-348.el8.x86_64 botocore/1.25.6

Export the required AWS variables from the cluster:

$ export AWS_ACCESS_KEY_ID=$(kubectl -n default get secret ceph-notification-bucket -o jsonpath='{.data.AWS_ACCESS_KEY_ID}' | base64 --decode)
$ export AWS_SECRET_ACCESS_KEY=$(kubectl -n default get secret ceph-notification-bucket -o jsonpath='{.data.AWS_SECRET_ACCESS_KEY}' | base64 --decode)
$ export AWS_URL=https://rook-ceph-rgw-my-store-rook-ceph.apps-crc.testing

Get the bucket from the OBC:

$ export BUCKET_NAME=$(kubectl get objectbucketclaim ceph-notification-bucket -o jsonpath='{.spec.bucketName}')

Upload the file and ensure that it's available:

$ echo "hello world" > hello.txt
$ aws --no-verify-ssl --endpoint-url "$AWS_URL" s3 cp hello.txt s3://"$BUCKET_NAME"
upload: ./hello.txt to s3://ceph-bkt-f51b12b7-1240-48a0-b6a5-fa0a15c18e94/hello.txt
$ aws --no-verify-ssl --endpoint-url "$AWS_URL" s3 ls s3://"$BUCKET_NAME"
2022-05-04 04:49:57         12 hello.txt

Object storage is easy to install in the cloud

This article has shown how to use the Rook Operator to create storage in the same cluster where your application runs. The principles can be extended to many cloud environments and types of storage.

Last updated: November 8, 2023