Kubernetes container log rotation and retention

Kubelet rotates container logs on each node, so node disks stay healthy but old lines disappear. This page explains the settings, what kubectl logs can still return, and how to ship and retain logs for audit and incident response.

On this page

Kubernetes log rotation and retention starts with what the node keeps

On a self-managed cluster, the kubelet rotates container log files on each node, and that rotation, not any retention policy you set elsewhere, decides how much history kubectl logs can return. Once a container's log file has been rotated out and deleted, the API has nothing to serve, and the only copy of those lines is whatever a log shipper or another system captured earlier. Teams usually need a deliberate rotation and retention design in two situations: when node disks fill up because chatty workloads write faster than the kubelet's limits allow, or when an incident review asks for logs from a pod that was restarted, evicted or deleted days ago and the lines are already gone.

The first decision is what the node itself keeps. Confirm the kubelet's log rotation settings on every node pool, including the maximum size per container log file and the number of rotated files kept, because these are per-node values that can drift between pools built at different times. Check them against the rate at which your heaviest workloads write, and check the node's image and log filesystem headroom at the same time. Node disk pressure from logs and from container images often shows up together, so size the log filesystem as its own line item rather than assuming the root disk covers both.

The second decision is what leaves the node before the kubelet rotates it away. Shipping logs with a collector such as Fluent Bit or a similar agent is the only way to keep lines past the node's rotation window, and that pipeline has its own failure modes: a backed-up buffer, a rejected write to the destination or a collector that restarts during a burst can lose lines even while the node is healthy. Ask for a written statement of which log streams are shipped, where they land, how long each destination keeps them and who owns retention for audit and incident response. Those answers, not the kubelet defaults, define what your incident team can actually retrieve.

Rotation and retention options and when each fits

This table compares four ways to keep container logs on Kubernetes nodes and in central stores, with the disk, network and operator effort each one carries. Read each row as a decision: find the retention need you have, then check the trade-off in the other columns. Kubelet rotation settings are version-specific, so confirm the exact keys and defaults in the kubelet documentation for your Kubernetes version before you set any value.

OptionWhen it fitsCost in disk, network or effortWhat to confirm
Kubelet rotation onlyShort-term troubleshooting where node-local logs are enough and nothing needs to outlive the nodeDisk on each node is bounded by rotation settings. Little network load. Low operator effort, but logs vanish with pod or node replacementCurrent kubelet log rotation keys, their defaults and how your container runtime applies them
Node-local retention onlySmall clusters with short audit windows and no formal log retention requirementNode disk grows with log volume and retention period. Logs are lost when nodes are rebuilt or autoscaled away. Effort is low until a node fillsYour disk headroom per node and how your retention policy defines a log record
Ship before rotation to a central storeIncident response and audit needs that require logs to survive pod, node or cluster lossAdds a collector DaemonSet on every node, a steady network stream and a buffer on disk for outages. Operator effort covers collector config, parsing and alerting on shipping failuresCollector buffer sizing against your rotation window, and whether the store's ingest path can absorb peak volume
Long-term store on object storageRetention periods set by audit, regulatory or contractual requirements, with cheap storage needed at volumeObject storage capacity grows with retained volume. Query and compaction tooling adds operator effort. Egress and ingest traffic depend on your network designRetention periods your compliance owner has approved, object storage cost model and the store's retention and deletion controls

What kubectl logs can still return after rotation

kubectl logs reads only what the kubelet still holds on the node, so its answer depends on rotation settings, pod lifecycle and where the node runs. The cases below show when the current or previous container log is still available and when it is gone for good.

Restarted container, same pod

When a container crashes and restarts inside the same pod, kubectl logs returns the current instance, and with the --previous flag the last terminated instance, as long as the kubelet still has that file. Rotation can remove older output from the previous instance first. For incident response, capture the previous logs immediately after a crash loop starts, and confirm how many rotated files your kubelet keeps per container before relying on them.

Kubernetes logging docs

Evicted pod on disk pressure

An evicted pod keeps its object for a while, but the kubelet may still delete its containers and log files to reclaim space. Disk pressure is the case where rotation and eviction interact most directly, so the logs an investigation needs can disappear during the same event that caused the failure. Check node conditions and eviction events early, and confirm whether logs are already shipped off the node before the pod is cleaned up.

Deleted pod or namespace

Deleting a pod or namespace removes the containers and their log files from the node, and kubectl logs has nothing left to read. Deployment rollouts, Jobs with cleanup policies and CI teardown scripts all delete pods routinely. Treat deletion as the point after which only a log pipeline or an external store can answer questions, and ask whether that pipeline captured the namespace before teardown ran.

Node replacement or repair

Draining, reimaging or replacing a node removes every container log stored on its disk. This includes autoscaler scale-in, cluster upgrades that rebuild nodes and hardware failures where the disk is unreadable. Logs from workloads that ran on that node are only recoverable from a shipper or collector that already sent them elsewhere. Confirm that the collector runs on every node pool, including the pools you rebuild most often.

Logs from a pod that moved

A pod rescheduled to another node starts with an empty log history on that node, so kubectl logs shows only the new instance. The older output stays on the original node until it is removed, and only the node that held it can serve it. Responders who assume one pod name equals one continuous log stream can miss the failure window entirely. Search by workload labels in your central store rather than by pod name alone.

How to set up rotation and shipping before logs are lost

This sequence sets kubelet rotation limits, sizes node disks, ships logs off each node and sets central retention, so container output survives after the node rotates or loses it. Each step ends with a check you can run before moving on.

  1. Confirm the container runtime and kubelet log settings

    Your platform or cluster engineer confirms which container runtime each node uses and where it writes container logs, then reads the kubelet configuration for the log rotation fields, including the maximum size of a single log file and the number of rotated files kept per container. Record the values per node pool, because nodes built from different templates often differ. Done means you have a written table of runtime, log path, max size and max files for every node pool, and you have confirmed those values in the running kubelet configuration rather than only in the template. Check the exact field names against the Kubernetes documentation for your supported version, since the settings are kubelet configuration, not workload settings.

  2. Size node disks against measured log volume

    Measure how many bytes each node writes to container logs over a representative period, using your current metrics or a test namespace, then multiply by the per-container rotation limits to find the worst-case disk footprint per node. Add headroom for images, the writable layer and ephemeral storage used by pods. Ask your infrastructure team to confirm the disk size and the filesystem that holds the log directory, and note whether it shares space with the image store. Done means a sizing note shows the worst-case log footprint against the disk capacity of each node pool, with the owner of any gap named.

  3. Deploy a node log shipper as a DaemonSet

    Deploy the log shipper, such as Fluent Bit, as a DaemonSet so every node runs one collector that reads the container log files from the node. Configure its input path, its position file location on a persistent host path so it resumes after restarts, its buffering limits and its output to your central store. The shipper needs read access to the log directory and a clear RBAC scope for metadata enrichment. Done means every node in every pool shows a running shipper pod, and each shipper reports its read offsets advancing in its own status or metrics output.

  4. Verify shipped lines match node output

    Pick a test workload that writes numbered lines at a known rate, then compare the lines in the central store with the output from kubectl logs and with the raw files on the node. Look for missing sequence numbers, duplicates after a shipper restart, and multiline records split into separate entries. Repeat the test after forcing a log rotation on the node so you can see whether rotated files are still picked up. Done means the counts and sequence numbers match across the three sources for the test window, and you have recorded any parser or buffering fixes that were needed.

  5. Set retention in the central log store

    Set the retention period and storage limits in the central store according to the requirements your audit, legal and incident response owners gave you, and confirm which log streams are kept longer than others. Check that the store's own compaction or deletion jobs run, and that object storage or disk capacity covers the retention you chose. Document who can change retention and how changes are recorded. Done means a retention configuration exists per tenant or stream, a test write survives until its configured deletion point, and the owners have signed off on the values in writing.

  6. Test a restore of a known incident window

    Choose a past or staged incident window with known events, then query the central store for the namespace, pod and time range and confirm the expected lines return with their labels and timestamps. Include a case where the source pod has been deleted and the node has rotated its files, since that is the case that matters for investigations. Record what could not be recovered and why. Done means the investigation team can reproduce the timeline from the central store alone, and the gaps are documented as accepted limits or fixed. Watch disk pressure on nodes throughout, using the monitoring page for this cluster, because a full node disk can stop the shipper before the data reaches the store.

Retention requirements for audit and incident response

Retention periods are a policy decision, not a node setting. Kubelet rotation controls how much log data a node keeps before it is discarded, but how long logs must exist is set by the organization's audit, legal and incident response obligations. Before changing any rotation value, agree the retention periods in writing with your compliance owner, security owner and legal counsel. Ask each of them which log sources must be kept, for how long, in what location and who may read them. Specific periods must come from the framework your organization is assessed against, so confirm them with the relevant framework owner or auditor rather than copying a number from another organization.

Keep application logs and Kubernetes audit logs on separate retention tracks. Application logs usually serve troubleshooting and incident timelines, and their volume and sensitivity vary by workload. Kubernetes audit logs record API requests and are often the primary evidence for who changed what in the cluster, so they usually need their own policy, storage location and access list. Confirm with your platform team how the API server audit policy is configured, where audit output is written, and whether a log shipper such as Fluent Bit forwards it. Both tracks should be shipped off the node before rotation removes them, and the retention rules should be enforced in the backend store, such as Loki or a SIEM, not left to node behavior.

Retention records themselves must be reviewable. Keep a versioned document that lists each log source, its owner, the agreed period, the storage backend, the access roles and the date of the last change. Store it in version control next to the platform configuration so reviewers can see when a period changed and who approved it. Test the policy periodically by restoring a sample of logs from a past date and confirming they are present and readable. DeployOpen can prepare the configurations, test evidence and written procedures for your assessment, but auditors and certification bodies draw the conclusions about whether your retention meets the framework.

How container logs move from the node to long-term storage

The path starts when a container writes to its stdout and stderr, which the container runtime stores as a log file on the node. The kubelet rotates that file on the node, so the node is the rotation boundary and the file on disk is only a short-lived copy. A DaemonSet shipper, typically Fluent Bit, reads those files, buffers lines and routes them to a central store, which is where retention is set. Operators then query the central store, not the node, because kubectl logs only returns what the node still holds. Check that the shipper keeps up with rotation, since lines rotated away before they are read are lost.

Node rotation boundary and central retention boundary for container logs.

Security and operational risks in log retention

Log retention creates risks in both directions: logs can expose data they should not hold, and they can disappear when they matter most. The cards below pair each risk with the control that addresses it on self-managed clusters, so the rotation settings, shipping pipeline and central store are designed together.

Sensitive data in logs

Applications sometimes write tokens, personal data, card numbers or full request bodies to stdout, and the kubelet then stores that output on the node and in every shipped copy. Check which fields your services log, and ask developers to remove or mask secrets at the source. Scan a sample of recent log lines before you widen retention, because rotation does not remove data that has already been shipped.

Access to the central store

Once logs leave the node, the central store becomes a high-value target because it holds the same secrets and personal data as the workloads. Restrict query access by namespace or tenant, separate operator and auditor roles, and make sure the cluster's Secrets are not reachable through log search. Confirm how your chosen backend authenticates users and records queries before you grant broad access.

Tamper resistance

Logs used for incident response lose value if someone with node or store access can edit or delete them without a trace. Write logs to storage that the workload's service accounts cannot modify, keep the write path separate from administrator delete rights, and record administrative changes to the logging stack itself. Confirm with the backend vendor whether it offers immutability or write-once settings for the buckets or indexes you plan to use.

Log loss during shipper outages

The kubelet rotates container logs on the node, so if the shipper stops reading, lines rotated away during the outage are gone. Size the on-node buffer against your expected outage window, alert when the shipper falls behind, and test a shipper restart on a staging cluster. Record the gap in your retention documentation so incident responders know where coverage starts and stops.

Disk pressure from buffering

A shipper that buffers to the node's disk can fill that disk during an outage and push the node into disk pressure, which evicts workloads. Set an explicit buffer limit and decide whether the shipper drops or blocks when the limit is reached. Monitor node filesystem usage and the kubelet's image and log space alongside the shipper's buffer size, since both draw on the same disk.

Retention matched to obligations

Retention periods for audit and incident response come from your own regulatory and contractual obligations, not from cluster defaults. Document which log sources must be kept, for how long, and in which location, then confirm the tiering and deletion rules match that policy. Ask your compliance team to sign off on the schedule, and review it when a new workload or data class joins the cluster.

Questions teams ask before changing log rotation

What drives the cost and effort of a container log retention design?

The main driver is how many logs must survive and for how long, not the rotation setting itself. Cost follows from node count, log volume per node, the number of retention classes (application logs, audit logs, node logs), and how much shipping and storage infrastructure has to be built before old logs are removed from nodes. Effort rises when teams have no agreed owner for retention periods or when logs must be searchable across clusters. One-time work covers design, pipeline setup and testing. Recurring work covers storage growth, pipeline upkeep and periodic reviews of retention. Ask any provider to price these components separately and to state which ones depend on your log volume measurements.

Can our team set up log rotation and retention without a partner?

Often yes, if you have engineers who already run the cluster and someone who owns logging and audit requirements. The kubelet rotation settings are a node-level configuration change, and the harder part is deciding what to keep and where it goes. Teams usually need experience with a log shipper, a log store and the access controls that come with them. A partner is most useful when the team lacks that experience, needs the work finished before an audit or incident-response requirement applies, or wants a documented design that reviewers can check. Whichever path you choose, agree on the retention decisions in writing first.

How long does a typical log rotation rollout take, and what drives that?

No timeline figure is available for this topic, so treat any duration you hear as unverified until it is tied to your environment. The main drivers are the number of clusters and node pools, whether a log store already exists, how many workloads write unusual log formats that need parsing, the number of retention decisions approvers must sign off, and how many change windows your operations team allows for node restarts or configuration rollouts. Ask for a schedule that lists each cluster, the approval steps and the test evidence you will receive before a change reaches production.

What does the work need from our team: node access, storage and retention decisions?

Expect to provide administrative access to the nodes or to the configuration that manages them, so that kubelet settings can be changed and verified. You will also need storage capacity for the log destination, whether that is object storage, a log store or a SIEM, and a clear network path from nodes to it. The most important input is the retention decision itself: how long application logs, node logs and audit logs must remain available, who may read them, and what happens at the end of each period. Compliance and security owners should confirm these periods, because the technical design depends on them.

How can we tell if container logs are being lost?

Logs are lost when rotation removes a file before it has been shipped, when a shipper falls behind or stops, or when the destination rejects writes. Check that each node's log shipper reports healthy status, that buffer and backlog metrics stay within limits, and that the number of log lines received in the store roughly matches what the nodes produce for a sample workload. Test the path by generating known log lines, deleting nothing, and confirming they arrive. Also watch for gaps in timestamps and for disk pressure events on nodes, which can indicate that rotation is not keeping up with output.

Why does kubectl logs stop returning older output, and is that a problem?

The kubectl logs command reads the current container log files on the node, so once rotation removes older files, those lines are no longer returned. This is expected behavior and it is why rotation exists, but it means kubectl is not a retention system. If an incident investigation or audit needs older output, that output must already be in a shipped store. Confirm the behavior on your Kubernetes version against the official documentation before you rely on any assumption about how much history remains available.

Does DeployOpen issue audit reports or certify our log retention?

No. DeployOpen plans and implements log rotation, shipping and retention controls in your infrastructure, and prepares the configuration, settings and evidence that compliance assessments review. Independent auditors and certification bodies issue audit reports, attestations and certifications. Ask your auditor which evidence they need, such as retention settings, access records and test results, before the design is finalized so the work is built to produce that evidence.

What happens to logs during a Kubernetes upgrade?

Kubelet settings and the log shipper need to be checked during upgrades, because node replacement or restarts can interrupt shipping or change where logs are written. Follow the version skew policy for control plane and node order, and rerun your log loss test after each step. Plan for the case where a node is replaced before its last logs are shipped, and decide whether that risk is acceptable for your incident-response needs.

How DeployOpen scopes log rotation and retention work

DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside your own infrastructure, including the Kubernetes clusters, node images and log pipelines covered on this page. For log rotation and retention, that means the work starts with your current kubelet settings, container runtime log configuration, node disk layout and the log destinations your audit and incident response teams already use, then moves to a written plan for what changes on each node pool and what stays in the cluster.

Most engagements are fixed-scope. Before work starts, the scope, deliverables and timelines are agreed in writing. For this topic, a typical scope lists the kubelet rotation values to set, the shipping pipeline that must capture logs before rotation removes them, the retention periods your compliance owner has approved for each log class, the verification steps for node disk pressure and log availability, and the operating notes your team will use after handover. Ask whether each of these is in the written scope and who owns each decision. A quote follows from that written scope, so the more specific your retention requirements are when you ask for one, the more accurate the quote will be.

Ongoing support is available as a retainer for teams that want DeployOpen to review rotation settings after cluster upgrades, check that shipping agents keep up with log volume, and update retention when a framework or internal policy changes. Confirm with your provider which of these activities sit inside a retainer and which need a new written scope.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.