Update the document to follow v1.18.

pull/24869/head
hideUW 2020-08-23 21:42:39 -07:00 committed by inductor
parent acea56b17a
commit ae2fedaf19
1 changed files with 36 additions and 27 deletions

View File

@ -43,7 +43,7 @@ kubectl get pod shell-demo
実行中のコンテナへのシェルを取得します: 実行中のコンテナへのシェルを取得します:
```shell ```shell
kubectl exec -it shell-demo -- /bin/bash kubectl exec --stdin --tty shell-demo -- /bin/bash
``` ```
{{< note >}} {{< note >}}
@ -54,23 +54,25 @@ kubectl exec -it shell-demo -- /bin/bash
シェル内で、ルートディレクトリーのファイル一覧を表示します: シェル内で、ルートディレクトリーのファイル一覧を表示します:
```shell ```shell
root@shell-demo:/# ls / # このコマンドをコンテナ内で実行します
ls /
``` ```
シェル内で、他のコマンドを試しましょう。以下がいくつかの例です: シェル内で、他のコマンドを試しましょう。以下がいくつかの例です:
```shell ```shell
root@shell-demo:/# ls / # これらのサンプルコマンドをコンテナ内で実行することができます
root@shell-demo:/# cat /proc/mounts ls /
root@shell-demo:/# cat /proc/1/maps cat /proc/mounts
root@shell-demo:/# apt-get update cat /proc/1/maps
root@shell-demo:/# apt-get install -y tcpdump apt-get update
root@shell-demo:/# tcpdump apt-get install -y tcpdump
root@shell-demo:/# apt-get install -y lsof tcpdump
root@shell-demo:/# lsof apt-get install -y lsof
root@shell-demo:/# apt-get install -y procps lsof
root@shell-demo:/# ps aux apt-get install -y procps
root@shell-demo:/# ps aux | grep nginx ps aux
ps aux | grep nginx
``` ```
## nginxのルートページへの書き込み ## nginxのルートページへの書き込み
@ -81,25 +83,31 @@ Podの設定ファイルを再度確認します。Podは`emptyDir`ボリュー
シェル内で、`/usr/share/nginx/html`ディレクトリに`index.html`を作成します。 シェル内で、`/usr/share/nginx/html`ディレクトリに`index.html`を作成します。
```shell ```shell
root@shell-demo:/# echo Hello shell demo > /usr/share/nginx/html/index.html # このコマンドをコンテナ内で実行します
echo 'Hello shell demo' > /usr/share/nginx/html/index.html
``` ```
シェル内で、nginxサーバーにGETリクエストを送信します: シェル内で、nginxサーバーにGETリクエストを送信します:
```shell ```shell
root@shell-demo:/# apt-get update # これらのコマンドをコンテナ内のシェルで実行します
root@shell-demo:/# apt-get install curl apt-get update
root@shell-demo:/# curl localhost apt-get install curl
curl http://localhost/
``` ```
出力に`index.html`ファイルに書き込んだ文字列が表示されます: 出力に`index.html`ファイルに書き込んだ文字列が表示されます:
```shell ```
Hello shell demo Hello shell demo
``` ```
シェルを終了する場合、`exit`を入力します。 シェルを終了する場合、`exit`を入力します。
```shell
exit # コンテナ内のシェルを終了する
```
## コンテナ内での各コマンドの実行 ## コンテナ内での各コマンドの実行
シェルではない通常のコマンドウインドウ内で、実行中のコンテナの環境変数の一覧を表示します: シェルではない通常のコマンドウインドウ内で、実行中のコンテナの環境変数の一覧を表示します:
@ -111,9 +119,9 @@ kubectl exec shell-demo env
他のコマンドを試します。以下がいくつかの例です: 他のコマンドを試します。以下がいくつかの例です:
```shell ```shell
kubectl exec shell-demo ps aux kubectl exec shell-demo -- ps aux
kubectl exec shell-demo ls / kubectl exec shell-demo -- ls /
kubectl exec shell-demo cat /proc/1/mounts kubectl exec shell-demo -- cat /proc/1/mounts
``` ```
@ -123,20 +131,21 @@ kubectl exec shell-demo cat /proc/1/mounts
## Podが1つ以上のコンテナを持つ場合にシェルを開く ## Podが1つ以上のコンテナを持つ場合にシェルを開く
Podが1つ以上のコンテナを持つ場合、`--container`か`-c`を使用して、`kubectl exec`コマンド内でコンテナを指定します。 Podが1つ以上のコンテナを持つ場合、`--container`か`-c`を使用して、`kubectl exec`コマンド内でコンテナを指定します。
例えば、my-podという名前のPodがあり、そのPodがmain-appとhelper-appという2つのコンテナを持つとします。 例えば、my-podという名前のPodがあり、そのPodが _main-app_ _helper-app_ という2つのコンテナを持つとします。
以下のコマンドはmain-appのコンテナへのシェルを開きます。 以下のコマンドは _main-app_ のコンテナへのシェルを開きます。
```shell ```shell
kubectl exec -it my-pod --container main-app -- /bin/bash kubectl exec -i -t my-pod --container main-app -- /bin/bash
``` ```
{{< note >}}
ショートオプションの `-i``-t` は、ロングオプションの `--stdin``--tty` と同様です。
{{< /note >}}
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
* [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec) * [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec)について読む。