I've an applicaion running inside pod which is created by deployment specification in k8s. As I've NFS clients in all nodes, I can mount volume from host to pod. Here is the mount-vol portion of yml file
spec:
containers:
volumeMounts:
- mountPath: /app/config
name: config-volume
- mountPath: /var/log
name: logs
volumes:
- name: config-volume
hostPath:
path: /nfs/config
- name: logs
hostPath:
path: /nfs/logs/containerlogs
config-volume: it mounts the config files from host to pod container.
logs: it is not working. I want to mount the log folder from pod container to host folder.
I don't think you mount containers to host. It is always host to pod. Make sure that the path /nfs/logs/containerLogs exist in the host so that your pod can write to it.
As for me, your yaml almost do work. Personally, I think your yaml need to be completed, such as:
spec:
containers:
volumeMounts:
- mountPath: /app/config
name: config-volume
- mountPath: /var/log
name: logs
volumes:
- name: config-volume
hostPath:
path: /nfs/config
type: Directory
- name: logs
hostPath:
path: /nfs/logs/containerlogs
type: Directory
Also your spec missed configs image
& command
As you described above, there are 2 paths to store 2 kinds of logs.
What you may also do is to assign the 2 paths in your container spec, just like the way you start your application without container.
Actually, the similar configure in your spec is as follows:
command:
- /application
- --log-dir=/var/log
- --config-log-dir=/app/config
- --logtostderr=false
- --v=3
You may noticed that the arguments - --logtostderr
and - --v=3
. If your application has similar arguments, you should set them properly.
After you do the right config, the container will logs the log to the right place.