How to see the history in Pod Kubernetes

11/5/2021

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.

-- user1938143
kubectl
kubernetes

2 Answers

11/5/2021

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>

-- gohm&#39;c
Source: StackOverflow

11/5/2021

First thing, you can't update your existing deployment using kubectl create deployment because you will get error like:

error: failed to create deployment: deployments.apps "image-app" already exists

You should use kubectl set image command as presented in this example, in your case:

kubectl set image deployment/image-app <container-name>=<image>:<tag>

Updating the deployment means that pods with an old version (in your case image-name-1.0) will be terminated and new pods (with image-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.

-- Mikolaj S.
Source: StackOverflow