LoginSignup
10
7

More than 3 years have passed since last update.

IBM Cloud Shellを触ってみた

Last updated at Posted at 2020-06-25

1. はじめに

IBM Cloud ShellというIBM Cloud上で動くブラウザーベースのshell環境が提供されるようになったので、その特徴を紹介したいと思います。

2. IBM Cloud Shellの起動方法

IBM Cloud Portalのここから選ぶだけです。
image.png
image.png

3. 特徴

いくつか知っておくと便利な機能などを紹介します。

3.1 デフォルトの機能

  • (少なくともいまのところは)課金は発生しない。
  • インターネットにアクセスすることはできるが、各アカウントのPrivate NWには繋がっていない。
  • 各種コマンドがプリインストールされている。詳細は、こちらを参照。
  • 5つまでセッションが開ける
  • ワークスペース用ストレージ(500MB)はセッション間で共有されているだけでなく、同一ユーザーであればアカウントをまたがっても共有されている。
session1
xxxxxxx@cloudshell:~$ touch hoge
session2
xxxxxxx@cloudshell:~$ ls hoge
hoge

Your IBM Cloud Shell workspace includes 500 MB of temporary secure storage per region that you can access through your personal home directory, /home/. This storage space is provided at the user level rather than the account level. This means that only you can access your storage, and you can access it from any of your accounts. No one else in your accounts can access your workspace storage.

3.2 Locationの選択

IBM Cloud Shellが内部的に動く場所を明示的に選択できます。一応アクセスしている環境によって自動選択されるらしいので、日本のユーザーであればTokyoが選択されるでしょう。今は、Dallas/Frankfurt/Tokyoが選択できるようです。
image.png

image.png

3.3 ローカル端末からのファイルのアップロード・ダウンロード

IBM Cloud Shellはインターネットに繋がっているため、インターネット上のファイルサーバーにアクセスすることでファイルをダウンロードすることができますが、ローカル端末から直接ファイルをアップロードすることが可能です。もちろんIBM Cloud Shell上の環境からローカル端末にファイルをダウンロードすることも可能です。
image.png

3.4 ローカルで稼働するサービスアクセスする方法

IBM Cloud Shell上に例えばnode.jsやapacheなどでローカルWeb Serviceを立てておくと、このpreview on portの機能でアクセスすることができます。

Webサーバーを作成
xxxxxxx@cloudshell:~$ git clone https://github.com/IBM/nodejs-express-app.git
xxxxxxx@cloudshell:~$ cd nodejs-express-app
xxxxxxx@cloudshell:~/nodejs-express-app$ npm install
xxxxxxx@cloudshell:~/nodejs-express-app$ npm run start

> nodejsexpressapp@1.0.0 start /home/shiyasu/nodejs-express-app
> node server/server.js

App UI available http://localhost:3000
Swagger UI available http://localhost:3000/swagger/api-docs

  • Port 3000を選択する
    image.png
  • サービスが表示された
    image.png

  • (この稼動確認の後、cloud foundryにpushするなどの作業を行うことが可能)

3.5 リモートで稼働するサービスにアクセスする方法

ssh port forwardingを利用したり、kubectl port-forwardoc port-forwardなどを利用すれば、リモート環境で動いているサービスをローカルポートにアクセスすることで転送されるようになります。これを前節のようにIBM Cloud Shell経由でアクセスすれば、例えばリモート環境で動いているPodに対して、直接利用者端末のブラウザから稼働確認することができます。。
https://cloud.ibm.com/docs/cloud-shell?topic=cloud-shell-preview-apps#preview-kube-cluster

session1(ローカルポート3000をリモートポート8080に転送)
xxxxxxx@cloudshell:~$ oc get pods -n syasuda
NAME                                       READY   STATUS      RESTARTS   AGE
nodejs-ex-1-build                          0/1     Completed   0          15d
nodejs-ex-649bd6778d-wrznm                 1/1     Running     0          15d

xxxxxxx@cloudshell:~$ oc port-forward pod/nodejs-ex-649bd6778d-wrznm -n syasuda 3000:8080
Forwarding from 127.0.0.1:3000 -> 8080
Forwarding from [::1]:3000 -> 8080
session2(ローカルポート3000にアクセスすると、リモートサービスに接続される)
xxxxxxx@cloudshell:~$ ss -anpt|grep 3000
LISTEN     0      0      127.0.0.1:3000                     *:*                   users:(("oc",pid=305,fd=7))
LISTEN     0      0          ::1:3000                    :::*                   users:(("oc",pid=305,fd=8))

xxxxxxx@cloudshell:~$ curl -I http://localhost:3000
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 40430
ETag: W/"9dee-3nm2OJV/pDUlKWUTQSk1Z/pOG6E"
Date: Fri, 26 Jun 2020 00:09:56 GMT
Connection: keep-alive
  • Port 3000を選択すると・・・
    image.png
  • Podに直接アクセスできた!
    image.png

4. 注意点

10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7