Skip to content

kubelet: fix log files being overwritten on container state loss#99748

Merged
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
rphillips:fixes/check_log_path_for_restart_count
May 3, 2021
Merged

kubelet: fix log files being overwritten on container state loss#99748
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
rphillips:fixes/check_log_path_for_restart_count

Conversation

@rphillips
Copy link
Copy Markdown
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

If the container runtime state is wiped after a reboot, we can figure out the restart count by looking at the log files, since the log files are named {restartCount}.log.

This fixes a situation where pods can overwrite previous log files, since a lost container state's restartCount will start at 0. We see this mostly with static pods, but pods that are not drained, normally daemonsets and replicaset pods, can exhibit this issue as well.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 4, 2021
@rphillips
Copy link
Copy Markdown
Member Author

/sig node
/triage accepted

@k8s-ci-robot k8s-ci-robot added sig/node Categorizes an issue or PR as relevant to SIG Node. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 4, 2021
@k8s-ci-robot k8s-ci-robot requested review from dims and yifan-gu March 4, 2021 02:49
@k8s-ci-robot k8s-ci-robot added area/kubelet and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 4, 2021
@rphillips rphillips force-pushed the fixes/check_log_path_for_restart_count branch from 705eab5 to 13779f0 Compare March 4, 2021 13:54
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 4, 2021
@rphillips rphillips force-pushed the fixes/check_log_path_for_restart_count branch 6 times, most recently from 594d3c8 to f505c92 Compare March 4, 2021 14:51
@rphillips
Copy link
Copy Markdown
Member Author

/test pull-kubernetes-unit

@rphillips rphillips force-pushed the fixes/check_log_path_for_restart_count branch from f505c92 to 8c0814e Compare March 4, 2021 16:32
@ehashman
Copy link
Copy Markdown
Member

ehashman commented Mar 4, 2021

/priority important-longterm
/assign

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 4, 2021
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please switch to structured log (InfoS with err and path)

Comment thread pkg/kubelet/kuberuntime/kuberuntime_container.go Outdated
Comment thread pkg/kubelet/kuberuntime/kuberuntime_container.go Outdated
Comment thread pkg/kubelet/kuberuntime/kuberuntime_container.go Outdated
@rphillips rphillips force-pushed the fixes/check_log_path_for_restart_count branch from 8c0814e to 0ad5f6e Compare March 15, 2021 20:29
@rphillips rphillips force-pushed the fixes/check_log_path_for_restart_count branch from 0ad5f6e to d169c81 Compare March 15, 2021 20:33
@ehashman
Copy link
Copy Markdown
Member

One thing I am thinking about: this will cause the kubelet to potentially retain more logs than it currently is doing, for crashlooping pods. There is a possibility that a crashing pod that's outputting a lot of garbage into its logs would add a lot of log volume to disk.

How do we ensure this disk space is being accounted for by the pod and e.g. rotated or truncated as necessary?

@rphillips
Copy link
Copy Markdown
Member Author

The kubelet has a max log files and max log file size it takes into account:

https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/

--container-log-max-files int32 Default: 5
--container-log-max-size string     Default: 10Mi

@rphillips
Copy link
Copy Markdown
Member Author

/retest

Copy link
Copy Markdown
Member

@ehashman ehashman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Will leave setting milestone to approvers. I think we should consider this bugfix for 1.21.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 15, 2021
@mrunalp
Copy link
Copy Markdown
Contributor

mrunalp commented May 3, 2021

/approve

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mrunalp, rphillips

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

Development

Successfully merging this pull request may close these issues.

4 participants