Sidecar Containers [page]deterministic
Sidecar containers are the secondary containers that run along with the main application container within the same [Pod](#gloss:pod). These containers are used to enhance or to extend the functionality of the primary _app container_ by providing additional services, or functionality such as logging, monitoring, security, or data synchronization, without directly altering the primary application code.
Typically, you only have one app container in a Pod. For example, if you have a web application that requires a local webserver, the local webserver is a sidecar and the web application itself is the app container.
## Sidecar containers in Kubernetes {#pod-sidecar-containers}
Kubernetes implements sidecar containers as a special case of [init containers](/docs/concepts/workloads/pods/init-containers/); sidecar containers remain running after Pod startup. This document uses the term _regular init containers_ to clearly refer to containers that only run during Pod startup.
Provided that your cluster has the `SidecarContainers` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) enabled (the feature is active by default since Kubernetes v1.29), you can specify a `restartPolicy` for containers listed in a Pod's `initContainers` field. These restartable _sidecar_ containers are independent from other init containers and from the main application container(s) within the same pod. These can be started, stopped, or restarted without affecting the main application container and other init containers.
You can also run a Pod with multiple containers that are not marked as init or sidecar containers. This is appropriate if the containers within the Pod are required for the Pod to work overall, but you don't need to control which containers start or stop first. You could also do this if you need to support older versions of Kubernetes that don't support a container-level `restartPolicy` field.
### Example application {#sidecar-example}
Here's an example of a Deployment with two containers, one of which is a sidecar:
> Note: In this example, the sidecar container is intentionally defined under `initContainers` with `restartPolicy: Always`. Kubernetes treats such containers as sidecars that continue running for the lifetime of the Pod.
## Sidecar containers and Pod lifecycle
If an init container is created with its `restartPolicy` set to `Always`, it will start and remain running during the entire life of the Pod. This can be helpful for running supporting services separated from the main application containers.
If a `readinessProbe` is specified for this init container, its result will be used to determine the `ready` state of the Pod.
Since these containers are defined as init containers, they benefit from the same ordering and sequential guarantees as regular init containers, allowing you to mix sidecar containers with regular init containers for complex Pod initialization flows.
Compared to regular init containers, sidecars defined within `initContainers` continue to run after they have started. This is important when there is more than one entry inside `.spec.initContainers` for a Pod. After a sidecar-style init container is running (the kubelet has set the `started` status for that init container to true), the kubelet then starts the next init container from the ordered `.spec.initContainers` list. That status either becomes true because there is a process running in the container and no startup probe defined, or as a result of its `startupProbe` succeeding.
Upon Pod [termination](/docs/concepts/workloads/pods/pod-lifecycle/#termination-with-sidecars), the kubelet postpones terminating sidecar containers until the main application container has fully stopped. The sidecar containers are then shut down in the opposite order of their appearance in the Pod specification. This approach ensures that the sidecars remain operational, supporting other containers within the Pod, until their service …(trimmed)