I use this kubectl
to deploy a pod with the image nginx:
kubectl create deployment --image=<image-name-1.0> image-app
Now I want to update this pod with image=<image-name-2.0>
and run this command:
kubectl create deployment --image=<image-name-2.0> image-app
My question is: will the old pod log be updated after updating with image-name-2.0?
Can I see all history logs? I mean the both of them.
2
Answers
To be precise, there isn’t a "pod log" but container log, and you can use
kubectl logs --previous <pod name> -c <container name>
to retrieve logs from a previous container.A side note to update image, you can
kubectl set image deployment/<name> <container name>=<image repo:tag>
First thing, you can’t update your existing deployment using
kubectl create deployment
because you will get error like:You should use
kubectl set image
command as presented in this example, in your case:Updating the deployment means that pods with an old version (in your case
image-name-1.0
) will be terminated and new pods (withimage-name-2.0
) will be created. For more details about how a deployment updating process works I’d suggest reading this article.It means that you can’t fetch logs from pods with older image version using
kubectl logs
command as these pods will no longer exist.Keep in mind that
kubectl logs --previous <pod-name> -c <container-name>
command is getting logs from previous instance of the container within the same pod. If the pod is terminated (this is what happens during deployment update) logs are lost.What to do with this?
You may try getting logs directly from the nodes as presented in this example from the Kubernetes documentation but log files from deleted pods might be deleted as well – depending which container runtime and Kubernetes cluster solution did you use.
The best option is to implement a central log management system. Check this answer about it.