How do I save kubectl logs to a file on my host machine?
kubectl logs pod_name > app.log
for example, if you have a kube pod named app-6b8bdd458b-kskjh
and you intend to save the logs from this pod to a file name app.log
then the command should be
kubectl logs app-6b8bdd458b-kskjh > app.log
Note: This may not be an direct answer of how to make the logs go to the host machine, but it does provide a way to get logs onto the machine. This may not be the best answer, but it's what I know so I'm sharing. Please answer if you have a more direct solution.
You can do this using fluentd. Here's a tutorial about how to set it up. You can configure it to write to a file in a mounted hostdir or have it write to S3. It also allows you to aggregate all your logs from all your containers which may or may not be useful. Combined with ElasticSearch and Kibana you can put together a pretty strong logging stack. It will depend on your use-case of course though.