skip to Main Content

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


  1. 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>

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search