I'm looking to understand log rotation mechanics. ...
# rke2
q
I'm looking to understand log rotation mechanics. In /var/log/pods, I see that I mostly have files named 0.log. Sometimes I have 0.log and 1.log. In one case, I only have a 2.log. Did 0.log and 1.log rotate out? Will I eventually get a 3.log all by itself?
c
The number comes from the
Attempt
field in the container runtime config, which counts the number of times the kubelet has attempted to start that pod. https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go#L1808-L1824
Depending on what happened with the previous attempts to run the pod, you may or may not have old logs available
The highest number you see there should correspond to the
RESTARTS
column in
kubectl get pod
q
I see, good to know. Can you refer me to the code that handles writing and rotating the pod logs?
c
You'll have to dig through the guts of containerd for that
I don't have it handy
q
Got it, I found what I needed. Thanks for your help! Much appreciated, and have a nice weekend