(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【OpenShift】プロジェクトを作成してアプリケーションを起動する(前編)

スポンサーリンク

はじめに

以下の環境にてminishiftを利用してプロジェクト作成→アプリケーションを生成する流れについて説明しました。

  • openshift v3.11
  • Cygwin

尚、minishiftは起動中及びocコマンドを利用できる状況を想定しています。

事前準備


まず始めにocコマンドにてsystemユーザでログインを試みます。

$ oc.exe login -u system
Server [https://localhost:8443]:

そうすると上の出力結果が返ってきて入力待ちになります。

ここでOpenShiftのサーバのIPを指定します。以下にてブラウザに入力したIPアドレスとポート番号です。

入力を間違えば以下のようなエラーとなります。

error: dial tcp: lookup xxx: no such host - verify you have provided
the correct host and port and that the server is currently running.

以下のように正しい接続先サーバを指定すると

$ oc.exe login -u system
Server [https://localhost:8443]: 192.168.99.100:8443
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could
be intercepted by others.
Use insecure connections? (y/n): y

以下のようにパスワードを求められるので「admin」を入力するとログインに成功します。

Authentication required for https://192.168.99.100:8443 (openshift)
Username: system
Password:
Login successful.

You don't have any projects. You can try to create a new project, by running
    oc new-project <projectname>
Welcome! See 'oc help' to get started.

上記のように新しいプロジェクト作成を促されます。

この状態でoc statusを行っても同様のメッセージが表示されます。

$ oc.exe status
You don't have any projects. You can try to create a new project, by running
    oc new-project <projectname>

プロジェクトを作成する

先ほどの標準出力の構文に沿って以下のようにプロジェクトを作成します。

$ oc new-project hoge
Now using project "hoge" on server "https://192.168.99.100:8443".

You can add applications to this project with the 'new-app' command. For example
, try:
    oc new-app centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git
to build a new example application in Ruby.

プロジェクトが作成されたので、次はアプリケーションの追加が促されます。

systemユーザでログインしたブラウザにて確認すると確かに作成したプロジェクトが確認できます。

f:id:mtiit:20200204125400p:plain
プロジェクトが新規作成されている

アプリケーションを追加する

こちらも標準出力に表示されていたサンプル文をそのまま実行します。ただし、ラベル名は-l name=で付与しました。

$ oc new-app centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git -l name=ruby_test
...
    Tags: builder, ruby, ruby25, rh-ruby25
...
--> Creating resources with label name=ruby_test ...
    imagestream.image.openshift.io "ruby-25-centos7" created
    imagestream.image.openshift.io "ruby-ex" created
    buildconfig.build.openshift.io "ruby-ex" created
    deploymentconfig.apps.openshift.io "ruby-ex" created
    service "ruby-ex" created
...

作成後にブラウザ上を見ると確かにアプリケーションがPodsという形で作成されています。

f:id:mtiit:20200204130442p:plain
rubyのPodsが作成されている

リソースの確認

以下コマンドにてPodsを確認できます。

$ oc get pods
NAME              READY     STATUS     RESTARTS   AGE
ruby-ex-1-build   0/1       Init:0/2   0          5s

以下コマンドにてプロジェクト名

$ oc project
Using project "hoge" on server "https://192.168.99.100:8443".

以下コマンドでプロジェクトの状態を確認できます。

$ oc status
In project hoge on server https://192.168.99.100:8443

svc/ruby-ex - 172.30.35.240:8080
 dc/ruby-ex deploys istag/ruby-ex:latest <-
 bc/ruby-ex source builds ...
 build #1 running ...
 deployment #1 waiting on image or update
...

終わりに

本記事では

  • プロジェクトの作成
  • アプリケーションの追加
  • リソースの確認

の流れを確認しました。

後続の流れは上の記事に分割してます。