2017-08-04 13:15:34 -07:00
---
title : Object Storage
2019-02-04 09:46:00 -08:00
weight : 2200
2017-08-04 13:15:34 -07:00
indent : true
---
2018-01-12 16:55:23 -08:00
# Object Storage
2017-04-14 17:09:18 -07:00
Object storage exposes an S3 API to the storage cluster for applications to put and get data.
2017-08-07 12:13:18 -07:00
## Prerequisites
2017-04-14 17:09:18 -07:00
2019-08-08 19:54:24 -06:00
This guide assumes a Rook cluster as explained in the [Quickstart ](ceph-quickstart.md ).
2017-04-14 17:09:18 -07:00
2018-03-16 08:32:12 -07:00
## Create an Object Store
2017-08-07 12:13:18 -07:00
2019-08-08 19:54:24 -06:00
The below sample will create a `CephObjectStore` that starts the RGW service in the cluster with an S3 API.
2018-12-07 14:21:50 +01:00
2019-08-08 19:54:24 -06:00
**NOTE:** This sample requires *at least 3 bluestore OSDs* , with each OSD located on a *different node* .
The OSDs must be located on different nodes, because the [`failureDomain` ](ceph-pool-crd.md#spec ) is set to `host` and the `erasureCoded` chunk settings require at least 3 different OSDs (2 `dataChunks` + 1 `codingChunks` ).
See the [Object Store CRD ](ceph-object-store-crd.md#object-store-settings ), for more detail on the settings availabe for a `CephObjectStore` .
2017-09-29 09:27:12 -07:00
```yaml
2018-12-03 15:08:29 -07:00
apiVersion : ceph.rook.io/v1
2018-12-03 23:48:40 -07:00
kind : CephObjectStore
2017-09-29 09:27:12 -07:00
metadata :
name : my-store
2018-05-18 14:28:05 -07:00
namespace : rook-ceph
2017-09-29 09:27:12 -07:00
spec :
metadataPool :
2018-12-07 14:21:50 +01:00
failureDomain : host
2017-09-29 09:27:12 -07:00
replicated :
size : 3
dataPool :
2018-12-07 14:21:50 +01:00
failureDomain : host
2017-09-29 09:27:12 -07:00
erasureCoded :
2017-11-02 00:32:16 +01:00
dataChunks : 2
codingChunks : 1
2017-09-29 09:27:12 -07:00
gateway :
type : s3
2018-04-01 18:31:47 +02:00
sslCertificateRef :
2017-09-29 09:27:12 -07:00
port : 80
securePort :
instances : 1
```
2019-08-08 19:54:24 -06:00
After the `CephObjectStore` is created, the Rook operator will then create all the pools and other resources necessary to start the service. This may take a minute to complete.
2017-09-29 09:27:12 -07:00
```bash
# Create the object store
2018-05-18 14:28:05 -07:00
kubectl create -f object.yaml
2017-09-29 09:27:12 -07:00
# To confirm the object store is configured, wait for the rgw pod to start
2018-05-18 14:28:05 -07:00
kubectl -n rook-ceph get pod -l app = rook-ceph-rgw
2017-09-29 09:27:12 -07:00
```
## Create a User
2019-08-08 19:54:24 -06:00
Next, create a `CephObjectStoreUser` , which will be used to connect to the RGW service in the cluster using the S3 API.
See the [Object Store User CRD ](ceph-object-store-user-crd.md ) for more detail on the settings available for a `CephObjectStoreUser` .
2018-11-09 09:41:00 -06:00
```yaml
2018-12-03 15:08:29 -07:00
apiVersion : ceph.rook.io/v1
2018-12-03 23:48:40 -07:00
kind : CephObjectStoreUser
2018-11-09 09:41:00 -06:00
metadata :
name : my-user
namespace : rook-ceph
spec :
store : my-store
displayName : "my display name"
```
2019-08-08 19:54:24 -06:00
When the `CephObjectStoreUser` is created, the Rook operator will then create the RGW user on the specified `CephObjectStore` and store the Access Key and Secret Key in a kubernetes secret in the same namespace as the `CephObjectStoreUser` .
2017-04-14 17:09:18 -07:00
```bash
2018-11-09 09:41:00 -06:00
# Create the object store user
kubectl create -f object-user.yaml
# To confirm the object store user is configured, describe the secret
2018-12-07 22:50:33 -07:00
kubectl -n rook-ceph describe secret rook-ceph-object-user-my-store-my-user
2018-11-09 09:41:00 -06:00
2018-12-07 22:50:33 -07:00
Name: rook-ceph-object-user-my-store-my-user
2018-11-09 09:41:00 -06:00
Namespace: rook-ceph
Labels: app = rook-ceph-rgw
rook_cluster = rook-ceph
rook_object_store = my-store
Annotations: <none>
Type: kubernetes.io/rook
Data
====
AccessKey: 20 bytes
SecretKey: 40 bytes
2017-04-14 17:09:18 -07:00
```
2018-11-09 09:41:00 -06:00
The AccessKey and SecretKey data fields can be mounted in a pod as an environment variable. More information on consuming
2018-12-07 22:50:33 -07:00
kubernetes secrets can be found in the [K8s secret documentation ](https://kubernetes.io/docs/concepts/configuration/secret/ )
To directly retrieve the secrets:
```bash
kubectl -n rook-ceph get secret rook-ceph-object-user-my-store-my-user -o yaml | grep AccessKey | awk '{print $2}' | base64 --decode
kubectl -n rook-ceph get secret rook-ceph-object-user-my-store-my-user -o yaml | grep SecretKey | awk '{print $2}' | base64 --decode
```
2017-08-07 12:13:18 -07:00
2018-03-16 08:32:12 -07:00
## Consume the Object Storage
2017-04-14 17:09:18 -07:00
2019-08-08 19:54:24 -06:00
Use an S3 compatible client to create a bucket in the `CephObjectStore` .
2018-03-16 08:32:12 -07:00
2019-08-08 19:54:24 -06:00
This section will allow you to test connecting to the `CephObjectStore` and uploading and downloading from it. Run the following commands after you have connected to the [Rook toolbox ](ceph-toolbox.md ).
2018-10-02 16:42:55 -06:00
### Install s3cmd
2019-08-08 19:54:24 -06:00
To test the `CephObjectStore` we will install the `s3cmd` tool into the toobox pod.
2018-10-02 16:42:55 -06:00
```bash
yum --assumeyes install s3cmd
```
2018-03-16 08:32:12 -07:00
### Connection Environment Variables
To simplify the s3 client commands, you will want to set the four environment variables for use by your client (ie. inside the toolbox):
2017-04-14 17:09:18 -07:00
```bash
2018-03-16 08:32:12 -07:00
export AWS_HOST = <host>
export AWS_ENDPOINT = <endpoint>
export AWS_ACCESS_KEY_ID = <accessKey>
export AWS_SECRET_ACCESS_KEY = <secretKey>
2017-04-14 17:09:18 -07:00
```
2018-05-18 14:28:05 -07:00
- `Host` : The DNS host name where the rgw service is found in the cluster. Assuming you are using the default `rook-ceph` cluster, it will be `rook-ceph-rgw-my-store.rook-ceph` .
- `Endpoint` : The endpoint where the rgw service is listening. Run `kubectl -n rook-ceph get svc rook-ceph-rgw-my-store` , then combine the clusterIP and the port.
2018-03-16 08:32:12 -07:00
- `Access key` : The user's `access_key` as printed above
- `Secret key` : The user's `secret_key` as printed above
The variables for the user generated in this example would be:
```bash
2018-05-18 14:28:05 -07:00
export AWS_HOST = rook-ceph-rgw-my-store.rook-ceph
2018-03-16 08:32:12 -07:00
export AWS_ENDPOINT = 10.104.35.31:80
export AWS_ACCESS_KEY_ID = XEZDB3UJ6X7HVBE7X7MA
export AWS_SECRET_ACCESS_KEY = 7yGIZON7EhFORz0I40BFniML36D2rl8CQQ5kXU6l
```
2019-03-01 00:26:55 +08:00
The access key and secret key can be retrieved as described in the section above on [creating a user ](#create-a-user ).
2018-12-07 22:50:33 -07:00
2018-03-16 08:32:12 -07:00
### Create a bucket
Now that the user connection variables were set above, we can proceed to perform operations such as creating buckets.
2019-08-08 19:54:24 -06:00
Create a bucket in the `CephObjectStore`
2018-03-16 08:32:12 -07:00
```bash
2019-05-15 12:51:58 +02:00
s3cmd mb --no-ssl --host=${AWS_HOST} --region=":default-placement" --host-bucket="" s3://rookbucket
2018-03-16 08:32:12 -07:00
` ``
2019-08-08 19:54:24 -06:00
List buckets in the ` CephObjectStore`
2018-03-16 08:32:12 -07:00
` ``bash
s3cmd ls --no-ssl --host=${AWS_HOST}
` ``
### PUT or GET an object
Upload a file to the newly created bucket
` ``bash
2018-07-13 14:29:57 -06:00
echo "Hello Rook" > /tmp/rookObj
2018-03-16 08:32:12 -07:00
s3cmd put /tmp/rookObj --no-ssl --host=${AWS_HOST} --host-bucket= s3://rookbucket
` ``
Download and verify the file from the bucket
` ``bash
s3cmd get s3://rookbucket/rookObj /tmp/rookObj-download --no-ssl --host=${AWS_HOST} --host-bucket=
cat /tmp/rookObj-download
` ``
2017-04-14 17:09:18 -07:00
## Access External to the Cluster
Rook sets up the object storage so pods will have access internal to the cluster. If your applications are running outside the cluster,
you will need to setup an external service through a ` NodePort`.
First, note the service that exposes RGW internal to the cluster. We will leave this service intact and create a new service for external access.
` ``bash
2018-05-18 14:28:05 -07:00
$ kubectl -n rook-ceph get service rook-ceph-rgw-my-store
2017-09-29 09:27:12 -07:00
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
rook-ceph-rgw-my-store 10.3.0.177 <none> 80/TCP 2m
2017-04-14 17:09:18 -07:00
` ``
2017-08-08 14:03:04 -07:00
Save the external service as ` rgw-external.yaml`:
` ``yaml
apiVersion: v1
kind: Service
metadata:
2017-09-29 09:27:12 -07:00
name: rook-ceph-rgw-my-store-external
2018-05-18 14:28:05 -07:00
namespace: rook-ceph
2017-08-08 14:03:04 -07:00
labels:
app: rook-ceph-rgw
2018-05-18 14:28:05 -07:00
rook_cluster: rook-ceph
2017-09-29 09:27:12 -07:00
rook_object_store: my-store
2017-08-08 14:03:04 -07:00
spec:
ports:
- name: rgw
2018-03-30 08:51:13 +03:00
port: 80
2017-08-08 14:03:04 -07:00
protocol: TCP
2018-03-30 08:51:13 +03:00
targetPort: 80
2017-08-08 14:03:04 -07:00
selector:
app: rook-ceph-rgw
2018-05-18 14:28:05 -07:00
rook_cluster: rook-ceph
2017-09-29 09:27:12 -07:00
rook_object_store: my-store
2017-08-08 14:03:04 -07:00
sessionAffinity: None
type: NodePort
` ``
Now create the external service.
2017-04-14 17:09:18 -07:00
` ``bash
kubectl create -f rgw-external.yaml
` ``
See both rgw services running and notice what port the external service is running on:
` ``bash
2018-05-18 14:28:05 -07:00
$ kubectl -n rook-ceph get service rook-ceph-rgw-my-store rook-ceph-rgw-my-store-external
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
rook-ceph-rgw-my-store ClusterIP 10.104.82.228 <none> 80/TCP 4m
rook-ceph-rgw-my-store-external NodePort 10.111.113.237 <none> 80:31536/TCP 39s
2017-04-14 17:09:18 -07:00
` ``
2019-08-08 19:54:24 -06:00
Internally the rgw service is running on port ` 80`. The external port in this case is ` 31536`. Now you can access the ` CephObjectStore` from anywhere! All you need is the hostname for any machine in the cluster, the external port, and the user credentials.