﻿# Keep the telemetry sidecar alive through model shutdown

Native sidecar shutdown order preserves an opportunity to flush; shared grace time and downstream acknowledgment determine delivery.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-ks-sidecar-stop-order/
Language: en

A model process writes its final request record while terminating, but the log-forwarding container has already stopped. Kubernetes-style sidecars offer shutdown ordering that ordinary sibling containers do not imply. Use that ordering while keeping the final delivery guarantee honest.

## Identify a native sidecar

The lifecycle applies to restartable init containers configured as sidecars. Check the effective Pod specification rather than assuming any container called collector receives special treatment. During normal Pod termination, Kubernetes postpones their termination until the main application containers stop, then terminates sidecars in reverse specification order.

## Map the real delivery path

A collector can read a shared log file, accept a local telemetry connection or forward buffered messages. Identify which path carries the model's final record. Remaining alive is necessary for some paths but does not prove ingestion or remote acknowledgment. A file still present on a temporary volume can disappear with the Pod before a remote system receives it.

## Reserve time for the final flush

The Pod's grace period is shared. Main-container shutdown can consume the available time, leaving the sidecar little opportunity to flush before forced termination. Size and test the actual shutdown sequence rather than assigning the collector an imaginary independent full grace period. Multiple sidecars need an order consistent with their own dependencies.

## Handle collector failure separately

The collector can restart independently during normal service. The model should not block indefinitely on local telemetry if that would prevent request completion or shutdown. Use bounded buffering and the telemetry client's documented failure policy. Sidecar ordering cannot recover data that was already dropped or guarantee access to an unavailable remote collector.

## Verify an acknowledged final marker

In an isolated fixture, make the main process emit a synthetic final marker and delay its exit. Observe the collector lifetime and whether the marker reaches the intended durable destination. Repeat with a slow receiver and an exhausted grace period. Report process ordering and delivery as separate results. Acceptance is a supported lifecycle plus measured limits, not a claim that every terminating Pod preserves every last message under power loss or forced deletion.

## Primary references

[Kubernetes Sidecar Containers](https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/).

[Kubernetes Pod Lifecycle](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/).

[Kubernetes Init Containers](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/).

Related reading: [preStop consumes the grace period: budgeting Pod termination](/journal/kubernetes-prestop-termination-budget/); [kubectl logs --previous is not enough: Pod log rotation and collection](/journal/kubernetes-log-rotation-restarts/).
