<p>I have one deployment which has two containers.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: ol000dep
spec:
  selector:
    matchLabels:
      app: ol000kube
  replicas : 2
  template:
    metadata:
      labels:
        app: ol000kube
    spec:
      containers:
        - name: django
          image: django:local
          ports:
          - containerPort: 8011
      containers:
        - name: nginx
          image: nginx:local
          ports:
          - containerPort: 80
</code></pre>
<p>This makes two replicad pods, and on my understanding, each pod has two containers.</p>
<pre><code>kubectl get pods      
NAME                       READY   STATUS    RESTARTS   AGE
ol000dep-bc96bfc98-r9lrj   1/1     Running   0          21m
ol000dep-bc96bfc98-t6flw   1/1     Running   0          21m
</code></pre>
<p>Now I can login</p>
<pre><code>kubectl exec -it ol000dep-bc96bfc98-r9lrj  /bin/bash
</code></pre>
<p>Then, I wonder,</p>
<p>Is this login in a Pod not a Container??</p>
<p>If so ,how can I select the container I want to login?</p>

<p>Interesting. Even though the yaml you provided is incorrect (<code>.spec.containers</code> map key must be <strong>unique</strong>), k8s seems to be fine with that.</p>
<p>In your case the pod is started with <strong>only</strong> the second container (name: nginx) in it though.</p>
<blockquote>
<p>Is this login in a Pod not a Container??</p>
</blockquote>
<p><strong>Container.</strong></p>
<p>So, with  <code>kubectl exec -it ol000dep-bc96bfc98-r9lrj /bin/bash</code>, you login/exec into the nginx container.</p>
<p>After correcting the yaml, two containers would be started in the pod and you can log into the desired container via its name (e.g. <code>name: django</code>) using the <code>-c / --container</code> parameter.</p>
<pre class="lang-yaml prettyprint-override"><code>...
      containers:
        - name: django
          image: django:local
          ports:
          - containerPort: 8011
        - name: nginx
          image: nginx:local
          ports:
          - containerPort: 80
</code></pre>
<p>login:</p>
<pre><code>kubectl exec -it POD_NAME -c CONTAINER_NAME -- /bin/bash 
</code></pre>
<p>Note that if you do not specify the name of the container (by omitting <code>-c CONTAINER_NAME</code>), you will login into the first defined container by default (in your case <code>django</code>).</p>
