k8s sidecar收集的日志会不会丢失?

Will the logs collected by k8s sidecar be lost?

我使用k8s的sidecar方式收集日志。如果使用emptydiry挂载,pod移动到其他节点时,未收集的日志会不会丢失?

apiVersion: v1
kind: Pod
metadata:
 name: counter
spec:
 containers:
   - name: count
     image: busybox
     ...    
     volumeMounts:
       - name: varlog
         mountPath: /var/log
   - name: count-agent
     image: k8s.gcr.io/fluentd-gcp:1.30
     ...
     volumeMounts:
       - name: varlog
         mountPath: /var/log
       - name: config-volume
         mountPath: /etc/fluentd-config
 volumes:
   - name: varlog
     emptyDir: {}
   - name: config-volume
     configMap:
       name: fluentd-config

是的,您会丢失数据。 emptyDir 删除 pod 时(例如,当它被逐出到另一个节点时)。

您要保留的日志应该打印到 stdout;然后由集群中的日志记录子系统收集并保存。

来自docs

An emptyDir volume is first created when a Pod is assigned to a node, and exists as long as that Pod is running on that node.