<p>I want to store logs of pods in kubernetes at one place. i.e output of <strong>kubectl logs podname</strong></p>

<p>I referred this question <a href="https://stackoverflow.com/questions/56489250/kubernetes-basic-pod-logging">Kubernetes basic pod logging</a>  which gives me successfully logs for counter...How to modify this args attribute in spec to get output of <strong>kubectl logs podname</strong> stored in file at one place?</p>

<p>Here is my pod.yaml i created but not able to see any file at location <strong>/tmp/logs/</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: spring-boot-demo-pricing
spec:
  ports:
  - name: spring-boot-pricing
    port: 8084
    targetPort: 8084
  selector:
    app: spring-boot-demo-pricing

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: spring-boot-demo-pricing
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: spring-boot-demo-pricing
    spec:
      containers:
      - name: spring-boot-demo-pricing
        image: djtijare/a2ipricing12062019:v1
        imagePullPolicy: IfNotPresent
       # envFrom:
        #- configMapRef:
        #    name: spring-boot-demo-config-map
        resources:
          requests:
            cpu: 100m
            memory: 1Gi
        ports:
        - containerPort: 8084
        args: [/bin/sh, -c,
          'i=0; while true; do echo "$i: $(date)" &gt;&gt; /u01/kubernetes_prac/logs/log_output.txt; i=$((i+1)); sleep 1; done']
        volumeMounts:
        - name: varlog
          mountPath: /u01/kubernetes_prac/logs
      volumes:
       - name: varlog
         hostPath:
           path: /tmp/logs
</code></pre>

<p>The right approach would be to store logs outside the cluster, say for example if you use AWS, there are provisions like storing logs to cloudwatch, s3, etc. An example might be <a href="https://github.com/fluent/fluentd-kubernetes-daemonset" rel="nofollow noreferrer">fluentd</a>, that writes to many sources. The reason being that kubernetes clusters run on VPC(Virtual private cloud) and providing access to the nodes in the cluster might not be right all the time. So this is one such approach followed. </p>

<p>This <a href="https://eksworkshop.com/logging/" rel="nofollow noreferrer">link</a> provides the guideline to expose all the containers' log to EFK(Elasticsearch, Fluentd, and Kibana).</p>
