您可以使用 kubectl get pods
命令来列出 Kubernetes 集群中的所有 Pod。此外,您可以使用 kubectl describe pod <pod_name>
命令来查看有关特定 Pod 的详细信息,包括它所属的容器。
要查看一个 Pod 中运行的容器,请执行以下步骤:
- 使用
kubectl get pods
命令获取要查看的 Pod 的名称。 - 运行命令
kubectl describe pod <pod_name>
,其中<pod_name>
是要查看其容器列表的 Pod 的名称。 - 在输出中找到 “Containers” 部分,该部分将列出当前在该 Pod 中运行的所有容器。
例如,如果您想查看名为 “nginx-deployment-xxxxx” 的 nginx Pod 中正在运行哪些容器,则可以运行以下命令:
kubectl describe pod nginx-deployment-xxxxx
这将显示该 Pod 的详细信息。在输出中找到 “Containers” 部分即可查看它所属的容器。