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?
CodePudding user response:
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.