Openshift-cli

提供:Dev Guides
移動先:案内検索

OpenShift-CLI

OpenShift CLIは、コマンドラインからOpenShiftアプリケーションを管理するために使用されます。 OpenShift CLIには、エンドツーエンドのアプリケーションライフサイクルを管理する機能があります。 一般的に、OpenShiftと通信するためにOpenShiftクライアントであるOCを使用します。

OpenShift CLIセットアップ

別のオペレーティングシステムでOCクライアントをセットアップするには、異なる一連の手順を実行する必要があります。

Windows用OCクライアント

  • ステップ1 *-次のリンクからoc cliをダウンロードしますhttps://github.com/openshift/origin/releases/tag/v3.6.0-alpha.2
  • ステップ2 *-マシン上のターゲットパスでパッケージを解凍します。
  • ステップ3 *-システムのパス環境変数を編集します。
C:\Users\xxxxxxxx\xxxxxxxx>echo %PATH%

C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files
(x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files
(x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\
v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files
(x86)\ATI Technologies\ATI.ACE\C

ore-Static;C:\Program Files\Intel\Intel(R) Management Engine
Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine
Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
  • ステップ4 *-WindowsでOCセットアップを検証します。
C:\openshift-origin-client-tools-v3.6.0-alpha.2-3c221d5-windows>oc version
oc v3.6.0-alpha.2+3c221d5
kubernetes v1.6.1+5115d708d7
features: Basic-Auth

Mac OS X用OCクライアント

Windowsと同じ場所にMac OSセットアップバイナリをダウンロードし、後でその場所で解凍し、環境のPATH変数で実行可能ファイルのパスを設定できます。

あるいは

Home brewを使用して、次のコマンドを使用してセットアップできます。

$ brew install openshift-cli

Linux用OCクライアント

同じページの下に、インストールに使用できるLinuxインストール用のtarファイルがあります。 後で、その特定の実行可能場所を指すパス変数を設定できます。

https://github.com/openshift/origin/releases/tag/v3.6.0-alpha.2

次のコマンドを使用して、tarファイルを解凍します。

$ tar –xf < path to the OC setup tar file >

次のコマンドを実行して、認証を確認します。

C:\openshift-origin-client-tools-v3.6.0-alpha.2-3c221d5-windows>oc login
Server [https://localhost:8443]:

CLI構成ファイル

OC CLI構成ファイルは、複数のOpenShiftサーバー接続と認証メカニズムを管理するために使用されます。 この構成ファイルは、複数のプロファイルを保存および管理し、それらを切り替えるためにも使用されます。 通常の構成ファイルは次のようになります。

$ oc config view
apiVersion: v1
clusters:
   - cluster:
      server: https://vklnld908.int.example.com
   name: openshift

contexts:
- context:
   cluster: openshift
   namespace: testproject
   user: alice
   name: alice
current-context: alice
kind: Config
preferences: {}
users:
- name: vipin
   user:
      token: ZCJKML2365jhdfafsdj797GkjgjGKJKJGjkg232

CLIクライアントのセットアップ

ユーザー資格情報の設定用

$ oc config set-credentials <user_nickname>
[--client-certificate = <path/to/certfile>] [--client-key=<path/to/keyfile>]
[--token = <bearer_token>] [--username = <basic_user>] [--password = <basic_password>]

クラスターの設定用

$ oc config set-cluster <cluster_nickname> [--server = <master_ip_or_fqdn>]
[--certificate-authority = <path/to/certificate/authority>]
[--api-version = <apiversion>] [--insecure-skip-tls-verify = true]

$ oc config set-credentials vipin --token = ZCJKML2365jhdfafsdj797GkjgjGKJKJGjkg232

コンテキストの設定用

$ oc config set-context <context_nickname> [--cluster = <cluster_nickname>]
[--user = <user_nickname>] [--namespace = <namespace>]

CLIプロファイル

単一のCLI構成ファイルには、複数のプロファイルを含めることができます。各プロファイルには異なるOpenShiftサーバー構成があり、後で異なるCLIプロファイル間の切り替えに使用できます。

apiVersion: v1
clusters: --→ 1
- cluster:
   insecure-skip-tls-verify: true
   server: https://vklnld908.int.example.com:8443
   name: vklnld908.int.example.com:8443
- cluster:
   insecure-skip-tls-verify: true
   server: https://vklnld1446.int.example.com:8443
   name: vklnld1446.int.example.com:8443
contexts: ---→ 2
- context:
   cluster: vklnld908.int.example.com:8443
   namespace: openshift-project
   user: vipin/vklnld908.int.example.com:8443
   name: openshift-project/vklnld908.int.example.com:8443/vipin
- context:
   cluster: vklnld908.int.example.com:8443
   namespace: testing-project
   user: alim/vklnld908.int.example.com:8443
   name: testproject-project/openshift1/alim
current-context: testing-project/vklnld908.int.example.com:8443/vipin - 3
kind: Config
preferences: {}

users:
- name: vipin/vklnld908.int.example.com:8443
user: ---→ 4
   token: ZCJKML2365jhdfafsdj797GkjgjGKJKJGjkg232

上記の構成では、OpenShiftマスターマシンの2つのインスタンスを定義するクラスターから始まる4つの主要なセクションに分かれています。 2番目のコンテキストセクションでは、vipinおよびalimという2つのコンテキストを定義します。 現在のコンテキストは、現在使用されているコンテキストを定義します。 ここで定義を変更すると、他のコンテキストまたはプロファイルに変更できます。 最後に、ユーザー定義とその認証トークンが定義されます。これは、この例ではvipinです。

使用中の現在のプロファイルを確認したい場合、それを使用して行うことができます-

$ oc status
oc status
In project testing Project (testing-project)
$ oc project
Using project "testing-project" from context named "testing-
project/vklnld908.int.example.com:8443/vipin" on server "https://vklnld908.int.example.com:8443".

他のCLIに切り替えたい場合は、次のコマンドを使用してコマンドラインから実行できます。

$ oc project openshift-project
Now using project "Openshift-project" on server "
https://vklnld908.int.example.com:8443".

上記のコマンドを使用して、プロファイルを切り替えることができます。 構成を表示したい場合は、いつでも$ oc config viewコマンドを使用できます。