SUSE Support

Here When You Need Us

[JP] How to troubleshoot using the namespace of a container

This document (000020069) is provided subject to the disclaimer at the end of this document.

Situation

背景

問題をトラブルシューティングする場合、発生した問題と一致する再現環境が必要です。ただしコンテナー環境を利用する場合では、コンテナー内でツールとシェル環境が簡単に利用できない可能性があり再現環境の構築が困難になります。

手順

上記の課題を解決するために以下二つの手順があります。

Sidecar container を利用

問題を持つコンテナーが属するNamespaceで新しいsidecarコンテナーを実行すると、このsidecarコンテナーを用いてトラブルシュッティングすることができます。

sidecarコンテナーは、親コンテナーと同じVolumeをAttachしながら、同じNetworkとPIDのNamespaceを使用して起動できます。

  • トラブルシューティングするContainerのIDまたは名前を設定します。

ID=<container ID or name>

  • 同じNetwork、PIDのNamespaceとVolumeを使用しsidecarコンテナーを実行します。

docker run -it --net=container:$ID --pid=container:$ID --volumes-from=$ID alpine sh

  • これから問題があるcontainerやPodと同じコンテキスト内で、alpineコンテナーのコマンドでトラブルシュッティングをすることができます。

例えば、Podにネットワークの問題が発生した場合、Sidecar Containerに入り、コマンドを実行しながらネットワーク環境の設定を確認したりトラブルシュッティングすることができます。

必要に応じて、alpine containerを別のイメージを置き換えてください。

親コンテナーと同じVolumeをAttachできますが、親コンテナーのRead/Writeレイヤのアクセスはできません。同じファイルシステムをアクセスしたい場合は下記のnsenterの例をご参考ください。

nsenter を利用

nsenterコマンドを使用して、ノード上で利用可能なコマンドを使用できます。nsenterコマンドは、ほとんどのLinuxディストリビューションでデフォルト的にインストールされています。たとえば、Ubuntuでは、util-linuxパッケージによって提供されます。

  • トラブルシューティングするContainerのIDまたは名前を設定します。

ID=<container ID or name>

  • Container内の初めてのプロセス(PID 1)の番号を取得します。

PID=$(docker inspect --format '{{ .State.Pid }}' $ID)

  • nsenterを使ってContainer/Podの全種類のNamespaceで、ノード上のコマンドを実行することができます。

nsenter -a -t $PID <command>

例えば、ネットワークの問題をトラブルシュッティングする時、ノード上にあるコマンド、tcpdump、curl、digやmtrなどが使用可能になります。

-a パラメータは最近のnsenterで利用可能だが、もしこのパラメータが使えなかったら、単独のNamespaceに入るようにパラメータをしてしてください。詳細についてはnsenter --helpをご参考ください。

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:000020069
  • Creation Date: 06-May-2021
  • Modified Date:06-May-2021
    • SUSE Rancher

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.