-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge main into dev-1.29 #44305
Merged
k8s-ci-robot
merged 21 commits into
kubernetes:dev-1.29
from
sftim:20231211_dev_1.29_merge_main
Dec 11, 2023
Merged
Merge main into dev-1.29 #44305
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7a8ed1c
docs: Small fixes to the Resource deletion section of API Concept
austince 5c49e61
Changed yellow color to orange color for better visibility
PranitRout07 d174742
kubeadm: add section on how to use the "generate-csr" command
neolit123 bc7c1db
added a new concept page Sidecar containers and revise details detail…
T-Lakshmi 7518e4e
[pt] Update "Operator White Paper" link on operator.md page
Arhell 83b1334
Update service.md
rohan-kapse 6edfcad
Fix Broken voyager link in ingress-controllers.md
Community-Programmer d2492b5
[zh-cn] sync secret cheatsheet php-apache.yaml
my-git9 c064885
Merge pull request #43719 from PranitRout07/test1
k8s-ci-robot f7ead26
Merge pull request #43689 from austince/patch-1
k8s-ci-robot 2ceb4a4
Modified community index and added x-org image
Manish-hr14 f5ad2c5
Merge pull request #44287 from Manish-hr14/main
k8s-ci-robot 2448333
Merge pull request #44274 from rohan-kapse/patch-7
k8s-ci-robot 4813a41
Merge pull request #44276 from Community-Programmer/main
k8s-ci-robot 43ecd32
Merge pull request #44285 from my-git9/patch-4ro4
k8s-ci-robot af8de40
Merge pull request #44200 from Arhell/pt-operator
k8s-ci-robot 73e33f6
[zh-cn] Update KubeCon dates (#44280)
Fan-Lin b23c499
Revise details for Resource sharing within containers
T-Lakshmi 0c5cb41
Merge pull request #43871 from neolit123/1.29-add-task-for-kubeadm-ge…
k8s-ci-robot 9b9d765
Merge pull request #43346 from T-Lakshmi/sidecar-container
k8s-ci-robot e57cf32
Merge 'dev-1.29' with main
sftim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,11 +150,22 @@ the `Terminated` state. | |
The `spec` of a Pod has a `restartPolicy` field with possible values Always, OnFailure, | ||
and Never. The default value is Always. | ||
|
||
The `restartPolicy` applies to all containers in the Pod. `restartPolicy` only | ||
refers to restarts of the containers by the kubelet on the same node. After containers | ||
in a Pod exit, the kubelet restarts them with an exponential back-off delay (10s, 20s, | ||
40s, …), that is capped at five minutes. Once a container has executed for 10 minutes | ||
without any problems, the kubelet resets the restart backoff timer for that container. | ||
The `restartPolicy` for a Pod applies to {{< glossary_tooltip text="app containers" term_id="app-container" >}} | ||
in the Pod and to regular [init containers](/docs/concepts/workloads/pods/init-containers/). | ||
[Sidecar containers](/docs/concepts/workloads/pods/sidecar-containers/) | ||
ignore the Pod-level `restartPolicy` field: in Kubernetes, a sidecar is defined as an | ||
entry inside `initContainers` that has its container-level `restartPolicy` set to `Always`. | ||
For init containers that exit with an error, the kubelet restarts the init container if | ||
the Pod level `restartPolicy` is either `OnFailure` or `Always`. | ||
|
||
When the kubelet is handling container restarts according to the configured restart | ||
policy, that only applies to restarts that make replacement containers inside the | ||
same Pod and running on the same node. After containers in a Pod exit, the kubelet | ||
restarts them with an exponential back-off delay (10s, 20s,40s, …), that is capped at | ||
five minutes. Once a container has executed for 10 minutes without any problems, the | ||
kubelet resets the restart backoff timer for that container. | ||
[Sidecar containers and Pod lifecycle](/docs/concepts/workloads/pods/sidecar-containers/#sidecar-containers-and-pod-lifecycle) | ||
explains the behaviour of `init containers` when specify `restartpolicy` field on it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this needs a fix at some point |
||
|
||
## Pod conditions | ||
|
||
|
@@ -600,6 +611,8 @@ for more details. | |
|
||
* Learn more about [container lifecycle hooks](/docs/concepts/containers/container-lifecycle-hooks/). | ||
|
||
* Learn more about [sidecar containers](/docs/concepts/workloads/pods/sidecar-containers/). | ||
|
||
* For detailed information about Pod and container status in the API, see | ||
the API reference documentation covering | ||
[`status`](/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodStatus) for Pod. |
126 changes: 126 additions & 0 deletions
126
content/en/docs/concepts/workloads/pods/sidecar-containers.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
--- | ||
title: Sidecar Containers | ||
content_type: concept | ||
weight: 50 | ||
--- | ||
|
||
<!-- overview --> | ||
{{< feature-state for_k8s_version="v1.29" state="beta" >}} | ||
|
||
Sidecar containers are the secondary containers that run along with the main | ||
application container within the same {{< glossary_tooltip text="Pod" term_id="pod" >}}. | ||
These containers are used to enhance or to extend the functionality of the main application | ||
container by providing additional services, or functionality such as logging, monitoring, | ||
security, or data synchronization, without directly altering the primary application code. | ||
|
||
<!-- body --> | ||
|
||
## Enabling sidecar containers | ||
|
||
Starting with Kubernetes 1.28, a | ||
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) named | ||
`SidecarContainers` allows you to specify a `restartPolicy` for containers listed in a | ||
Pod's `initContainers` field. These restartable _sidecar_ containers are independent with | ||
other [init containers](/docs/concepts/workloads/pods/init-containers/) and main | ||
application container within the same pod. These can be started, stopped, or restarted | ||
without effecting the main application container and other init containers. | ||
|
||
## 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 other init containers, allowing them to | ||
be mixed with other init containers into 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. | ||
|
||
Here's an example of a Deployment with two containers, one of which is a sidecar: | ||
|
||
{{% code_sample language="yaml" file="application/deployment-sidecar.yaml" %}} | ||
|
||
This feature is also useful for running Jobs with sidecars, as the sidecar | ||
container will not prevent the Job from completing after the main container | ||
has finished. | ||
|
||
Here's an example of a Job with two containers, one of which is a sidecar: | ||
|
||
{{% code_sample language="yaml" file="application/job/job-sidecar.yaml" %}} | ||
By default, this feature is not available in Kubernetes. To avail this feature, you | ||
need to enable the [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) | ||
named `SidecarContainers`. | ||
|
||
## Differences from regular containers | ||
|
||
Sidecar containers run alongside regular containers in the same pod. However, they do not | ||
execute the primary application logic; instead, they provide supporting functionality to | ||
the main application. | ||
|
||
Sidecar containers have their own independent lifecycles. They can be started, stopped, | ||
and restarted independently of regular containers. This means you can update, scale, or | ||
maintain sidecar containers without affecting the primary application. | ||
|
||
Sidecar containers share the same network and storage namespaces with the primary | ||
container This co-location allows them to interact closely and share resources. | ||
|
||
## Differences from init containers | ||
|
||
Sidecar containers work alongside the main container, extending its functionality and | ||
providing additional services. | ||
|
||
Sidecar containers run concurrently with the main application container. They are active | ||
throughout the lifecycle of the pod and can be started and stopped independently of the | ||
main container. Unlike [init containers](/docs/concepts/workloads/pods/init-containers/), | ||
sidecar containers support [probes](/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe) to control their lifecycle. | ||
|
||
These containers can interact directly with the main application containers, sharing | ||
the same network namespace, filesystem, and environment variables. They work closely | ||
together to provide additional functionality. | ||
|
||
## Resource sharing within containers | ||
|
||
{{< comment >}} | ||
This section is also present in the [init containers](/docs/concepts/workloads/pods/init-containers/) page. | ||
If you're editing this section, change both places. | ||
{{< /comment >}} | ||
|
||
Given the order of execution for init, sidecar and app containers, the following rules | ||
for resource usage apply: | ||
|
||
* The highest of any particular resource request or limit defined on all init | ||
containers is the *effective init request/limit*. If any resource has no | ||
resource limit specified this is considered as the highest limit. | ||
* The Pod's *effective request/limit* for a resource is the sum of | ||
[pod overhead](/docs/concepts/scheduling-eviction/pod-overhead/) and the higher of: | ||
* the sum of all non-init containers(app and sidecar containers) request/limit for a | ||
resource | ||
* the effective init request/limit for a resource | ||
* Scheduling is done based on effective requests/limits, which means | ||
init containers can reserve resources for initialization that are not used | ||
during the life of the Pod. | ||
* The QoS (quality of service) tier of the Pod's *effective QoS tier* is the | ||
QoS tier for all init, sidecar and app containers alike. | ||
|
||
Quota and limits are applied based on the effective Pod request and | ||
limit. | ||
|
||
Pod level control groups (cgroups) are based on the effective Pod request and | ||
limit, the same as the scheduler. | ||
|
||
## {{% heading "whatsnext" %}} | ||
|
||
* Read a blog post on [native sidecar containers](/blog/2023/08/25/native-sidecar-containers/). | ||
* Read about [creating a Pod that has an init container](/docs/tasks/configure-pod-container/configure-pod-initialization/#create-a-pod-that-has-an-init-container). | ||
* Learn about the [types of probes](/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe): liveness, readiness, startup probe. | ||
* Learn about [pod overhead](/docs/concepts/scheduling-eviction/pod-overhead/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved per #43346