0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure Kubernetes Serviceにおいて特定のノード・コンテナ内でコマンドを実行する方法

Posted at

はじめに

Azure Kubernetes Service(以下、AKS)のネットワーク内部構造を検証していた時にAKSの特定のノードや特定のポッド内のコンテナに対してnetnsやipコマンドを実行したい場面があったので方法を調べてみました。

今回のように検証用だけでなく実運用においても障害時等の情報取得にも使えると思いますので、以下に整理します。

特定のノード内でコマンドを実行する

[node name]で指定したNode内で特権コンテナを起動する

kubectl debug node/[node name] -it --image=mcr.microsoft.com/dotnet/runtime-deps:6.0

出力例(node nameに” aks-nodepool1-67404889-vmss000006 “を指定した場合)

Creating debugging pod node-debugger-aks-nodepool1-67404889-vmss000006-xsg6g with container debugger on node aks-nodepool1-67404889-vmss000006.
If you don't see a command prompt, try pressing enter.
root@aks-nodepool1-67404889-vmss000006:/# hostname
aks-nodepool1-67404889-vmss000006

ルートディレクトリの変更

chroot /host

以降、node nameで指定したNode内でコマンド実行が可能になる。

(作業後)特権コンテナの削除

kubectl delete pod node-debugger-aks-nodepool1-67404889-vmss000006-xsg6g

補足

検証時は、特権コンテナ起動のイメージは「mcr.microsoft.com/dotnet/runtime-deps:6.0」でしたが、MSLearnの記事が更新されて今は以下のコマンドが最新のようですね。

kubectl debug node/[node name] -it --image=mcr.microsoft.com/cbl-mariner/busybox:2.0

特定のPodのContainer内でコマンドを実行する

[pod name]で指定したPodの[container name]で指定したcontainer内で[command] を実行する

kubectl exec -it [pod name] --container [container name] – [command]

出力例(commandに” ip link “を指定した場合)

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
 qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0@if16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT g
roup default 
    link/ether 32:c0:4d:25:d1:7d brd ff:ff:ff:ff:ff:ff link-netnsid 0

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?