Skip to content

Commit 74aea81

Browse files
authored
Merge pull request #44800 from sftim/20240118_improve_sidecar_container_docs
Update docs around sidecar containers
2 parents 7226b92 + d9723d7 commit 74aea81

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

content/en/docs/concepts/workloads/pods/init-containers.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ for resource usage apply:
331331
Quota and limits are applied based on the effective Pod request and
332332
limit.
333333

334-
Pod level control groups (cgroups) are based on the effective Pod request and
335-
limit, the same as the scheduler.
334+
### Init containers and Linux cgroups {#cgroups}
335+
336+
On Linux, resource allocations for Pod level control groups (cgroups) are based on the effective Pod
337+
request and limit, the same as the scheduler.
336338

337339
{{< comment >}}
338340
This section also present under [sidecar containers](/docs/concepts/workloads/pods/sidecar-containers/) page.

content/en/docs/concepts/workloads/pods/sidecar-containers.md

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,43 @@ weight: 50
99

1010
Sidecar containers are the secondary containers that run along with the main
1111
application container within the same {{< glossary_tooltip text="Pod" term_id="pod" >}}.
12-
These containers are used to enhance or to extend the functionality of the main application
13-
container by providing additional services, or functionality such as logging, monitoring,
12+
These containers are used to enhance or to extend the functionality of the primary _app
13+
container_ by providing additional services, or functionality such as logging, monitoring,
1414
security, or data synchronization, without directly altering the primary application code.
1515

16+
Typically, you only have one app container in a Pod. For example, if you have a web
17+
application that requires a local webserver, the local webserver is a sidecar and the
18+
web application itself is the app container.
19+
1620
<!-- body -->
1721

18-
## Enabling sidecar containers
22+
## Sidecar containers in Kubernetes {#pod-sidecar-containers}
23+
24+
Kubernetes implements sidecar containers as a special case of
25+
[init containers](/docs/concepts/workloads/pods/init-containers/); sidecar containers remain
26+
running after Pod startup. This document uses the term _regular init containers_ to clearly
27+
refer to containers that only run during Pod startup.
28+
29+
Provided that your cluster has the `SidecarContainers`
30+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) enabled
31+
(the feature is active by default since Kubernetes v1.29), you can specify a `restartPolicy`
32+
for containers listed in a Pod's `initContainers` field.
33+
These restartable _sidecar_ containers are independent from other init containers and from
34+
the main application container(s) within the same pod.
35+
These can be started, stopped, or restarted without effecting the main application container
36+
and other init containers.
37+
38+
You can also run a Pod with multiple containers that are not marked as init or sidecar
39+
containers. This is appropriate if the containers within the Pod are required for the
40+
Pod to work overall, but you don't need to control which containers start or stop first.
41+
You could also do this if you need to support older versions of Kubernetes that don't
42+
support a container-level `restartPolicy` field.
43+
44+
### Example application {#sidecar-example}
45+
46+
Here's an example of a Deployment with two containers, one of which is a sidecar:
1947

20-
Enabled by default with Kubernetes 1.29, a
21-
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) named
22-
`SidecarContainers` allows you to specify a `restartPolicy` for containers listed in a
23-
Pod's `initContainers` field. These restartable _sidecar_ containers are independent with
24-
other [init containers](/docs/concepts/workloads/pods/init-containers/) and main
25-
application container within the same pod. These can be started, stopped, or restarted
26-
without effecting the main application container and other init containers.
48+
{{% code_sample language="yaml" file="application/deployment-sidecar.yaml" %}}
2749

2850
## Sidecar containers and Pod lifecycle
2951

@@ -35,8 +57,8 @@ If a `readinessProbe` is specified for this init container, its result will be u
3557
to determine the `ready` state of the Pod.
3658

3759
Since these containers are defined as init containers, they benefit from the same
38-
ordering and sequential guarantees as other init containers, allowing them to
39-
be mixed with other init containers into complex Pod initialization flows.
60+
ordering and sequential guarantees as regular init containers, allowing you to mix
61+
sidecar containers with regular init containers for complex Pod initialization flows.
4062

4163
Compared to regular init containers, sidecars defined within `initContainers` continue to
4264
run after they have started. This is important when there is more than one entry inside
@@ -46,30 +68,28 @@ next init container from the ordered `.spec.initContainers` list.
4668
That status either becomes true because there is a process running in the
4769
container and no startup probe defined, or as a result of its `startupProbe` succeeding.
4870

49-
Here's an example of a Deployment with two containers, one of which is a sidecar:
50-
51-
{{% code_sample language="yaml" file="application/deployment-sidecar.yaml" %}}
71+
### Jobs with sidecar containers
5272

53-
This feature is also useful for running Jobs with sidecars, as the sidecar
54-
container will not prevent the Job from completing after the main container
55-
has finished.
73+
If you define a Job that uses sidecar using Kubernetes-style init containers,
74+
the sidecar container in each Pod does not prevent the Job from completing after the
75+
main container has finished.
5676

5777
Here's an example of a Job with two containers, one of which is a sidecar:
5878

5979
{{% code_sample language="yaml" file="application/job/job-sidecar.yaml" %}}
6080

61-
## Differences from regular containers
81+
## Differences from application containers
6282

63-
Sidecar containers run alongside regular containers in the same pod. However, they do not
83+
Sidecar containers run alongside _app containers_ in the same pod. However, they do not
6484
execute the primary application logic; instead, they provide supporting functionality to
6585
the main application.
6686

6787
Sidecar containers have their own independent lifecycles. They can be started, stopped,
68-
and restarted independently of regular containers. This means you can update, scale, or
88+
and restarted independently of app containers. This means you can update, scale, or
6989
maintain sidecar containers without affecting the primary application.
7090

7191
Sidecar containers share the same network and storage namespaces with the primary
72-
container This co-location allows them to interact closely and share resources.
92+
container. This co-location allows them to interact closely and share resources.
7393

7494
## Differences from init containers
7595

@@ -112,8 +132,10 @@ for resource usage apply:
112132
Quota and limits are applied based on the effective Pod request and
113133
limit.
114134

115-
Pod level control groups (cgroups) are based on the effective Pod request and
116-
limit, the same as the scheduler.
135+
### Sidecar containers and Linux cgroups {#cgroups}
136+
137+
On Linux, resource allocations for Pod level control groups (cgroups) are based on the effective Pod
138+
request and limit, the same as the scheduler.
117139

118140
## {{% heading "whatsnext" %}}
119141

content/en/docs/tasks/run-application/horizontal-pod-autoscale.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pod usage is still within acceptable limits.
283283
The HorizontalPodAutoscaler API also supports a container metric source where the HPA can track the
284284
resource usage of individual containers across a set of Pods, in order to scale the target resource.
285285
This lets you configure scaling thresholds for the containers that matter most in a particular Pod.
286-
For example, if you have a web application and a logging sidecar, you can scale based on the resource
286+
For example, if you have a web application and a sidecar container that provides logging, you can scale based on the resource
287287
use of the web application, ignoring the sidecar container and its resource use.
288288
289289
If you revise the target resource to have a new Pod specification with a different set of containers,

0 commit comments

Comments
 (0)