How to store logs of all pods in kubernetes at one place on Node?

6/14/2019

I want to store logs of pods in kubernetes at one place. i.e output of kubectl logs podname

I referred this question Kubernetes basic pod logging which gives me successfully logs for counter...How to modify this args attribute in spec to get output of kubectl logs podname stored in file at one place?

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

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)" >> /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
--
kubernetes
kubernetes-pod
logging

1 Answer

7/5/2019

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 fluentd, 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.

This link provides the guideline to expose all the containers' log to EFK(Elasticsearch, Fluentd, and Kibana).

-- Malathi
Source: StackOverflow