2

I am having 2 containers inside one pod, 1 is DB and 1 is application. When my application container started but, not ready to accept traffic by this time the container generates some log files and I want those log files for further application investigation. As the container does not passes readiness probe and it failed to start so, the pod is getting killed so, the log files also getting deleted so how I can get those log files before the pod is getting killed??

2
  • You should investigate how to use oc debug and run an instance where you get interactive shell access. You can then run the original startup command manually and watch what happens, using a separate terminal to oc rsh into the debug pod to tail any file system based logs if necessary. Using file system logs is bad practice, should send to stdout/stderr so the platform can capture them. Aug 30, 2019 at 20:59
  • 1
    Perhaps a bit silly, perhaps useful; but you could reattempt the upgrade of your deployment and check the logs during readiness checks simply using kubectl logs <podname>.
    – Webber
    Aug 31, 2019 at 17:29

5 Answers 5

0

The quickest solution is probably to just mount a volume of type hostPath to your pod. Then, bind this volume to your log directory.
See the documentation here.

Just keep in mind that this solution is certainly not the cleanest one. It's just for debug purpose.

0

What about forward logs to STDOUT and STDERR? That would be the cleanest solution (however, it requires some changes in your code). https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods

0

A one-off solution is to install stern and then run the following command in a separate terminal before starting your application container:

stern <pod_name>

You can then pipe the output to local storage for further analysis

0

You can get logs of a container inside a pod by using -c CONTAINER flag of oc logs command.

If you know the name of the container in your pod, you can get the logs of that container with a command like below

for i in {1..100}; do oc get pods -o name | grep -v "deploy" | xargs -i oc logs -p {} -c CONTAINER_NAME; done

Of course it will be good if you run this in an empty project only with your failing pod.

0

create a persistent volume and mount it on the log directory of containers.You will get logs even after pod is killed. Few volume type that you can be used for this task are -

  • azure disk
  • hostpath
  • gce persistent disk The simplest one is hostpath but not preferred .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.