Kubernetes - how to map host directory inside pod?

6/15/2018

I am trying to write logs to the kubernetes host machine from pod.

Please could you suggest if an application inside the pod can write on the host machine?

Below is my configuration. I am seeing logs being written to '/opt/logstash/logs' inside the pod but i am not seeing them on the host machine inside '/home/centos/dev/logstash/logs'

    volumeMounts:
    - name: sre-logstash-data-tcp
      mountPath: /opt/logstash/logs

  volumes:
  - name: sre-logstash-data-tcp
    hostPath:
      path: /home/centos/dev/logstash/logs
-- Srinivas
kubernetes

1 Answer

6/15/2018

Please could you suggest if an application inside the pod can write on the host machine?

Yes, it can be configured to do so, hostPath is one of the ways to do so.

I am seeing logs being written to '/opt/logstash/logs' inside the pod but i am not seeing them on the host machine inside '/home/centos/dev/logstash/logs'

That is most probably because node that pod is running on is different than node you are looking at /home/centos/dev/logstash/logs.

Check what node pod is running onto and then make sure to check path on that very node.

Just as a side note hostPath can be problematic for data persistence if you don't use some kind of node affinity to allocate pods to same node and can lead to confusion around it as well.

-- Const
Source: StackOverflow