Native Sidecar Containers with restartPolicy: Always
Intermediate · 30 minutes · 5 tasks, checked automatically · 100 points
In Kubernetes 1.29+, native sidecar containers are defined as init containers with `restartPolicy: Always`. Unlike traditional init containers, these sidecars start before the main containers, run alongside them for the lifetime of the Pod, and restart independently if they crash — without restarting the entire Pod. This lab walks you through creating a namespace, deploying a Pod that uses a native log-shipping sidecar, verifying lifecycle ordering, and observing how the sidecar restarts independently from the main container.
What you’ll learn
- Understand the difference between traditional init containers and native sidecar containers (restartPolicy: Always)
- Deploy a Pod that uses a native sidecar to ship logs from a shared volume alongside the main application container
- Observe that the native sidecar starts before the main container, persists for the Pod lifetime, and can restart independently
How this lab works
- Start the lab: One click starts a real Kubernetes cluster on your computer (kind), with kubectl ready in a toolbox terminal.
- Work through 5 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work reads your live cluster and says, task by task, what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Cluster: A real Kubernetes cluster on your computer (kind)
- Kubernetes: 1.34.8
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- Docker Desktop installed and running
- A kind cluster created in the Kubernetes Playground
Topics: kubernetes, sidecar, init-containers, restartPolicy, pod-lifecycle, logging, v1.29+
Create a free account to start this lab.
Keep going
- Self-Healing Pods with Liveness and Readiness Probes
- Set Resource Requests and Limits (and Trigger an OOMKill)
- Persist Data with PersistentVolumeClaims and StorageClasses
- Run a Stateful Database with a StatefulSet and Headless Service
- Schedule Pods with NodeSelectors, Affinity, and Taints/Tolerations
- Lock Down a Pod with RBAC (ServiceAccount, Role, RoleBinding)