I am stuck on a scenario where I have to get the log folder of container 1 into 2nd container. I have found a solution in which we will create a emptyDir directory.
spec:
containers:
- name: app
image: app-image
imagePullPolicy: Always
ports:
- containerPort: 8080
volumeMounts:
- name: logs
mountPath: /var/log/app/
- name: uf
image: splunk/splunkuniversalforwarder
...
volumeMounts:
- name: logs
mountPath: /var/log/app/
volumes:
- name: logs
emptyDir: {}
But in my situation I want to share /usr/var/log/tomcat/ of 1st container into /var/log/message. This is because splunkUF image will monitor /var/log/app/. so I want to share the log folder of different apps, be it /var/log/app/tomcat or /var/log/messages but at one same location with splunk container /var/log/app/.
I can run copy command to get the log 1 time but how to get the logs continuously?
If you are using PersistentVolumeClaim
or PersistentVolume
, I got bad news because the access modes are pretty limited. The one you would want is ReadWriteMany
but it has a really limited support ATM. See more info here.
You could do with this however it has limitations of having to share a node host which not might be a desirable behaviour. I believe that something that would best suit your case would be this.
I don't see an issue here. you can mount the same volume at a different location in each container.
According to your description this should be something like this:
spec:
containers:
- name: app
image: app-image
...
volumeMounts:
- name: logs
mountPath: /usr/var/log/tomcat/
- name: uf
image: splunk/splunkuniversalforwarder
...
volumeMounts:
- name: logs
mountPath: /var/log/app/
volumes:
- name: logs
emptyDir: {}