<p>Consider this Kubernetes Pod:</p>
<pre><code># pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: testing123
spec:
  containers:
  - name: testing123
    image: busybox:latest
    command: ['sh', '-c', 'echo &quot;Hello, Kubernetes!&quot; &amp;&amp; sleep 3600']
</code></pre>
<p>If I deploy this Pod and run <code>logs</code> I see this:</p>
<pre><code>$ kubectl apply -f pod.yaml
$ k logs testing123           
Hello, Kubernetes!
</code></pre>
<p>So far, so good. I now &quot;login&quot; to the Pod and run an echo command:</p>
<pre><code>$ k exec -ti testing123 -- ash
/ # echo &quot;Run after logging in.&quot;
Run after logging in.
/ # exit
$ k logs testing123           
Hello, Kubernetes!
$
</code></pre>
<p>Why didn't <code>Run after logging in.</code> appear in the logs output of the Pod?</p>

<p>Containers logs are captured from their command line / entrypoint stdout and stderr.</p>
<p>When you enter a container (kubectl exec), you spawn a new process, with its own stdin/stdout/stderr.</p>
