Init Container Restart — control init container restart behavior.
1apiVersion: v12kind: Pod3metadata:4 name: my-pod5spec:6 initContainers:7 - name: init-18 image: busybox:1.369 command: ["sh", "-c", "echo init-1 && exit 0"]10 restartPolicy: Never # Don't restart on success11 - name: init-212 image: busybox:1.3613 command: ["sh", "-c", "echo init-2 && exit 1"] # Will fail14 restartPolicy: Always # Restart on failure15 - name: init-316 image: busybox:1.3617 command: ["sh", "-c", "echo init-3 && exit 0"]18 # Default: Always19 containers:20 - name: app21 image: myapp:latest22 restartPolicy: Always
1# Check init container status2kubectl get pod my-pod -o jsonpath='{.status.initContainerStatuses}' | jq34# Check restart count5kubectl get pod my-pod -o jsonpath='{.status.initContainerStatuses[*].restartCount}'67# Watch init containers8kubectl get pod my-pod -w9kubectl describe pod my-pod | grep -A 10 "Init Containers"1011# Check last state12kubectl get pod my-pod -o jsonpath='{.status.initContainerStatuses[*].lastState}' | jq1314# View init container logs15kubectl logs my-pod -c init-116kubectl logs my-pod -c init-2 --previous # Previous instance
Restart Policies:
Behavior: