<p>I am new to Kubernetes and currently working on logging.
What I have tried so far is using minikube, created a mount-point and by using PV/PVC I am mounting it in POD.</p>
<p>The problem I am having is when I do <code>kubectl logs test-app</code> I did not get any logs.
But when I do:</p>
<pre><code>kubectl exec -it test-app -- bash

[root@test-app /]# tail -f /var/log/test.log 
Mon Jul 4 06:36:31 UTC 2022
Mon Jul 4 06:36:36 UTC 2022
Mon Jul 4 06:36:41 UTC 2022
Mon Jul 4 06:36:46 UTC 2022
Mon Jul 4 06:36:51 UTC 2022
Mon Jul 4 06:36:56 UTC 2022
</code></pre>
<p>I get the logs. My question is how can I get these logs with 'kubectl logs test-app' ?</p>
<p><strong>pv-pvc.yaml</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/mnt/data&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
</code></pre>
<p><strong>test-pod.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-app
spec:
  volumes:
  - name: ps
    persistentVolumeClaim:
      claimName: task-pv-claim
  containers:
  - name: app
    image: centos
    command: [&quot;/bin/sh&quot;]
    args: [&quot;-c&quot;, &quot;while true; do echo $(date -u) &gt;&gt; /var/log/test.log; sleep 5; done&quot;]
    volumeMounts:
    - mountPath: &quot;/var/log&quot;
      name: ps
</code></pre>

nice guy
<p>Kubernetes only collects container logs written to stdout and this is what you get from <code>kubectl logs</code>. For more information, please refer to the <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/#basic-logging-in-kubernetes" rel="nofollow noreferrer">documentation</a>.</p>
<p>If you need to collect logs that are written to a file, you will have to use a more sophisticated log collector like <a href="https://www.fluentd.org/" rel="nofollow noreferrer">fluentd</a> or <a href="https://fluentbit.io/" rel="nofollow noreferrer">fluentbit</a>.</p>
