<p>I have deployment.yml file where i'm mounting service logging folder to a folder in host machine.
The issue is when i run multiple instances using the same deployment.yml file like scaling up all the instances are logging to a same file. Is there a way to solve this by dynamically creating folder in host machine based on container id or something. Any suggestions is appreciated.
My current deployment.yml file is </p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: logstash-deployment
spec:
  selector:
matchLabels:
  app: logstash
  replicas: 2
  template:
    metadata:
      labels:
        app: logstash
    spec:
       containers:
       - name: logstash
         image: logstash:6.8.6
         volumeMounts:
         - mountPath: /usr/share/logstash/config/
           name: config
          - mountPath: /usr/share/logstash/logs/
            name: logs
       volumes:
       - name: config
         hostPath:
           path: "/etc/logstash/"
       - name: logs
         hostPath:
           path: "/var/logs/logstash"
</code></pre>

sandeep P
<p>There are some fields in kubernetes which you can get dynamically like node name, pod name, pod ip, etc. Refer this (<a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/</a>) doc for examples.</p>

<p>Here is an example where you can set node-name as an environment variable. </p>

<pre><code>env:
        - name: MY_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
</code></pre>

<p>You can change your deployment in such a way that it creates a file by adding node name to it.. In this way you can have different file name on each node. Recommended is to create a daemonset instead of deployment which will spawn one pod on each selected nodes (selection can be done using node selector).</p>
