LoginSignup
0
0

More than 1 year has passed since last update.

oc debug コマンドで ROSA Node に遠隔ログインしてみた

Posted at

はじめに

今回は短い Tips ブログです。AWS で ROSA(Red Hat OpenShift Service on AWS) を動かしているときに、SSH でアクセスしたい気持ちになります。SSH 自体は出来ないのですが、oc debugkubectl debug コマンドで該当の Node へリモートアクセスすることが出来ます。今回は、その手順を紹介します。

oc コマンドは、kubectl コマンドと同じ機能を提供しており、さらに OpenShift リソースを扱えるようにしているコマンドです。次の URL に2つのコマンドの相違点が説明されています。
https://access.redhat.com/documentation/ja-jp/openshift_container_platform/3.11/html/cli_reference/cli-reference-differences-oc-kubectl

今回のリモートアクセスについては、どちらでもいいのですが、OpenShift になれるために oc コマンドでやっていきます。

oc debug コマンド

oc debug コマンドを実行することで、指定した Node でデバッグ用途の Pod が起動します。まずはやってみましょう。

node 一覧を確認します。

$ kubectl get nodes
NAME                                              STATUS   ROLES          AGE     VERSION
ip-10-0-129-250.ap-northeast-1.compute.internal   Ready    infra,worker   6h52m   v1.22.3+ffbb954
ip-10-0-150-162.ap-northeast-1.compute.internal   Ready    worker         7h8m    v1.22.3+ffbb954
ip-10-0-157-183.ap-northeast-1.compute.internal   Ready    master         7h17m   v1.22.3+ffbb954
ip-10-0-160-228.ap-northeast-1.compute.internal   Ready    infra,worker   6h52m   v1.22.3+ffbb954
ip-10-0-164-3.ap-northeast-1.compute.internal     Ready    worker         7h8m    v1.22.3+ffbb954
ip-10-0-168-81.ap-northeast-1.compute.internal    Ready    master         7h17m   v1.22.3+ffbb954
ip-10-0-201-136.ap-northeast-1.compute.internal   Ready    worker         7h8m    v1.22.3+ffbb954
ip-10-0-202-170.ap-northeast-1.compute.internal   Ready    master         7h17m   v1.22.3+ffbb954
ip-10-0-203-78.ap-northeast-1.compute.internal    Ready    infra,worker   6h52m   v1.22.3+ffbb954

今回は、Infrastructur Node にアクセスをしてみましょう。次の形式で、node の名前を指定します。

oc debug node/ip-10-0-129-250.ap-northeast-1.compute.internal

実行例

$ oc debug node/ip-10-0-129-250.ap-northeast-1.compute.internal
Starting pod/ip-10-0-129-250ap-northeast-1computeinternal-debug ...
To use host binaries, run `chroot /host`
Pod IP: 10.0.129.250
If you don't see a command prompt, try pressing enter.
sh-4.4#

Host 側のバイナリを利用するために、chroot /host コマンドを実行します。debug 用の Pod は、Host 側のディレクトリを /host にマウントしており、chroot で Root ディレクトリを切り替えます。

chroot /host

OS の詳細情報を確認できます

# cat /etc/redhat-release
Red Hat Enterprise Linux CoreOS release 4.9

systemctl も実行可能です。

# systemctl status kubelet
● kubelet.service - Kubernetes Kubelet
   Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/kubelet.service.d
           └─10-mco-default-env.conf, 10-mco-default-madv.conf, 20-aws-node-name.conf, 20-logging.conf
   Active: active (running) since Wed 2021-12-29 06:18:26 UTC; 7h ago
  Process: 1394 ExecStartPre=/bin/rm -f /var/lib/kubelet/memory_manager_state (code=exited, status=0/SUCCESS)
  Process: 1392 ExecStartPre=/bin/rm -f /var/lib/kubelet/cpu_manager_state (code=exited, status=0/SUCCESS)
  Process: 1390 ExecStartPre=/bin/mkdir --parents /etc/kubernetes/manifests (code=exited, status=0/SUCCESS)
 Main PID: 1396 (kubelet)
    Tasks: 22 (limit: 202228)
   Memory: 241.3M
      CPU: 31min 1.526s

psコマンド、top コマンドなど、ベーシックなコマンドが利用可能です。

参考URL

0
0
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
0
0