Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Volumes - Dynamic path

Tags:

kubernetes

I want my applications to write log files at a host location, so I'm mounting a hostPath volume. But all applications try to write logs using the same file name.

I'd like to separate the files into folders named after the Pod names, but I see nowhere in the documentation how to implement it:

  volumes:
  - name: logs-volume
    hostPath:
      path: /var/logs/apps/${POD_NAME}
      type: DirectoryOrCreate

In the (not working) example above, apps should write files to the POD_NAME folder.

Is it possible?

like image 909
gcstr Avatar asked Dec 21 '17 19:12

gcstr


1 Answers

As of kubernetes 1.17 this is supported using subPathExpr. See https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath-expanded-environment for details.

like image 61
Yasser Avatar answered Oct 04 '22 11:10

Yasser