LoginSignup
10
7

More than 3 years have passed since last update.

Red Hat OpenShift on IBM Cloud: OpenShiftクラスターにコマンド一発でログインする方法

Last updated at Posted at 2020-06-28

1. はじめに

Red Hat OpenShift on IBM CloudのOpenShiftクラスターにocコマンドでログインするために、毎回IBM Cloud PortalにログインしてToken情報取得してるわー、Tokenがタイムアウトする度にこの作業するのは面倒だわーっていう人に向けての記事です。APIキーを事前に取得しておけばこういう作業は都度必要なくなります。

  • IBM Cloud PortalにログインしてOpenShiftクラスターの画面に移動し、Token情報を発行する
    image.png
  • 以下の画面からコピペ
    image.png

2. 事前準備

要はここに記載があります。

APIキーを取得する。このキーは2度と発行されることはないのでメモしておく。
$ ibmcloud iam api-key-create myAPIKey
Creating API key myAPIKey under xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx as xxxxxxx@xx.xxx.xxx...
OK
API key myAPIKey was created

Please preserve the API key! It cannot be retrieved after it's created.

ID            ApiKey-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Name          myAPIKey
Description
Created At    2020-05-02T05:36+0000
API Key       <API Key>
Locked        false
.bashrcに環境変数に保管し、有効化する
$ vi .bashrc
export APIKEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
alias oclogin="oc login -u apikey -p $APIKEY"

$ . .bashrc

3. はじめてOpenShiftクラスターにログインする際の設定

IBMCloudにAPIKeyを使ってログインし、クラスター構成情報を事前に取得しておく
$ ibmcloud login --apikey $APIKEY
API endpoint: https://cloud.ibm.com
Region: us-south
Authenticating...
OK

Targeted account IBM (yyyyyyyyyyyyyyyyy) <-> zzzzzzz


API endpoint:      https://cloud.ibm.com
Region:            us-south
User:              xxxxxxx@xx.xx.xx
Account:           IBM (yyyyyyyyyyyyyyyyy) <-> zzzzzzz
Resource group:    No resource group targeted, use 'ibmcloud target -g RESOURCE_GROUP'
CF API endpoint:
Org:
Space:

$ ibmcloud oc cluster config -c myrokscluster43
OK
The configuration for myrokscluster43 was downloaded successfully.

Added context for myrokscluster43 to the current kubeconfig file.
You can now execute 'kubectl' commands against your cluster. For example, run 'kubectl get nodes'.

4. OpenShiftクラスターへのログイン方法

$ oclogin
Login successful.

You have access to 67 projects, the list has been suppressed. You can list all projects with 'oc projects'

Using project "syasuda".
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