Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't command line echo in Kubernetes Pod container show in logs

Consider this Kubernetes Pod:

# pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: testing123
spec:
  containers:
  - name: testing123
    image: busybox:latest
    command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']

If I deploy this Pod and run logs I see this:

$ kubectl apply -f pod.yaml
$ k logs testing123           
Hello, Kubernetes!

So far, so good. I now "login" to the Pod and run an echo command:

$ k exec -ti testing123 -- ash
/ # echo "Run after logging in."
Run after logging in.
/ # exit
$ k logs testing123           
Hello, Kubernetes!
$

Why didn't Run after logging in. appear in the logs output of the Pod?

like image 487
rlandster Avatar asked Nov 15 '25 09:11

rlandster


1 Answers

Containers logs are captured from their command line / entrypoint stdout and stderr.

When you enter a container (kubectl exec), you spawn a new process, with its own stdin/stdout/stderr.

like image 106
SYN Avatar answered Nov 17 '25 06:11

SYN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!