<p>I am trying to mount my Pod logs directory from <code>/var/log/pods</code> to a local node volume <code>/var/data10</code>.</p>
<p>Deployment file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:       
   name: nginx-counter
   namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:      
      app: my-nginx
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
       nodeSelector:
         kubernetes.io/hostname: kworker3
       containers:
       - name: count
         image: busybox
         args: [/bin/sh, -c,
            'i=0; while true; do echo &quot;$i: $(date)&quot;; i=$((i+1)); sleep 1; done']
         ports:
         - containerPort: 80
         volumeMounts:
           - name: dirvol
             mountPath: &quot;/var/log/containers&quot;
             readOnly: true
         env:
           - name: POD_NAMESPACE
             valueFrom:
               fieldRef:
                 fieldPath: metadata.namespace
           - name: POD_ID
             valueFrom:
               fieldRef:
                 fieldPath: metadata.uid
           - name: POD_NAME
             valueFrom:
               fieldRef:
                 apiVersion: v1
                 fieldPath: metadata.name
       volumes:
           - name: dirvol
             persistentVolumeClaim:
                     claimName: nginx-pvc
</code></pre>
<p>PV+PVC file:</p>
<pre><code>---
kind: PersistentVolume
apiVersion: v1
metadata:
    name: nginx-pv
    namespace: default
spec:
  storageClassName: nginx-sc
  capacity:
    storage: 50Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
      path: &quot;/var/data10&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: nginx-pvc
    namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
     requests:
         storage: 50Gi
  storageClassName: nginx-sc
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
    name: nginx-sc
    namespace: default
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
---
</code></pre>
<p>Terminal Window:</p>
<pre><code>us@kworker3:~$ cd /var/log/pods/default_nginx-counter-6bdd59f45f-psd9x_f1999c22-6702-41b6-afb7-26db4239977b/
us@kworker3:/var/log/pods/default_nginx-counter-6bdd59f45f-psd9x_f1999c22-6702-41b6-afb7-26db4239977b$ cd count/
us@kworker3:/var/log/pods/default_nginx-counter-6bdd59f45f-psd9x_f1999c22-6702-41b6-afb7-26db4239977b/count$ ls
0.log
us@kworker3:/var/log/pods/default_nginx-counter-6bdd59f45f-psd9x_f1999c22-6702-41b6-afb7-26db4239977b/count$ cd
us@kworker3:~$ 
us@kworker3:~$ 
us@kworker3:~$ 
us@kworker3:~$ cd /var/data10
us@kworker3:/var/data10$ cd default_nginx-counter-6bdd59f45f-psd9x_f1999c22-6702-41b6-afb7-26db4239977b/
us@kworker3:/var/data10/default_nginx-counter-6bdd59f45f-psd9x_f1999c22-6702-41b6-afb7-26db4239977b$ ls
us@kworker3:/var/data10/default_nginx-counter-6bdd59f45f-psd9x_f1999c22-6702-41b6-afb7-26db4239977b$ ls
</code></pre>
<p>I am trying to take the log file <code>0.log</code> and place it in the persistent volume <code>/var/data10</code> But as you can see it is empty.</p>
<p>I know I could have used a logging agent like fluentd to grab my container logs but I am trying to use this way to get my logs.</p>
<p><strong>Please note</strong> that I am trying to apply this scenario for a real web application, kubernetes pods would normally throw logs to the /var/log/containers directory on the node and my goal is to mount the log file (of the container) to the hostDisk (/var/data10) so that when the pod is deleted I would still have the logs inside my volume.</p>

amin
<p>Symbolic link does not work in hostPath. Use <code>tee</code> to make a copy in the pod <code>echo ... | tee /pathInContainer/app.log</code> which in turn mount to <code>/var/data10</code> hostPath volume. If <code>tee</code> is not ideal, your best bet is running a log agent as sidecar.</p>
<p>Note that your PV <code>hostPath.path: &quot;/var/data10&quot;</code> will not contain any data as your stdout does not save here. You mounted this hostPath in the container as &quot;/var/log/containers&quot; will serve no purpose.</p>
