【问题标题】:Kubectl exec to the specific container in deploymentKubectl exec 到部署中的特定容器
【发布时间】:2020-02-17 16:53:24
【问题描述】:

使用三个 pod 运行部署。

NAME                        READY   STATUS    RESTARTS   AGE
my-api-XXX                  3/3     Running   0          4h

Containers:
  zipkin:
    Container ID:   docker://XXX
    Image:          openzipkin/zipkin:2.11
    Image ID:       docker-pullable://openzipkin/zipkin@sha256:XXX
    Port:           8611/TCP
    Host Port:      8611/TCP
    State:          Running
      Started:      Mon, 17 Feb 2020 12:13:03 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      XXX
  my-api:
    Container ID:   docker://XXX
    Image:          XXX
    Image ID:       XXX
    Ports:          5000/TCP, 6000/TCP
    Host Ports:     5000/TCP, 6000/TCP
    State:          Running
      Started:      Mon, 17 Feb 2020 12:13:04 +0800
    Ready:          True
    Restart Count:  0
    Mounts:
      XXX
  my-metrics:
    Container ID:   docker://XXX
    Image:          XXX
    Image ID:       XXX
    Ports:          5001/TCP, 6001/TCP
    Host Ports:     5001/TCP, 6001/TCP
    State:          Running
      Started:      Mon, 17 Feb 2020 12:13:04 +0800
    Ready:          True
    Restart Count:  0
    Environment:
      XXX
    Mounts:
      XXX

我可以连接的唯一一个 pod 容器是带有 kubectl exec -it my-api-XXX -- /bin/bash 的 zipkin。

如果我想使用 kubectl exec -it my-api-XXX -c &lt;my-api container ID&gt; -- /bin/bash 访问 my-api 容器。

它报告一个错误,表明容器不在那个 pod 中。

来自服务器的错误 (BadRequest):容器 my-api_containerID 对 pod my-api-XXX 无效

【问题讨论】:

    标签: kubernetes kubectl


    【解决方案1】:

    kubectl exec -it "pod-name" -c "container-name" -n "namespace"

    这里只需要容器名称。在您的情况下,它将是:

    kubectl exec -it my-api-XXX -c my-api -- /bin/bash

    您可以执行到 Zipkin,因为 exec 将 zipkin 作为默认容器。

    【讨论】:

      猜你喜欢
      • 2022-12-17
      • 2017-02-20
      • 1970-01-01
      • 2022-01-18
      • 2018-10-06
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 2020-08-04
      相关资源
      最近更新 更多