DockerライクなUXでCloud Nativeな体験が出来るらしいRioを試してみる

qiita.com

遅れてしまいましたが、この記事は、 MicroAd Advent Calendar 2018 の16日目の記事です。

はじめに

本当は、 Rancher Labsの RKE を試す記事にしようかなぁと思っていたが、すでに他社の別の人 1 がやっているのを観測してしまったので、どうせなら、 同じく気になっていた Rio に変更しました。

とは言え、
febc-yamamoto.hatenablog.jp
上記の記事とも被りますが、そんな事を言いだしたら永久に何も出来ないので、まずは、 「個人的な興味として」 触りたい(大事)。

って事で続きます。

Rioって何?

rancher.com

Rancher Labsの新しい開発プロジェクトで、開発には、 Rancher LabsのChief Architect & Co-founderDarren Shepherd(@ibuildthecloud)さん が関わっています。

github.com

Rioのコンセプトは

  1. Simple, fun, end-to-end container experience
  2. Cloud Native Container Distribution

Rio is a user-oriented end-to-end container solution with a focus on keeping containers simple and combating the current trend of complexity. It's kept fun and simple though it's familiar and opinionated user experience. Additionally, Rio is a "Cloud Native Container Distribution" meaning it includes built-in Cloud Native technologies such as Kubernetes, Istio, Containerd, etc. so that the user need not be an expert in installing, using, and maintaining these systems.

www.youtube.com

という事で、利用者が使いやすく、シンプルで楽しいCloud Nativeなコンテナソリューションだそうで、
今後は、ストレージに Rancher Labsの Longhorn も予定しているとの事で気になります。 また、Rioのコマンドは、昔のdockerコマンドのようなもの2が多く見受けられ、取っつきやすい感じはあります。

ただ、まだ、 Early Preview なので、未実装なところも多く残っています。

コンセプト

Rioのコンセプトは Concepts にある通り、 ServiceStackProjectで構成されています。

まず、個々のコンテナを組み合わせて1つのServiceを構成し、
その複数をまとめたStackがあります。ServiceStackが異なれば名前が被ってもOK。
また、Stack単位にアクセス出来る・出来ないを制御するのがProject(最初はWorkspaceと呼んでいました)となります。

例えば、下図の様な使い方が考えられます。

f:id:yassan0627:20181217232440p:plain

ServiceStackなど端々に、Rancher v1系の面影を感じますね。

実際にお試ししてみる

インストールには、スタンドアローンk8s上で使う、2つモードがありますが、今回は、スタンドアローンを選択します。

実行環境は、GCPを利用し、以下の構成で行いました。

  • Ubuntu 18.04 LTS
  • GCE(vCPU x 4、メモリ 15 GB)
  • Rio v0.0.3

GCEでインスタンスの用意

GCE3インスタンスを「vCPU x 4、メモリ 15 GB」のスペックで用意。 OSは「Ubuntu 18.04 LTS」

※お試しなので、お安く上げるために、「可用性ポリシー」の項目を「プリエンプティブ ON」にします。
 これで、約$0.044/hour(us-east1)となります(お小遣い制の私にも優しい)。

Rioのインストール

Releases · rancher/rio より、実行ファイルをダウンロードして、展開し、PATHの通ったところに展開したものをコピー

# Rioをダウンロード
curl -L -o rio.tar.gz https://github.com/rancher/rio/releases/download/v0.0.3/rio-v0.0.3-linux-amd64.tar.gz

# 展開
tar xvf rio.tar.gz

# PATHの通った場所にコピー
sudo cp rio-v0.0.3-linux-amd64/rio /usr/local/bin/

Rio Serverの起動

yassan@rio01:~$ sudo rio server
INFO[0000] Starting Rio v0.0.3                          
INFO[0006] Creating CRD gateways.networking.istio.io    
INFO[0006] Creating CRD virtualservices.networking.istio.io 
INFO[0006] Waiting for CRD virtualservices.networking.istio.io to become available 
INFO[0007] Done waiting for CRD virtualservices.networking.istio.io to become available 
INFO[0007] Waiting for CRD gateways.networking.istio.io to become available 
INFO[0007] Done waiting for CRD gateways.networking.istio.io to become available 
INFO[0007] Creating CRD listenconfigs.space.cattle.io   
INFO[0007] Creating CRD services.rio.cattle.io          
INFO[0007] Creating CRD configs.rio.cattle.io           
INFO[0007] Waiting for CRD listenconfigs.space.cattle.io to become available 
INFO[0007] Creating CRD routesets.rio.cattle.io         
INFO[0007] Creating CRD volumes.rio.cattle.io           
INFO[0007] Creating CRD stacks.rio.cattle.io            
INFO[0008] Done waiting for CRD listenconfigs.space.cattle.io to become available 
INFO[0008] Listening on :7443                           
INFO[0008] Listening on :7080                           
INFO[0008] Client token is available at /var/lib/rancher/rio/server/client-token 
INFO[0008] Node token is available at /var/lib/rancher/rio/server/node-token 
INFO[0008] To use CLI: rio login -s https://XXXX:7443 -t XXXX::admin:XXXX 
INFO[0008] To join node to cluster: rio agent -s https://XXXX:7443 -t XXXX::node:XXXX 
INFO[0009] Agent starting, logging to /var/lib/rancher/rio/agent/agent.log 

これで起動。

起動ログに http: TLS handshake error from 127.0.0.1:44334: remote error: tls: bad certificate なんて出てますが、そっ閉じ。。。

Rio Serverに接続

今回は、スタンドアローンモードで実行するので、Agentのインストールはせずに、直接、起動中のServerへ接続します。 まずは、Serverへ接続しないと何もコマンドを受け付けません(rootでは別)。

接続の方法は、上記のRio Serverへアクセスした際に出ていたログ

 :
INFO[0008] Node token is available at /var/lib/rancher/rio/server/node-token 
INFO[0008] To use CLI: rio login -s https://XXXX:7443 -t XXXX::admin:XXXX     ←←←← ※コレ!
INFO[0008] To join node to cluster: rio agent -s https://XXXX:7443 -t XXXX::node:XXXX 
 :

rio login -s https://XXXX:7443 -t XXXX::admin:XXXX の部分を使います。 別のターミナルを開いて以下を実行。

$ rio login -s https://XXXX:7443 -t XXXX::admin:XXXX
INFO[0000] Log in successful
 :

カナリアリリースを試してみる

RioのREADMEにある Service Mesh をそのまま試してみます。 デプロイするアプリは、curlで叩くとHollo world返してくれる ibuildthecloud/demo を利用しています。

v1のdemoを3つのコンテナでScaleした状態にデプロイします。

yassan@rio01:~$ rio run -p 80/http --name test/svc --scale=3 ibuildthecloud/demo:v1
test-124a4837:svc

状態の確認

yassan@rio01:~$ rio ps
NAME       IMAGE                    CREATED         SCALE       STATE     ENDPOINT                                  DETAIL
test/svc   ibuildthecloud/demo:v1   8 seconds ago   (3/0/0)/3   pending   http://svc.test.g50yg5.lb.rancher.cloud   

と直後ではなっていますが、しばらくすると以下のようになります。

yassan@rio01:~$ rio ps
NAME       IMAGE                    CREATED              SCALE     STATE     ENDPOINT                                  DETAIL
test/svc   ibuildthecloud/demo:v1   About a minute ago   3         active    http://svc.test.g50yg5.lb.rancher.cloud   

ENDPOINTにcurlして状態を見てみます。

yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World

次にv3でデプロイしてみます。

yassan@rio01:~$ rio stage --image=ibuildthecloud/demo:v3 test/svc:v3
test-124a4837:svc

# Serviceの状態を確認(v1とv3の両方が存在しています)
yassan@rio01:~$ rio ps
NAME          IMAGE                    CREATED         SCALE     STATE     ENDPOINT                                     DETAIL
test/svc      ibuildthecloud/demo:v1   2 minutes ago   3         active    http://svc.test.g50yg5.lb.rancher.cloud      
test/svc:v3   ibuildthecloud/demo:v3   2 minutes ago   3         active    http://svc-v3.test.g50yg5.lb.rancher.cloud   
# Serviceの設定を確認
yassan@rio01:~$ rio export test
services:
  svc:
    image: ibuildthecloud/demo:v1
    ports:
    - 80/http
    revisions:
      v3:
        image: ibuildthecloud/demo:v3
        scale: 3
    scale: 3
# v3を確認
yassan@rio01:~$ curl http://svc-v3.test.g50yg5.lb.rancher.cloud
Hello World v3

では、準備が出来たところで、カナリア試します。 v1とv3を半々にしてみますます。

yassan@rio01:~$ rio weight test/svc:v3=50%
test-124a4837:svc

実際にcurlして確認してみます。

yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World
yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World v3
yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World
yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World
yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World v3

まぁおおよそ、半々出てますね!

では、v3を完全に反映させます。

yassan@rio01:~$ rio promote test/svc:v3
test-124a4837:svc

# Serviceの状態の確認(v3のENDPOINTがv1のときのものに変わってますね)
yassan@rio01:~$ rio ps
NAME       IMAGE                    CREATED         SCALE     STATE     ENDPOINT                                  DETAIL
test/svc   ibuildthecloud/demo:v3   5 minutes ago   3         active    http://svc.test.g50yg5.lb.rancher.cloud   

では、curlでも確認してみます。

yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World v3
yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World v3
yassan@rio01:~$ curl http://svc.test.g50yg5.lb.rancher.cloud
Hello World v3

ちゃんと反映出来ています。
如何でしたでしょうか。簡単なコマンドで実行が可能になっています。
本当なら、上図に描いたような構成を作ってみて、アクセス制御などもお試ししたいところですが、今回はここまで。

最後に

Rioは如何でしたでしょうか?

実は、Rio自体は内部にk8sを利用しています4
また、rio/vendor.confからも分かるように、k8s以外にも様々なものを内包しており、単体でここまで出来るのは面白い試みだと思います。

まだまだ、実装途中ではありますが、今後が楽しみです。

以上、16日目の記事でした。