在容器上执行 shell 命令
如需排查一些问题,您可能需要访问容器以直接在容器本身上执行命令。您可以通过 bash shell 或通过 PowerShell 使用 kubectl exec 命令访问容器。
- 使用 kubectl describe pods来查找您的集群中要连接的 Pod 的名称。在以下示例中,该命令列出了 suitecrm-0 pod。 kubectl describe pods | grep Name Name: suitecrm-0 
- 使用以下方法之一执行 shell 命令:
    - 使用 kubectl exec打开 bash 命令 shell,您可在其中执行命令。kubectl exec -it pod-name -- /bin/bash 以下示例获取了一个连接到 suitecrm-0 pod 的 shell: kubectl exec -it suitecrm-0 -- /bin/bash 
- 使用 kubectl exec直接执行命令。kubectl exec -it pod-name -- /bin/bash -c "command(s)" 以下示例列出了 suitecrm-0 pod 的根目录: kubectl exec -it suitecrm-0 -- /bin/bash -c "ls /" 
 
- 使用 
如需了解详情,请参阅 Kubernetes 文档。