---
title: "OpenEBS Container Attached Storage | grasys blog"
url: "https://blog.grasys.io/post/dokuma/openebs1/"
description: "OpenEBS 最近流行りのコンテナ用Persistent Diskソリューション(Container Attached Storage)のOpenEBSを使ってみたので公開。 メリット/デメリットは次のような感じ。個人的には運用ベースで考えるとメリットの方がデメリットを上回ってると考えています。パフォーマンスに関し…"
---

# OpenEBS Container Attached Storage

-   ![](/_astro/noicon.CTHOhNiB_1HMs6A.webp)[dokuma](/authors/dokuma/)
-   公開日：2018年3月5日
-   カテゴリー：[Tech](/categories/tech/)
-   タグ：[#cassandra](/tags/cassandra/)[#Kubernetes](/tags/kubernetes/)[#openebs](/tags/openebs/)

![OpenEBS Container Attached Storage](/_astro/og-image.DDSiu2Ny_XHpDd.webp)

## OpenEBS

最近流行りのコンテナ用Persistent Diskソリューション(Container Attached Storage)の[OpenEBS](https://docs.openebs.io/)を使ってみたので公開。

メリット/デメリットは次のような感じ。個人的には運用ベースで考えるとメリットの方がデメリットを上回ってると考えています。パフォーマンスに関してはゴリゴリにしたいのであればやはり専用のインフラ持つとかすると思うので無視w

メリット

-   Persistent DiskをStorageClassで抽象化するのでk8sレイヤの変更はStorageClassのみ
-   Statefulなアプリケーションはデータの永続性をシンプルに管理できる

デメリット

-   OpenEBSレイヤがオーバーヘッドとなるのでI/Oパフォーマンス低下するであろう(測定してないw)
-   OpenEBS自体がDeploymentsで構成されているのでクラスタリソースを消費する

## GKEクラスタ構築

弊社はGoogle Cloud (GCP) PlatformのパートナーなのでGCPで構築します。それ以外のCloud Providorとか期待してた方々(m´・ω・｀)m ｺﾞﾒﾝ…

Plain textcontent\_copy

```
PROJECT_ID=<Your Project ID>
gcloud container clusters create ebs-test \
  --project ${PROJECT_ID} \
  --zone asia-northeast1-a \
  --num-nodes 3 \
  --cluster-version 1.9.3-gke.0 \
  --tags open-ebs-test \
  --machine-type n1-standard-2 \
  --image-type UBUNTU
```

### 大事なこと

OpenEBSの[Requirements](https://docs.openebs.io/releasenotes.html#known-limitations)として

-   Kubernetes 1.7.5+
-   iscsi initiatorがNodeにインストールされていること

とあるので、`--cluster-version 1.9.3-gke.0`(GKEのStatefulSetは1.9でGAなので最新使う)、`--image-type UBUNTU`としています。 現状OpenEBSはNodeにマウントされているDiskしか利用できないのでDisk冗長構成のため3Node作ります。 1zoneに3台作るかzone分けて1台ずつ作るかの議論は今回は無視w

## OpenEBSクラスタデプロイ

現時点で最新の0.5.2を使います。

デプロイは[ドキュメント](https://docs.openebs.io/docs/cloudsolutions.html#google-cloud)の通り実施すればOK。つまり、超簡単。

Plain textcontent\_copy

```
GCP_ACCOUNT_EMAIL=<Your GCP Account Email Address>
CURRENT_CONTEXT=`kubectl config current-context`
git clone https://github.com/openebs/openebs.git
git checkout tags/v0.5.2
cd openebs/k8s
kubectl create clusterrolebinding ${CURRENT_CONTEXT} \
  --clusterrole=cluster-admin \
  --user=${GCP_ACCOUNT_EMAIL}
kubectl apply -f openebs-operator.yaml
```

### マメ

GKEの制約でOpenEBSのRBACを作成する際にclusterrolebindingが必要なため[1](#user-content-fn-1)実行しています。これ、RBAC使っているソリューションは全部一緒だからマメな。

serviceとdeploymentsがデプロイされました。

Plain textcontent\_copy

```
kubectl get all
NAME                         DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/maya-apiserver        1         1         1            1           1m
deploy/openebs-provisioner   1         1         1            1           1m

NAME                               DESIRED   CURRENT   READY     AGE
rs/maya-apiserver-798f5d6887       1         1         1         1m
rs/openebs-provisioner-74f87ccd6   1         1         1         1m

NAME                         DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/maya-apiserver        1         1         1            1           1m
deploy/openebs-provisioner   1         1         1            1           1m

NAME                               DESIRED   CURRENT   READY     AGE
rs/maya-apiserver-798f5d6887       1         1         1         1m
rs/openebs-provisioner-74f87ccd6   1         1         1         1m

NAME                                     READY     STATUS    RESTARTS   AGE
po/maya-apiserver-798f5d6887-64jng       1/1       Running   0          1m
po/openebs-provisioner-74f87ccd6-trmsc   1/1       Running   0          1m

NAME                         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
svc/kubernetes               ClusterIP   10.35.240.1    <none>        443/TCP    36m
svc/maya-apiserver-service   ClusterIP   10.35.243.59   <none>        5656/TCP   1m
```

## Cassandraをデプロイしてみる

さて、OpenEBSはデプロイできましたが、これだけでは何も楽しくないですね。

OpenEBSのリポジトリにdemoとして色々と用意されています。

Plain textcontent\_copy

```
ls -l demo/
total 48
-rw-r--r-- 1 dokuma  staff    852  2 19 13:42 README.md
-rw-r--r-- 1 dokuma  staff  14378  2 19 13:42 Vagrantfile
drwxr-xr-x   8 dokuma  staff    256  2 23 14:46 cassandra
drwxr-xr-x   7 dokuma  staff    224  2 19 13:42 cockroachDB
drwxr-xr-x   6 dokuma  staff    192  2 19 13:42 couchbase
drwxr-xr-x  10 dokuma  staff    320  2 19 13:42 crunchy-postgres
drwxr-xr-x   7 dokuma  staff    224  2 19 13:42 efk
drwxr-xr-x   3 dokuma  staff     96  2 19 18:44 galera-xtradb-cluster
drwxr-xr-x   5 dokuma  staff    160  2 19 13:42 jenkins
drwxr-xr-x   4 dokuma  staff    128  2 19 13:42 jupyter
drwxr-xr-x   9 dokuma  staff    288  3  5 13:46 kafka
drwxr-xr-x   5 dokuma  staff    160  3  5 13:46 mongodb
drwxr-xr-x   3 dokuma  staff     96  2 19 13:42 mysql-replication-cluster
drwxr-xr-x   8 dokuma  staff    256  2 19 13:42 percona
-rw-r--r-- 1 dokuma  staff    203  2 19 13:42 pvc.yaml
drwxr-xr-x   5 dokuma  staff    160  2 19 13:42 rabbitmq
drwxr-xr-x   6 dokuma  staff    192  2 19 18:43 redis
drwxr-xr-x   8 dokuma  staff    256  2 19 13:42 scripts
drwxr-xr-x  12 dokuma  staff    384  2 19 13:42 specs
drwxr-xr-x   3 dokuma  staff     96  2 19 13:42 vdbench
```

というわけで、Cassandraでもデプロイしてみますか。

Plain textcontent\_copy

```
kubectl apply -f openebs-storageclasses.yaml
kubectl apply -f demo/cassandra/cassandra-service.yaml
kubectl apply -f demo/cassandra/cassandra-statefulset.yaml
```

もりもり作成されましたね。

Plain textcontent\_copy

```
ubectl get svc,deployments,pods,pvc
NAME                                                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
svc/cassandra                                           ClusterIP   None            <none>        9042/TCP            16m
svc/kubernetes                                          ClusterIP   10.35.240.1     <none>        443/TCP             1h
svc/maya-apiserver-service                              ClusterIP   10.35.243.59    <none>        5656/TCP            24m
svc/pvc-1f7e768d-2036-11e8-88cd-42010a9200cb-ctrl-svc   ClusterIP   10.35.245.7     <none>        3260/TCP,9501/TCP   8m
svc/pvc-55d137c0-2036-11e8-88cd-42010a9200cb-ctrl-svc   ClusterIP   10.35.242.49    <none>        3260/TCP,9501/TCP   6m
svc/pvc-dd17fec4-2035-11e8-88cd-42010a9200cb-ctrl-svc   ClusterIP   10.35.248.126   <none>        3260/TCP,9501/TCP   10m

NAME                                                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/maya-apiserver                                  1         1         1            1           24m
deploy/openebs-provisioner                             1         1         1            1           24m
deploy/pvc-1f7e768d-2036-11e8-88cd-42010a9200cb-ctrl   1         1         1            1           8m
deploy/pvc-1f7e768d-2036-11e8-88cd-42010a9200cb-rep    2         2         2            2           8m
deploy/pvc-55d137c0-2036-11e8-88cd-42010a9200cb-ctrl   1         1         1            1           6m
deploy/pvc-55d137c0-2036-11e8-88cd-42010a9200cb-rep    2         2         2            2           6m
deploy/pvc-dd17fec4-2035-11e8-88cd-42010a9200cb-ctrl   1         1         1            1           10m
deploy/pvc-dd17fec4-2035-11e8-88cd-42010a9200cb-rep    2         2         2            2           10m

NAME                                                                READY     STATUS    RESTARTS   AGE
po/cassandra-0                                                      1/1       Running   0          10m
po/cassandra-1                                                      1/1       Running   0          8m
po/cassandra-2                                                      1/1       Running   0          6m
po/maya-apiserver-798f5d6887-64jng                                  1/1       Running   0          24m
po/openebs-provisioner-74f87ccd6-trmsc                              1/1       Running   0          24m
po/pvc-1f7e768d-2036-11e8-88cd-42010a9200cb-ctrl-86b4d74df5-cgr96   2/2       Running   0          8m
po/pvc-1f7e768d-2036-11e8-88cd-42010a9200cb-rep-6646db99fc-25mnm    1/1       Running   0          8m
po/pvc-1f7e768d-2036-11e8-88cd-42010a9200cb-rep-6646db99fc-6v7k4    1/1       Running   0          8m
po/pvc-55d137c0-2036-11e8-88cd-42010a9200cb-ctrl-886c96586-wgxhm    2/2       Running   0          6m
po/pvc-55d137c0-2036-11e8-88cd-42010a9200cb-rep-856d5898d6-gmw2w    1/1       Running   0          6m
po/pvc-55d137c0-2036-11e8-88cd-42010a9200cb-rep-856d5898d6-vwbhw    1/1       Running   0          6m
po/pvc-dd17fec4-2035-11e8-88cd-42010a9200cb-ctrl-7c969cc66c-jl5sj   2/2       Running   0          10m
po/pvc-dd17fec4-2035-11e8-88cd-42010a9200cb-rep-598955b9b4-mt5px    1/1       Running   0          10m
po/pvc-dd17fec4-2035-11e8-88cd-42010a9200cb-rep-598955b9b4-tjqjg    1/1       Running   0          10m

NAME                             STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS        AGE
pvc/cassandra-data-cassandra-0   Bound     pvc-dd17fec4-2035-11e8-88cd-42010a9200cb   5G         RWO            openebs-cassandra   10m
pvc/cassandra-data-cassandra-1   Bound     pvc-1f7e768d-2036-11e8-88cd-42010a9200cb   5G         RWO            openebs-cassandra   8m
pvc/cassandra-data-cassandra-2   Bound     pvc-55d137c0-2036-11e8-88cd-42010a9200cb   5G         RWO            openebs-cassandra   6m
```

おお〜簡単。

本格的にCassandraを使いたいときは、`demo/cassandra/cassandra-statefulset.yaml`を参考に色々試してみれば良さそうですね。

### お時間あれば

`cassandra-stress`で負荷テストかけるJobも用意されているので、興味ある人は実施してみてね☆彡

OpenEBSを利用するためのエッセンスは`volumeClaimTemplates`でStorageClassを設定しているところだけです。

Plain textcontent\_copy

```
  volumeClaimTemplates:
  - metadata:
      name: cassandra-data
      annotations:
        volume.beta.kubernetes.io/storage-class: openebs-cassandra # <- これ
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 5G
```

`openebs-cassandra`というStorageClassは`openebs-storageclasses.yaml`のなかで定義されていて、

Plain textcontent\_copy

```
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: openebs-cassandra
provisioner: openebs.io/provisioner-iscsi
parameters:
  openebs.io/storage-pool: "default"
  openebs.io/jiva-replica-count: "2"
  openebs.io/volume-monitor: "true"
  openebs.io/capacity: 5G
```

こんな感じ。

SSDとか使いたいとかcapacity変更したいとかあれば場合は独自のStorageClassを定義すれば。。。

現状のOpenEBSはその辺の設定([StoragePolicy](https://docs.openebs.io/docs/storagepolicies.html))が複雑なので今回は紹介しませんが、SSDをマウントして使うところまでは確認しています。

## まとめ

OpenEBSはコンテナ世代のストレージソリューションです。まだGAじゃないけど開発も活発だしどう考えても素敵ソリューションです。

-   簡単に構築できる
-   GKEで管理しているアプリケーション(特にStatefulなやつ)のストレージ管理が楽になる
-   StoragePolicy(もりもり開発中だと思う)を理解すればカスタム可能
-   RBACの作成は気をつけよう
-   demoに色々あるから参考になる

今後注目のCAS(Container Attached Storage)、OpenEBSの紹介でした！

enjoy!

* * *

## Footnotes

1.  [参考](https://coreos.com/operators/prometheus/docs/latest/troubleshooting.html) [↩](#user-content-fnref-1)
    

## この記事を書いた人

[![](/_astro/noicon.CTHOhNiB_Z24aAgM.webp)](/authors/dokuma/)

### [dokuma](/authors/dokuma/)

dokumaのプロフィールと執筆記事をご覧いただけます。

[プロフィールと記事一覧](/authors/dokuma/)
