A synthetic batch Job presents a deceptively simple symptom: the primary container has terminated with exit code 0, a supporting process is still running, and the Job has no terminal Complete condition. The release question is not “does Kubernetes support sidecars?” It is narrower: does the supporting process live in ordinary .spec.containers, in .spec.initContainers with container-level restartPolicy: Always, or in .spec.initContainers without that restart policy? Those three classifications produce materially different lifecycle behavior. Kubernetes v1.33 documents native sidecars as restartable init containers and states that, for Jobs, they do not prevent completion after the main application containers finish; ordinary init containers, by contrast, must complete before application containers start.
This playbook treats four facts as separate evidence: the primary process terminated, a companion remains or terminates, the Pod reaches a terminal phase, and the Job receives its final condition. Kubernetes v1.31 and later delays terminal Complete or Failed Job conditions until the Job's Pods have terminated, so a collector must distinguish controller criteria from terminal state rather than collapsing them into “the Job is done.”
The experiment is specified for kind v0.28.0, Kubernetes v1.33.1 and kubectl v1.33.1 using the published kindest/node:v1.33.1@sha256:8d866994839cd096b3590681c55a6fa4a071fdaf33be7b9660e5697d2ed13002 image. It is deliberately historical. No Kubernetes execution was performed for this article. Every runtime outcome below is therefore EXPECTED / NOT EXECUTED, and the overall runtime verdict is HOLD.
Define the completion contract before changing the manifest
A finite Job needs separate success contracts at three layers. At the application layer, each ordinary application container that is part of the Job's required work must terminate successfully. At the Pod layer, the Pod must reach the terminal phase expected by the case. At the Job layer, the controller must expose the expected terminal condition. Kubernetes documents terminal Job states as Complete for success and Failed for failure; since v1.31, the Job controller delays those terminal conditions until all Job Pods are terminated.
That separation matters because “main container exit code 0” is not equivalent to “Pod succeeded,” and neither is equivalent to “Job Complete.” An ordinary helper placed in .spec.containers is another application container for Pod lifecycle purposes. A native sidecar is different: Kubernetes v1.33 defines it as an entry in .spec.initContainers with container-level restartPolicy: Always, and the sidecar documentation explicitly states that such a sidecar does not prevent Job completion once the main application containers finish.
The invariant fixture policy is:
spec:
completions: 1
parallelism: 1
backoffLimit: 0
template:
spec:
restartPolicy: NeverJ05 changes only the main process exit code. J06 changes the helper's classification to an ordinary init container. J07 adds a second ordinary application container. J08 deliberately restarts the native sidecar once. No case introduces CronJobs, podFailurePolicy, indexed completion, readiness/liveness/startup probes, custom readiness gates, mesh injection, Service routing, preStop, node disruption, force deletion or resource-sizing experiments.
If the actual question is which failed Pod consumes which retry allowance, that is a different boundary; use Kubernetes Job failure and retry accounting. Here, backoffLimit: 0 remains fixed so retry behavior does not become the diagnosis.
Engineering inference: helper classification should be changed only if the helper is truly supporting work whose lifecycle may end when ordinary application work ends. If its output is indispensable to business success, converting it to a native sidecar merely to obtain Complete would weaken the application's success contract.
Freeze a disposable, versioned environment
Use a unique local cluster, namespace and run identifier. The fixture must require no credentials, host mounts, external datastore, external log sink or production context. Isolation is not evidence of production hardening; it is simply a way to keep this lifecycle test bounded. Broader permission and workload controls belong to a separate Kubernetes workload hardening review.
Before creating anything, capture host, client and local runtime facts. Do not infer them from the article.
set -u
export RUN_ID="sidecar-job-$(date -u +%Y%m%dT%H%M%SZ)"
export CLUSTER="sidecar-job-lab"
export NS="sidecar-job-lab"
export EVIDENCE="$PWD/evidence/$RUN_ID"
mkdir -p "$EVIDENCE"/{preflight,manifests,cases,stderr}
{
printf 'run_id=%s\n' "$RUN_ID"
uname -a
uname -m
printf 'os_release:\n'
cat /etc/os-release 2>/dev/null || true
} >"$EVIDENCE/preflight/host.txt" 2>&1
kind version \
>"$EVIDENCE/preflight/kind-version.stdout" \
2>"$EVIDENCE/stderr/kind-version.stderr"
printf '%s\n' "$?" >"$EVIDENCE/preflight/kind-version.status"
kubectl version --client -o yaml \
>"$EVIDENCE/preflight/kubectl-client.yaml" \
2>"$EVIDENCE/stderr/kubectl-client.stderr"
printf '%s\n' "$?" >"$EVIDENCE/preflight/kubectl-client.status"
docker version \
>"$EVIDENCE/preflight/docker-version.txt" \
2>"$EVIDENCE/stderr/docker-version.stderr"
printf '%s\n' "$?" >"$EVIDENCE/preflight/docker-version.status"Do not pipe a failing command through tee without preserving PIPESTATUS. Shell command status and Kubernetes container exit status are different evidence fields.
Lock the historical runtime and workload identity
kind v0.28.0 published Kubernetes v1.33.1 as its default and lists exactly this node image digest; its release notes also mention containerd 2.1 and runc 1.3, but those release notes are not a substitute for recording the runtime actually instantiated.
Create the cluster only after confirming kind version reports v0.28.0:
cat >"$EVIDENCE/preflight/kind.yaml" <<'YAML'
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.33.1@sha256:8d866994839cd096b3590681c55a6fa4a071fdaf33be7b9660e5697d2ed13002
YAML
kind create cluster \
--name "$CLUSTER" \
--config "$EVIDENCE/preflight/kind.yaml" \
>"$EVIDENCE/preflight/kind-create.stdout" \
2>"$EVIDENCE/stderr/kind-create.stderr"
printf '%s\n' "$?" >"$EVIDENCE/preflight/kind-create.status"
kubectl config current-context >"$EVIDENCE/preflight/context.txt"
kubectl version -o yaml \
>"$EVIDENCE/preflight/kubectl-server.yaml" \
2>"$EVIDENCE/stderr/kubectl-server.stderr"
printf '%s\n' "$?" >"$EVIDENCE/preflight/kubectl-server.status"
kubectl get nodes -o json >"$EVIDENCE/preflight/nodes.json"
docker exec "${CLUSTER}-control-plane" containerd --version \
>"$EVIDENCE/preflight/containerd.txt" 2>&1
docker exec "${CLUSTER}-control-plane" runc --version \
>"$EVIDENCE/preflight/runc.txt" 2>&1The client and server must both be v1.33.1 for this fixture. A mismatch is HOLD.
For the synthetic workload, this playbook uses the Docker Official Image busybox:1.36.1. Docker Hub currently identifies its immutable multi-platform index as sha256:73aaf090f3d85aa34ee199857f03fa3a95c8ede2ffd4cc2cdb5b94e566b11662. That is a real digest, not an invented placeholder.
Record:
export WORKLOAD_IMAGE='busybox@sha256:73aaf090f3d85aa34ee199857f03fa3a95c8ede2ffd4cc2cdb5b94e566b11662'
docker buildx imagetools inspect "$WORKLOAD_IMAGE" \
>"$EVIDENCE/preflight/workload-image.txt" \
2>"$EVIDENCE/stderr/workload-image.stderr"
printf '%s\n' "$?" >"$EVIDENCE/preflight/workload-image.status"Because no host/runtime execution occurred for this article, the host architecture, selected child manifest, Kubernetes imageID, and busybox runtime banner remain EXPECTED / NOT EXECUTED. If the immutable image cannot actually be resolved for the host architecture, preflight is HOLD, and no case is eligible to run.
Construct three comparable container layouts
Use an emptyDir only for synchronization markers. The main process waits for /ctl/release-main; the helper writes /ctl/helper-started; ordinary helpers wait for /ctl/release-helper. This avoids interpreting a fixed sleep as proof that another process started.
A deterministic renderer keeps the command payload comparable while changing placement.
cat > render-job.sh <<'SH'
#!/usr/bin/env bash
set -euo pipefail
: "${CASE:?}"
: "${NS:?}"
: "${WORKLOAD_IMAGE:?must be immutable digest}"
job="job-${CASE,,}"
main_cmd='
echo "ROLE=main CASE='"$CASE"'"
echo "BUSYBOX=$(/bin/busybox 2>&1 | head -n1)"
while [ ! -e /ctl/release-main ]; do sleep 1; done
echo "MAIN_RELEASED"
exit '"${MAIN_EXIT:-0}"'
'
helper_cmd='
echo "ROLE=helper CASE='"$CASE"'"
echo "BUSYBOX=$(/bin/busybox 2>&1 | head -n1)"
touch /ctl/helper-started
while [ ! -e /ctl/release-helper ]; do sleep 1; done
echo "HELPER_RELEASED"
exit 0
'
native_cmd='
echo "ROLE=native-helper CASE='"$CASE"'"
echo "BUSYBOX=$(/bin/busybox 2>&1 | head -n1)"
touch /ctl/helper-started
while :; do sleep 1; done
'
cat <<YAML
apiVersion: batch/v1
kind: Job
metadata:
name: ${job}
namespace: ${NS}
labels:
lab.run: ${RUN_ID}
lab.case: ${CASE}
spec:
completions: 1
parallelism: 1
backoffLimit: 0
template:
metadata:
labels:
lab.run: ${RUN_ID}
lab.case: ${CASE}
spec:
restartPolicy: Never
automountServiceAccountToken: false
volumes:
- name: ctl
emptyDir: {}
YAML
case "$CASE" in
J01)
cat <<YAML
containers:
- name: main
image: ${WORKLOAD_IMAGE}
command: ["/bin/sh","-c"]
args: [$(printf '%q' "$main_cmd")]
volumeMounts: [{name: ctl, mountPath: /ctl}]
YAML
;;
J02|J03)
cat <<YAML
containers:
- name: main
image: ${WORKLOAD_IMAGE}
command: ["/bin/sh","-c"]
args: [$(printf '%q' "$main_cmd")]
volumeMounts: [{name: ctl, mountPath: /ctl}]
- name: helper
image: ${WORKLOAD_IMAGE}
command: ["/bin/sh","-c"]
args: [$(printf '%q' "$helper_cmd")]
volumeMounts: [{name: ctl, mountPath: /ctl}]
YAML
;;
J04|J05|J08)
cat <<YAML
initContainers:
- name: helper
image: ${WORKLOAD_IMAGE}
restartPolicy: Always
command: ["/bin/sh","-c"]
args: [$(printf '%q' "$native_cmd")]
volumeMounts: [{name: ctl, mountPath: /ctl}]
containers:
- name: main
image: ${WORKLOAD_IMAGE}
command: ["/bin/sh","-c"]
args: [$(printf '%q' "$main_cmd")]
volumeMounts: [{name: ctl, mountPath: /ctl}]
YAML
;;
J06)
cat <<YAML
initContainers:
- name: helper
image: ${WORKLOAD_IMAGE}
command: ["/bin/sh","-c"]
args: [$(printf '%q' "$helper_cmd")]
volumeMounts: [{name: ctl, mountPath: /ctl}]
containers:
- name: main
image: ${WORKLOAD_IMAGE}
command: ["/bin/sh","-c"]
args: [$(printf '%q' "$main_cmd")]
volumeMounts: [{name: ctl, mountPath: /ctl}]
YAML
;;
esac
SH
chmod +x render-job.shJ07 and J08 require the small extensions shown later. The renderer intentionally has no ttlSecondsAfterFinished; finished evidence should remain until the collector and cleanup steps complete.
Keep process behavior comparable
The ordinary and native helper use the same immutable image, same marker volume, same explicit role log and same “remain alive” process intent. The changed variable is helper classification. Native sidecars are defined by Kubernetes as restartable init containers with restartPolicy: Always; ordinary init containers do not share that lifecycle.
Before releasing a main container:
POD="$(kubectl get pod -n "$NS" -l "job-name=job-${CASE,,}" -o jsonpath='{.items[0].metadata.name}')"
kubectl exec -n "$NS" "$POD" -c main -- \
sh -c 'test -e /ctl/helper-started'
printf 'helper-marker-status=%s\n' "$?" \
>"$EVIDENCE/cases/$CASE/helper-marker.status"
kubectl get pod -n "$NS" "$POD" -o json \
>"$EVIDENCE/cases/$CASE/pre-release.pod.json"For a native helper, also require its entry in .status.initContainerStatuses to report started: true before releasing main work. The documentation describes that status as the point after which the kubelet can continue to later init/application startup.
Author the expected-case manifest independently
Write the oracle before collecting output. It must not be generated from a successful observed run.
schemaVersion: 1
executionStatus: EXPECTED / NOT EXECUTED
requiredCommon:
job:
- metadata.uid
- status.conditions
pod:
- metadata.uid
- metadata.ownerReferences
- status.phase
- status.containerStatuses
nativeLayouts:
- status.initContainerStatuses
cases:
J01:
layout: main-only
expect:
mainExit: 0
podPhase: Succeeded
jobCondition: Complete
J02:
layout: ordinary-companion
expect:
mainExit: 0
helperState: Running
observationWindowSeconds: 60
jobCompletePresent: false
J03:
layout: ordinary-companion-same-J02-object
expect:
preserveJ02UIDs: true
helperExit: 0
podPhase: Succeeded
jobCondition: Complete
J04:
layout: native-sidecar
expect:
mainExit: 0
requireInitContainerStatuses: true
podPhase: Succeeded
jobCondition: Complete
J05:
layout: native-sidecar-main-fails
expect:
mainExit: 42
requireInitContainerStatuses: true
jobCondition: Failed
J06:
layout: ordinary-init-block
expect:
mainStarted: false
initHelperState: Running
jobCompletePresent: false
J07:
layout: native-sidecar-two-apps
expect:
appAExit: 0
appBInitiallyRunning: true
completeBeforeBExit: false
finalJobCondition: Complete
J08:
layout: native-sidecar-restart
expect:
requireInitContainerStatuses: true
helperRestartCountMinimum: 1
mainExit: 0
J09:
layout: evidence-negative-control
sourceCase: J04-or-J08
mutation: remove-status.initContainerStatuses-only
expect:
evaluatorVerdict: HOLDHuman-readable oracle:
Case | Controlled input | Expected result |
J01 | Main alone exits 0 | EXPECTED / NOT EXECUTED: Pod Succeeded; Job Complete. |
J02 | Main exits 0; ordinary helper remains alive | EXPECTED / NOT EXECUTED: main terminated 0; helper Running; no Complete during the bounded 60-second post-main window. |
J03 | Release J02 helper | EXPECTED / NOT EXECUTED: same Job/Pod identity; helper exits 0; terminal success can follow. |
J04 | Helper is native sidecar | EXPECTED / NOT EXECUTED: native helper does not indefinitely hold Job completion open; capture shutdown, Pod terminal phase and Complete. |
J05 | Native layout; main exits 42 | EXPECTED / NOT EXECUTED: Job Failed, not Complete. |
J06 | Long-running ordinary init helper | EXPECTED / NOT EXECUTED: main never starts; initialization blockage. |
J07 | Native helper; app A exits; app B held | EXPECTED / NOT EXECUTED: A alone is insufficient; completion waits for B. |
J08 | Native helper fails once, restarts, then main released | EXPECTED / NOT EXECUTED: helper restart history is retained independently; final outcome reconciled only after main release. |
J09 | Remove only initContainerStatuses from complete J04/J08 Pod copy | EXPECTED / NOT EXECUTED: evaluator returns HOLD. |
The expected J04 behavior is grounded in the Kubernetes v1.33 sidecar contract: a sidecar declared in initContainers with restartPolicy: Always does not prevent a Job from completing after its main containers finish. Kubernetes also documents sidecar shutdown after application containers and in reverse order when multiple sidecars exist.
Reject incomplete evidence deliberately
J09 must begin from an unmodified, complete J04 or J08 Pod artifact. J01 is invalid as the source because it legitimately has no init containers.
cp "$EVIDENCE/cases/J04/final.pod.json" \
"$EVIDENCE/cases/J09/source.pod.json"
jq 'del(.status.initContainerStatuses)' \
"$EVIDENCE/cases/J09/source.pod.json" \
>"$EVIDENCE/cases/J09/mutated.pod.json"An absent array is not equivalent to an intentionally empty array. Kubernetes exposes init-container status under .status.initContainerStatuses; a collector that needs to prove native-sidecar behavior cannot approve a native layout without it.
Use this local evaluator:
#!/usr/bin/env python3
import json, sys
from pathlib import Path
case = sys.argv[1]
pod_path = Path(sys.argv[2])
job_path = Path(sys.argv[3])
pod = json.loads(pod_path.read_text())
job = json.loads(job_path.read_text())
native_cases = {"J04", "J05", "J07", "J08", "J09"}
errors = []
def require(obj, keys, label):
cur = obj
for key in keys:
if not isinstance(cur, dict) or key not in cur:
errors.append(f"missing {label}: {'.'.join(keys)}")
return
cur = cur[key]
require(pod, ["metadata", "uid"], "pod identity")
require(pod, ["metadata", "ownerReferences"], "pod ownership")
require(pod, ["status", "phase"], "pod phase")
require(pod, ["status", "containerStatuses"], "app container status")
require(job, ["metadata", "uid"], "job identity")
require(job, ["status", "conditions"], "job conditions")
if case in native_cases:
require(pod, ["status", "initContainerStatuses"],
"native-sidecar status array")
if errors:
print("HOLD")
for err in errors:
print(err, file=sys.stderr)
sys.exit(2)
print("EVIDENCE-COMPLETE")
sys.exit(0)For J09, the expected evaluator output is EXPECTED / NOT EXECUTED: HOLD, with a nonzero local evaluator exit status.
Establish the primary-work baseline
J01 establishes that the fixture can produce a finite Job without any helper.
export CASE=J01 MAIN_EXIT=0
mkdir -p "$EVIDENCE/cases/$CASE"
./render-job.sh \
>"$EVIDENCE/manifests/$CASE.yaml" \
2>"$EVIDENCE/stderr/$CASE-render.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cases/$CASE/render.status"
kubectl apply -f "$EVIDENCE/manifests/$CASE.yaml" \
>"$EVIDENCE/cases/$CASE/apply.stdout" \
2>"$EVIDENCE/stderr/$CASE-apply.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cases/$CASE/apply.status"
kubectl get job -n "$NS" "job-j01" -o yaml \
>"$EVIDENCE/cases/$CASE/admitted.job.yaml"
POD="$(kubectl get pod -n "$NS" -l job-name=job-j01 \
-o jsonpath='{.items[0].metadata.name}')"
kubectl exec -n "$NS" "$POD" -c main -- touch /ctl/release-main \
>"$EVIDENCE/cases/$CASE/release.stdout" \
2>"$EVIDENCE/stderr/$CASE-release.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cases/$CASE/release.status"
kubectl get pod -n "$NS" "$POD" -o json \
>"$EVIDENCE/cases/$CASE/final.pod.json"
kubectl get job -n "$NS" job-j01 -o json \
>"$EVIDENCE/cases/$CASE/final.job.json"
kubectl wait -n "$NS" --for=condition=complete job/job-j01 \
--timeout=60s \
>"$EVIDENCE/cases/$CASE/wait.stdout" \
2>"$EVIDENCE/stderr/$CASE-wait.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cases/$CASE/wait.status"Collect raw objects before treating kubectl wait as evidence. A timeout means only that the requested condition was not observed within that command's interval. It does not identify the cause.
The expected baseline is EXPECTED / NOT EXECUTED: main terminates with container exit code 0, the Pod reaches Succeeded, and the Job eventually exposes Complete=True. Kubernetes defines Succeeded as a terminal Pod phase and Complete as the Job's successful terminal condition.
Observed Job UID: EXPECTED / NOT EXECUTED (unfilled)
Observed Pod UID: EXPECTED / NOT EXECUTED (unfilled)
Observed main exit code: EXPECTED / NOT EXECUTED (unfilled)
Observed Pod phase: EXPECTED / NOT EXECUTED (unfilled)
Observed Job condition: EXPECTED / NOT EXECUTED (unfilled)Reproduce the ordinary-companion blockage
For J02, render the ordinary companion in .spec.containers. Wait for both the helper marker and the helper's Running state, then release main.
export CASE=J02 MAIN_EXIT=0
mkdir -p "$EVIDENCE/cases/$CASE"
./render-job.sh >"$EVIDENCE/manifests/$CASE.yaml"
kubectl apply -f "$EVIDENCE/manifests/$CASE.yaml"
POD="$(kubectl get pod -n "$NS" -l job-name=job-j02 \
-o jsonpath='{.items[0].metadata.name}')"
until kubectl exec -n "$NS" "$POD" -c main -- \
test -e /ctl/helper-started; do sleep 1; done
kubectl get pod -n "$NS" "$POD" -o json \
>"$EVIDENCE/cases/$CASE/helper-confirmed.pod.json"
kubectl exec -n "$NS" "$POD" -c main -- touch /ctl/release-mainStart the fixture's 60-second post-main observation only after terminated status proves the main exited:
deadline=$((SECONDS + 60))
while (( SECONDS < deadline )); do
kubectl get pod -n "$NS" "$POD" -o json \
>>"$EVIDENCE/cases/$CASE/post-main.ndjson"
kubectl get job -n "$NS" job-j02 -o json \
>>"$EVIDENCE/cases/$CASE/post-main-job.ndjson"
sleep 2
doneEXPECTED / NOT EXECUTED: the main entry in containerStatuses is terminated with exit code 0; the ordinary helper remains Running; the Pod has not yet reached terminal success; and Complete=True remains absent throughout this fixture-defined 60-second window.
That 60 seconds is not a Kubernetes SLA and does not prove an infinite hang. It is a bounded test policy that gives the negative control an explicit observation boundary.
Make the ordinary companion finish under control
J03 is a second checkpoint of the same deliberate J02 case, not a new Job.
Preserve identity first:
kubectl get job -n "$NS" job-j02 -o json \
>"$EVIDENCE/cases/J03/pre-release.job.json"
kubectl get pod -n "$NS" "$POD" -o json \
>"$EVIDENCE/cases/J03/pre-release.pod.json"
kubectl exec -n "$NS" "$POD" -c main -- touch /ctl/release-helper \
>"$EVIDENCE/cases/J03/release-helper.stdout" \
2>"$EVIDENCE/stderr/J03-release-helper.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cases/J03/release-helper.status"Then collect terminal objects:
kubectl wait -n "$NS" --for=condition=complete job/job-j02 \
--timeout=60s \
>"$EVIDENCE/cases/J03/wait.stdout" \
2>"$EVIDENCE/stderr/J03-wait.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cases/J03/wait.status"
kubectl get pod -n "$NS" "$POD" -o json \
>"$EVIDENCE/cases/J03/final.pod.json"
kubectl get job -n "$NS" job-j02 -o json \
>"$EVIDENCE/cases/J03/final.job.json"EXPECTED / NOT EXECUTED: the Job UID and Pod UID match the J02 checkpoint; helper termination changes the remaining ordinary-container state; the Pod can then reach Succeeded, followed by terminal Job completion. That controlled release is stronger causal evidence than merely waiting longer or deleting the Pod.
Validate the native-sidecar comparison
J04 must be a fresh Job with a different Job UID and Pod UID. Its supporting process moves to .spec.initContainers and gains restartPolicy: Always. Kubernetes v1.33 defines that placement as a sidecar and explicitly documents that native sidecars do not prevent Job completion after main application work finishes.
export CASE=J04 MAIN_EXIT=0
mkdir -p "$EVIDENCE/cases/$CASE"
./render-job.sh >"$EVIDENCE/manifests/$CASE.yaml"
kubectl apply -f "$EVIDENCE/manifests/$CASE.yaml"
kubectl get job -n "$NS" job-j04 -o yaml \
>"$EVIDENCE/cases/$CASE/admitted.job.yaml"
POD="$(kubectl get pod -n "$NS" -l job-name=job-j04 \
-o jsonpath='{.items[0].metadata.name}')"
kubectl get pod -n "$NS" "$POD" -o json \
>"$EVIDENCE/cases/$CASE/pre-release.pod.json"
jq '.spec.initContainers |
map({name,image,restartPolicy,command,args})' \
"$EVIDENCE/cases/$CASE/pre-release.pod.json" \
>"$EVIDENCE/cases/$CASE/admitted-initcontainers.json"Do not approve the case from the local YAML. The admitted Pod object must still show helper under initContainers with restartPolicy: Always.
Release main only after the helper marker exists and the native helper's status is captured:
kubectl exec -n "$NS" "$POD" -c main -- \
test -e /ctl/helper-started
kubectl exec -n "$NS" "$POD" -c main -- \
touch /ctl/release-main
kubectl wait -n "$NS" --for=condition=complete job/job-j04 \
--timeout=60s \
>"$EVIDENCE/cases/$CASE/wait.stdout" \
2>"$EVIDENCE/stderr/$CASE-wait.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cases/$CASE/wait.status"Kubernetes documents that, during Pod termination, native sidecars are stopped after the ordinary application containers; if there are multiple sidecars, shutdown proceeds in reverse order. The experiment should capture actual state without asserting a fixed shutdown latency.
EXPECTED / NOT EXECUTED: main exits 0; the native helper no longer acts as an ordinary application-container blocker; the Pod eventually reaches a terminal successful phase and the Job gains Complete=True. Actual helper termination details remain unfilled until execution.
Capture the complete lifecycle evidence
Every case directory should contain the submitted manifest, admitted Job YAML, raw Job JSON, raw Pod JSON, logs, command stdout, command stderr, shell return status and timestamps marking the observation interval.
A basic collector:
collect_case() {
case_id="$1"
job="$2"
pod="$3"
dir="$EVIDENCE/cases/$case_id"
mkdir -p "$dir"
date -u +%FT%TZ >"$dir/collection-start.txt"
kubectl get job -n "$NS" "$job" -o json \
>"$dir/job.json" 2>"$EVIDENCE/stderr/$case_id-job.stderr"
printf '%s\n' "$?" >"$dir/job-get.status"
kubectl get pod -n "$NS" "$pod" -o json \
>"$dir/pod.json" 2>"$EVIDENCE/stderr/$case_id-pod.stderr"
printf '%s\n' "$?" >"$dir/pod-get.status"
kubectl logs -n "$NS" "$pod" --all-containers=true \
>"$dir/logs.txt" 2>"$EVIDENCE/stderr/$case_id-logs.stderr"
printf '%s\n' "$?" >"$dir/logs.status"
kubectl get events -n "$NS" -o json \
>"$dir/events.json" 2>"$EVIDENCE/stderr/$case_id-events.stderr"
printf '%s\n' "$?" >"$dir/events.status"
date -u +%FT%TZ >"$dir/collection-end.txt"
}Retain at minimum: run ID, Job UID, Pod owner reference, Pod UID, node name, image reference, runtime imageID, client/server versions, Pod phase, Job conditions, observation-window boundaries and cleanup evidence.
Generate an artifact inventory without modifying files:
find "$EVIDENCE" -type f -print0 |
sort -z |
xargs -0 sha256sum \
>"$EVIDENCE/SHA256SUMS"Events are supplementary. Missing events do not prove an event never happened because event retention and aggregation are separate from Pod/Job status. The decisive lifecycle record is the API object state plus container statuses.
Read both container-status arrays
A collector that reads only .status.containerStatuses cannot prove J04 or J08 because Kubernetes exposes init-container status separately under .status.initContainerStatuses.
Extract both:
jq '{
podUID: .metadata.uid,
phase: .status.phase,
app: (.status.containerStatuses // [] |
map({
name, image, imageID, started, restartCount,
state, lastState
})),
init: (.status.initContainerStatuses // [] |
map({
name, image, imageID, started, restartCount,
state, lastState
}))
}' "$EVIDENCE/cases/J04/pod.json" \
>"$EVIDENCE/cases/J04/status-summary.json"Retain terminated.exitCode, terminated.signal, terminated.startedAt, terminated.finishedAt, state, lastState, restartCount, imageID and started whenever present.
Pod phase definitions are coarse summaries, not substitutes for those per-container states. Kubernetes documents container state separately from Pod phase and identifies native sidecars through init-container placement plus container-level restartPolicy: Always.
Exercise failure, initialization and multiple-app boundaries
J05 asks whether sidecar classification can incorrectly convert failed main work into success. It must not.
export CASE=J05 MAIN_EXIT=42
./render-job.sh >"$EVIDENCE/manifests/J05.yaml"
kubectl apply -f "$EVIDENCE/manifests/J05.yaml"After helper startup, release main exactly as in J04. EXPECTED / NOT EXECUTED: main terminates 42; the native helper's special lifecycle does not reinterpret required application failure as success; the final Job condition is Failed, not Complete. Do not infer Job failure merely from a helper's shutdown exit code; reconcile the required application container, Pod phase and final Job condition together. Kubernetes distinguishes the Pod's container states from the Job's terminal conditions.
J06 uses an ordinary init container with no container-level restartPolicy: Always. Kubernetes documents ordinary init containers as sequential startup work that must successfully complete before application containers start.
EXPECTED / NOT EXECUTED: helper is running in .status.initContainerStatuses; main has no started application execution; the Pod is blocked in initialization rather than blocked after successful main completion. That is the diagnostic distinction a careless “sidecar stuck” label can miss.
J07 adds two ordinary application containers plus the native helper. The second app uses the same gate mechanism:
containers:
- name: app-a
image: busybox@sha256:73aaf090f3d85aa34ee199857f03fa3a95c8ede2ffd4cc2cdb5b94e566b11662
command: ["/bin/sh","-c"]
args: ["while [ ! -e /ctl/release-a ]; do sleep 1; done; exit 0"]
volumeMounts:
- {name: ctl, mountPath: /ctl}
- name: app-b
image: busybox@sha256:73aaf090f3d85aa34ee199857f03fa3a95c8ede2ffd4cc2cdb5b94e566b11662
command: ["/bin/sh","-c"]
args: ["while [ ! -e /ctl/release-b ]; do sleep 1; done; exit 0"]
volumeMounts:
- {name: ctl, mountPath: /ctl}Release A, capture the state while B remains running, then release B. EXPECTED / NOT EXECUTED: A's success alone is insufficient. Native-sidecar semantics do not make still-running ordinary application work optional. Completion follows only after the remaining application work is finished. This follows from the sidecar contract's distinction between application containers and restartable init sidecars.
For J08, make the native helper fail once using an emptyDir marker:
initContainers:
- name: helper
image: busybox@sha256:73aaf090f3d85aa34ee199857f03fa3a95c8ede2ffd4cc2cdb5b94e566b11662
restartPolicy: Always
command: ["/bin/sh","-c"]
args:
- |
if [ ! -e /ctl/helper-failed-once ]; then
touch /ctl/helper-failed-once
echo HELPER_FIRST_FAILURE
exit 17
fi
touch /ctl/helper-started
while :; do sleep 1; done
volumeMounts:
- {name: ctl, mountPath: /ctl}Do not assert a restart delay. Wait for restartCount >= 1 and /ctl/helper-started, capture state and lastState, then release main.
EXPECTED / NOT EXECUTED: helper restart history is visible in initContainerStatuses, independent of main completion. Kubernetes documents native sidecars as restartable init containers that can restart independently.
Reconcile each case against its prewritten expectation
The reconciliation ledger is the acceptance object; kubectl apply returning zero is not.
Case | Layout | Expected | Observed artifacts | Job UID | Pod UID | Main/app termination | Helper evidence | Pod phase | Job condition | Completeness | Verdict |
J01 | Main only | success baseline | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | n/a | unfilled | unfilled | unfilled | HOLD |
J02 | Ordinary helper | blocked during 60s window | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | HOLD |
J03 | Same J02 identity | controlled completion | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | HOLD |
J04 | Native sidecar | finite completion | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | HOLD |
J05 | Native + main 42 | failure retained | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | HOLD |
J06 | Ordinary init | startup blocked | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | HOLD |
J07 | Native + two apps | B still matters | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | HOLD |
J08 | Native restart | restart retained | EXPECTED / NOT EXECUTED | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | unfilled | HOLD |
J09 | Evidence mutation | evaluator rejects | EXPECTED / NOT EXECUTED | source only | source only | retained copy | removed array | retained | retained | deliberately incomplete | HOLD |
Compare effective manifests as well as outcomes. For J04/J05/J07/J08, require the admitted Pod spec to place the helper in initContainers and to retain restartPolicy: Always. A green outcome under the wrong admitted spec is not validation of native-sidecar migration.
J02 is a passing diagnostic control if the captured main is terminated successfully, the helper is still running and Complete remains absent for the declared observation window. Calling that case “failed” simply because its Job did not finish would reverse the purpose of the experiment.
Lifecycle completion also does not establish scheduled business-period correctness. If the operational concern is catch-up or replay of scheduled work, reconcile missed CronJob business periods as a separate acceptance problem.
Repair the workload and rehearse recovery
The repair decision begins with role ownership, not YAML syntax.
If the companion is supporting work whose lifecycle may legitimately end after required application work terminates, build a fresh Job template using the native-sidecar form and re-run the controls. Kubernetes v1.33's documented Job behavior is the contract being tested: restartable init sidecars do not prevent Job completion after main application containers finish.
If the companion performs work indispensable to business success (an acknowledgment, durable transfer, commit, export or equivalent), do not reclassify that work simply to make the Job turn green. Define an explicit application-level completion contract instead. Native Job completion says nothing by itself about whether an external log destination received every line or an exporter flushed successfully.
Promote an approved manifest through the same controlled change mechanism used for other workload specifications. The adjacent Kubernetes CI/CD pipeline foundations material can frame that delivery discipline, but it is not evidence for sidecar lifecycle semantics.
Recovery steps are:
Freeze the failing case directory and compute checksums before changes.
Confirm the effective admitted helper placement.
Classify the helper as supporting or indispensable work.
If supporting, render a new fixture Job using the native-sidecar template.
Run J01–J09 under a fresh run ID.
Compare each new case against the prewritten oracle.
Preserve any divergence rather than replacing it with a new run.
Approve only after evidence completeness and cleanup both pass.
Preserve the failed run before replacing Jobs
Do not treat an existing Job's Pod template as a scratch object for the repaired layout. Use a new Job name and new UID for the repaired attempt. J02 and J03 are the one intentional exception in this playbook: they are two checkpoints of the same controlled ordinary-helper case.
Archive before cleanup:
tar -C "$(dirname "$EVIDENCE")" \
-czf "${EVIDENCE}.tar.gz" \
"$(basename "$EVIDENCE")"
sha256sum "${EVIDENCE}.tar.gz" \
>"${EVIDENCE}.tar.gz.sha256"Then remove only fixture-owned resources:
kubectl delete namespace "$NS" \
>"$EVIDENCE/cleanup-namespace.stdout" \
2>"$EVIDENCE/stderr/cleanup-namespace.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cleanup-namespace.status"
kind delete cluster --name "$CLUSTER" \
>"$EVIDENCE/cleanup-cluster.stdout" \
2>"$EVIDENCE/stderr/cleanup-cluster.stderr"
printf '%s\n' "$?" >"$EVIDENCE/cleanup-cluster.status"For this article those cleanup results are EXPECTED / NOT EXECUTED. Never write “cleanup succeeded” without retained command and object evidence.
Apply the ACCEPT / REPAIR / RERUN / HOLD matrix
The release vocabulary is intentionally strict.
Condition | Decision | Owner | Next evidence |
All required cases executed on the pinned environment; identities complete; effective specs match; J02/J03 controls behave as expected; J04 native comparison matches; J05–J09 controls pass; cleanup verified | ACCEPT | Release approver | Retained artifact bundle and checksum |
Reproducible helper placement defect, missing restartPolicy: Always, or collector fails to capture required arrays | REPAIR | Workload or fixture owner | Corrected manifest/collector plus fresh controlled validation |
Fixture is valid but run was interrupted, contaminated or externally modified | RERUN | Fixture owner | New run ID, new Job/Pod UIDs, preserved interrupted run |
Workload digest unresolved, pinned versions mismatch, tests unexecuted, evidence missing, evaluator cannot discriminate, or runtime contradicts documented contract without explanation | HOLD | Platform/version owner + release approver | Resolve identity or divergence before any acceptance |
The current article verdict is HOLD (EXPECTED / NOT EXECUTED). The manifests and oracle are authored; no cluster run has populated observed fields. A future ACCEPT is conditional on retained evidence, not on confidence in the documentation alone.
Record ownership and the limits of the result
Fixture and collector ownership belongs to the engineer maintaining the reproducible harness. Platform-version ownership covers kind v0.28.0, Kubernetes v1.33.1, kubectl v1.33.1, host architecture, container runtime and immutable image resolution. Application ownership decides whether the companion is genuinely supporting work or required business work. Release approval is a separate responsibility: it checks that the evidence supports the intended contract rather than merely that the commands completed.
This result is deliberately scoped to one historical single-cluster fixture. Kubernetes v1.33 documentation is an archived versioned snapshot, not a statement about the latest supported Kubernetes release. The sidecar behavior is documented for that contract; any discrepancy in the pinned runtime must be retained and investigated rather than silently replaced with another version.
Completion proves neither exactly-once business effects nor external delivery. CronJob recovery is a separate topic. Likewise, deletion-hook timing and grace-period consumption belong to the separate Kubernetes preStop shutdown budgets boundary.
Before namespace or cluster removal, preserve raw API objects, logs, command statuses, version captures and artifact checksums.
Build these operational foundations with Refonte Learning
The practical conclusion is narrow: an ordinary long-running companion in .spec.containers remains part of ordinary application-container completion, while a Kubernetes-native sidecar is declared in .spec.initContainers with container-level restartPolicy: Always and follows the documented sidecar lifecycle for finite Jobs. Acceptance still requires an admitted-spec check, complete container-status evidence and successful controls.
For engineers building the underlying platform skills, Refonte Learning's DevOps Engineering Program lists a three-month, 12–14-hours-per-week program covering Linux and scripting, Git/GitHub, CI/CD, Docker/Kubernetes, Terraform, cloud platforms, monitoring/logging and a capstone. It describes mentor guidance, projects and potential internship opportunities; those are foundations rather than a claim that this specialized native-sidecar validation lab is part of the curriculum.
