<p>Running a deployment with three pod.</p>

<pre><code>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:    &lt;none&gt;
    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
</code></pre>

<p>The only one pod container I can connect is zipkin with <code>kubectl exec -it my-api-XXX -- /bin/bash</code>.</p>

<p>If I want to access the my-api container using <code>kubectl exec -it my-api-XXX -c &lt;my-api container ID&gt; -- /bin/bash</code>.</p>

<p>It report a error show the container is not in that pod.</p>

<blockquote>
  <p>Error from server (BadRequest): container my-api_containerID is not valid for pod my-api-XXX</p>
</blockquote>

ccd
<blockquote>
  <p>kubectl exec -it "pod-name" -c "container-name" -n "namespace"</p>
</blockquote>

<p>Here only the container name is needed. In your case it will be:</p>

<blockquote>
  <p>kubectl exec -it my-api-XXX -c my-api  -- /bin/bash</p>
</blockquote>

<p>You can exec to Zipkin because <code>exec</code> is taking zipkin as the default container.</p>
