Pod は k8s のデプロイ可能な最小単位。複数のコンテナから成り立つ。kubectl exec -it [pod名] [command]
だと、デフォルトのコンテナに接続されてしまう。
$ kubectl exec -it samplepod /bin/sh Defaulting container name to busybox1. Use 'kubectl describe pod/samplepod -n default' to see all of the containers in this pod.
-c
オプションを使うと任意のコンテナにexec
できる。(kubectl exec -it -c [container_name] [command]
)
$ kubectl exec -it samplepod -c busybox1 /bin/sh / # exit $ kubectl exec -it samplepod -c busybox2 /bin/sh / # exit
以上。まあ、そもそも基本的には 1コンテナ = 1Pod らしい。
単一のコンテナを稼働させるPod : いわゆる「1Pod1コンテナ」 構成のモデルは、最も一般的なKubernetesのユースケースです。 このケースでは、ユーザーはPodを単一のコンテナのラッパーとして考えることができ、Kubernetesはコンテナを直接扱うというよりは、Podを管理することになります。
引用元: Podについての概観(Pod Overview) - Kubernetes
Pod 内にいろいろ詰め込みたいのはどういうときか、は、以下が参考になりそうです。今後勉強します。サイドカーパターンとかそういうあれですかね。
Podについての概観(Pod Overview) - Kubernetes
いちおう環境
$ kubectl version Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89", GitTreeState:"clean", BuildDate:"2020-01-18T23:30:10Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:07:13Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
コンテナ名はkubectl describe
で表示できる。
$ kubectl describe pods samplepod Name: samplepod Namespace: default Priority: 0 Node: ip-172-30-0-112/172.30.0.112 Start Time: Wed, 19 Feb 2020 08:27:18 +0000 Labels: <none> Annotations: cni.projectcalico.org/podIP: 192.168.130.40/32 Status: Running IP: 192.168.130.40 IPs: IP: 192.168.130.40 Containers: busybox1: Container ID: docker://6b63ee58ff319268f388605b40604b7212e7c1d945dc2fee997b368e1674d390 Image: busybox:musl Image ID: docker-pullable://busybox@sha256:7fe0cb3632d9ea7b2a9ab4427e339e01f7cdfeff50674804cb8946664976c610 Port: <none> Host Port: <none> State: Running Started: Wed, 19 Feb 2020 08:27:19 +0000 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-ddwc9 (ro) busybox2: Container ID: docker://ba8c7e71fd500ce8ad0a0b641c85b9ac3903f57c53e82471494bd1bac4f8281d Image: busybox:musl Image ID: docker-pullable://busybox@sha256:7fe0cb3632d9ea7b2a9ab4427e339e01f7cdfeff50674804cb8946664976c610 Port: <none> Host Port: <none> State: Running Started: Wed, 19 Feb 2020 08:27:20 +0000 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-ddwc9 (ro)