I use the sidecar method of k8s to collect logs. If I use emptydiry to mount, will the uncollected logs be lost when the pod is moved to another node?
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
Yes, you will lose the data. emptyDir
is erased when a pod is removed (e.g. when it is evicted to another node).
The logs that you'd like to preserve should be printed to stdout
; then collected and persisted by your logging subsystem in the cluster.
From the 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.