You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: keps/sig-node/0753-sidecarcontainers.md
-113
Original file line number
Diff line number
Diff line change
@@ -386,9 +386,6 @@ During pod termination sidecars will be terminated last:
386
386
387
387
Containers and Sidecar will share the TerminationGracePeriod. If Containers don't exit before the end of the TerminationGracePeriod then they will be sent a SIGKIll as normal, Sidecars will then be sent a SIGTERM with a short grace period of 2 Seconds to give them a chance to cleanly exit.
388
388
389
-
PreStop Hooks will be sent to sidecars before containers are terminated.
390
-
This will be useful in scenarios such as when your sidecar is a proxy so that it knows to no longer accept inbound requests but can continue to allow outbound ones until the the primary containers have shut down.
391
-
392
389
To solve the problem of Jobs that don't complete: When RestartPolicy!=Always if all normal containers have reached a terminal state (Succeeded for restartPolicy=OnFailure, or Succeeded/Failed for restartPolicy=Never), then all sidecar containers will be sent a SIGTERM.
393
390
394
391
Sidecars are just normal containers in almost all respects, they have all the same attributes, they are included in pod state, obey pod restart policy, don't change pod phase in any way etc. The only differences are in the shutdown and startup of the pod.
@@ -398,7 +395,6 @@ Sidecars are just normal containers in almost all respects, they have all the sa
398
395
The proposal can broken down into four key pieces of implementation that all relatively separate from one another:
399
396
400
397
* Shutdown triggering for sidecars when RestartPolicy!=Always
401
-
* Pre-stop hooks sent to sidecars before non sidecar containers
402
398
* Sidecars are terminated after normal containers
403
399
* Sidecars start before normal containers
404
400
@@ -449,11 +445,6 @@ Package `kuberuntime`
449
445
450
446
Modify `kuberuntime_manager.go`, function `computePodActions`. If pods has sidecars it will return these first in `ContainersToStart`, until they are all ready it will not return the non-sidecars. Readiness changes do not normally trigger a pod sync, so to avoid waiting for the Kubelet's `SyncFrequency` (default 1 minute) we can modify `HandlePodReconcile` in the `kubelet.go` to trigger a sync when the sidecars first become ready (ie only during startup).
451
447
452
-
##### PreStop hooks sent to Sidecars first
453
-
Package `kuberuntime`
454
-
455
-
Modify `kuberuntime_container.go`, function `killContainersWithSyncResult`. Loop over sidecars and execute `executePreStopHook` on them before moving on to terminating the containers. This approach would assume that PreStop Hooks are idempotent as the sidecars would get sent the PreStop hook again when they are terminated.
456
-
457
448
### Proposal decisions to discuss
458
449
459
450
This section expands on some decisions or side effects of this proposal that
@@ -469,108 +460,6 @@ Bear in mind that these edge cases discussed here are either present in the KEP
469
460
design or the KEP design was not clear enough and they are present in the
470
461
[current open PR](https://github.com/kubernetes/kubernetes/pull/80744).
471
462
472
-
#### preStop hooks delivery guarantees are changed
473
-
474
-
Kubernetes currently [tries to deliver preStop hooks only once][hook-delivery],
475
-
although in some cases they can be called more than once. [The current
476
-
proposal](#prestop-hooks-sent-to-sidecars-first), however, guarantees that when
477
-
sidecar containers are used preStop hooks will be delivered _at least twice_ for
478
-
sidecar containers.
479
-
480
-
As explained [here](#proposal) the reason this is done is because (the following
481
-
is just c&p from the relevant paragraphs in the proposal):
482
-
483
-
> PreStop Hooks will be sent to sidecars before containers are terminated. This will be useful in scenarios such as when your sidecar is a proxy so that it knows to no longer accept inbound requests but can continue to allow outbound ones until the the primary containers have shut down.
484
-
485
-
In other words, the shutdown sequence proposed is:
486
-
487
-
1. Run preStop hooks for sidecars
488
-
1. Run preStop hooks for non-sidecars
489
-
1. Send SIGTERM for non-sidecars
490
-
1. Run preStop hooks for sidecars
491
-
1. Send SIGTERM for sidecars
492
-
493
-
For brevity, what happens when some step timeouts and needs to send a SIGKILL is
494
-
omitted in the above sequence, as it is not relevant for this point.
495
-
496
-
The concerns we see with this are that this changes the [current delivery
497
-
guarantees][hook-delivery] from _at least once_ to _at least twice_ for _some_
498
-
containers (for sidecar containers). Furthermore, before this patch preStop
499
-
hooks were delivered only once most of the time. After this patch is delivered
500
-
twice for most cases (using sidecars). The problem is not if this is idempotent
501
-
or not (as it should be in any case), but chainging the most common case from
502
-
delivering preStop hook once to twice.
503
-
504
-
Another concern is that in the future a different container type might be added,
505
-
and these semantics seems difficult to extend. For example, let's say a
506
-
container type "OrderedPhases" with the semantics of the [explained
507
-
alternative][phase-startup] is added in the future. When would the preStop hooks
508
-
be executed now that there are several phases? At the beginning? If there are 5
509
-
phases: 0, 1, 2, 3 and 4, how should the shutdown behaviour be? Run preStop
510
-
hooks for containers marked in phase 0, then kill containers in phase 4, then
511
-
preStop hooks for containers in phase 1, then kill containers in phase 3, etc.?
512
-
Or only the preStop hooks for container 0 are called? Why?
513
-
514
-
It seems confusing, there doesn't seem to be a clear answer on those cases nor
0 commit comments