Skip to content
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

Sidecar Containers #753

Open
11 tasks done
Joseph-Irving opened this issue Jan 29, 2019 · 220 comments
Open
11 tasks done

Sidecar Containers #753

Joseph-Irving opened this issue Jan 29, 2019 · 220 comments
Assignees
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/node Categorizes an issue or PR as relevant to SIG Node. stage/beta Denotes an issue tracking an enhancement targeted for Beta status

Comments

@Joseph-Irving
Copy link
Member

Joseph-Irving commented Jan 29, 2019

Enhancement Description

/sig node

Please keep this description up to date. This will help the Enhancement Team to track the evolution of the enhancement efficiently.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/node Categorizes an issue or PR as relevant to SIG Node. labels Jan 29, 2019
@Joseph-Irving
Copy link
Member Author

@enisoc @dchen1107 @fejta @thockin @kow3ns @derekwaynecarr, opened this tracking issue so that we can discuss.

@kow3ns
Copy link
Member

kow3ns commented Jan 31, 2019

/assign

@Joseph-Irving
Copy link
Member Author

@derekwaynecarr I've done some scoping out of the kubelet changes required for next week's sig-node meeting, I believe that changes are only needed in the kuberuntime package, specifically kuberuntime_manager.go in and kuberuntime_container.go.

In kuberuntime_manager.go you could modify computePodActions to implement the shutdown triggering (kill sidecars when all non-sidecars have permanently exited), and starting up the sidecars first.

In kuberuntime_container.go you could modify killContainersWithSyncResult for terminating the sidecars last and sending the preStop hooks (the preStop hooks bit was a bit debatable, it wasn't settled whether that should be done or not. @thockin had a good point about why you might not want to encourage that behaviour, see comment).

Let me know if you want me to investigate any further.

@resouer
Copy link

resouer commented Feb 1, 2019

@kow3ns The discussion makes more sense to me if maybe we can define a full description of containers sequence in Pod spec (sig-app), and how to handle the sequence in kubelet for start, restart and cascading consideration (sig-node). Let's catch the Feb 5 sig-node meeting to give more inputs.

cc @Joseph-Irving

@luksa
Copy link

luksa commented Feb 7, 2019

The proposal says that sidecars only run after the init containers run. But what if the use-case requires the sidecar to run while/before the init containers run. For example, if you'd like route the pod's traffic through a proxy running as a sidecar (as in Istio), you probably want that proxy to be in place while the init containers run in case the init container itself does network calls.

@Joseph-Irving
Copy link
Member Author

@luksa I think there's the possibility of looking at having sidecars that run in init phase at some point but currently the proposal is not going to cover that use case. There is currently no way to have concurrent containers running in the init phase so that would be potentially a much larger/messier change than what is being suggested here.

@Joseph-Irving
Copy link
Member Author

Update on this KEP:
I've spoken to both @derekwaynecarr and @dchen1107 from sig-node about this and they did not express any major concerns about the proposal. I will raise a PR to the KEP adding some initial notes around implementation details and clarifying a few points that came up during the discussion.

We still need to agree on the API, it seems there is consensus that a simple way of marking containers as sidecars is prefered over more in depth ordering flags. Having a bool is somewhat limiting though so perhaps something more along the lines of containerLifecycle: Sidecar would be preferable so that we have the option of expanding in the future.

@luksa
Copy link

luksa commented Feb 14, 2019

@Joseph-Irving Actually, neither the boolean nor the containerLifecycle: Sidecar are appropriate for proper future extensibility. Instead, containerLifecycle should be an object, just like deployment.spec.strategy, with type: Sidecar. This would allow us to then introduce additional fields. For the "sidecar for the whole lifetime of the pod" solution, it would be expressed along these lines:

containerLifecycle: 
  type: Sidecar
  sidecar:
    scope: CompletePodLifetime

as opposed to

containerLifecycle: 
  type: Sidecar
  sidecar:
    scope: AfterInit

Please forgive my bad naming - I hope the names convey the idea.

But there is one problem with the approach where we introduce containerLifecycle to pod.spec.containers. Namely, it's wrong to have sidecars that run parallel to init containers specified under pod.spec.containers. So if you really want to be able to extend this to init containers eventually, you should find an alternative solution - one that would allow you to mark containers as sidecars at a higher level - i.e. not under pod.spec.containers or pod.spec.initContainers, but something like pod.spec.sidecarContainers, which I believe you already discussed, but dismissed. The init containers problem definitely calls for a solution along these lines.

@Joseph-Irving
Copy link
Member Author

@luksa You could also solve the init problem by just allowing an init container to be marked as a sidecar and have that run alongside the init containers. As I understand it, the problem is that init containers sometimes need sidecars, which is different from needing a container that runs for the entire lifetime of the pod.

The problem with pod.spec.sidecarContainers is that it's a far more complex change, tooling would need to updated and the kubelet would require a lot of modifying to support another set of containers. The current proposal is far more modest, it's only building on what's already there.

@luksa
Copy link

luksa commented Feb 14, 2019

@Joseph-Irving We could work with that yes. It's not ideal for the sidecar to shut down after the init containers run and then have the same sidecar start up again, but it's better than not having that option. The bigger problem is that older Kubelets wouldn't handle init-sidecar containers properly (as is the case with main-sidecar containers).

I'd just like you to keep init-sidecars in mind when finalizing the proposal. In essence, you're introducing the concept of "sidecar" into k8s (previously, we basically only had a set of containers that were all equal). Now you're introducing actual sidecars, so IMHO, you really should think this out thoroughly and not dismiss a very important sidecar use-case.

I'd be happy to help with implementing this. Without it, Istio can't provide its features to init containers (actually, in a properly secured Kubernetes cluster running Istio, init containers completely lose the ability to talk to any service).

@Joseph-Irving
Copy link
Member Author

In relation to the implementation discussion in #841, I've opened a WIP PR containing a basic PoC for this proposal kubernetes/kubernetes#75099. It's just a first draft and obviously not perfect but the basic functionality works and gives you an idea of the amount of change required.

cc @enisoc

@Joseph-Irving
Copy link
Member Author

I put together a short video just showing how the PoC currently behaves https://youtu.be/4hC8t6_8bTs. Seeing it in action can be better than reading about it.
Disclaimer: I'm not a pro youtuber.

@Joseph-Irving
Copy link
Member Author

I've opened two new PRs:

Any thoughts or suggestions will be much appreciated.

@kfox1111
Copy link

kfox1111 commented Sep 5, 2024

We hit an issue with sidecars being a little undefined. Looking for guidence on what it the right behavior.

When the normal containers exit, the sidecars are shot.

In some cases, they then return exit codes != 0.

At least one k8s client, https://k9scli.io/ considers a completed pod with exit codes other then 0 bad and marks it in its ui as RED.

Its a bit unclear what the expectation around this is. Should it be documented that exit codes != 0 for sidecar containers are normal on main container exit and should be ignored? That would mean k9s's code should be adusted.

If exit code 0 is expected, each sidecar that doesnt return 0 should be adjusted, and perhaps alternate shutdown signals should be supported to the sidecar for more "graceful shutdown" signaling?

@SergeyKanzhelev
Copy link
Member

When the normal containers exit, the sidecars are shot.

In some cases, they then return exit codes != 0.

At least one k8s client, https://k9scli.io/ considers a completed pod with exit codes other then 0 bad and marks it in its ui as RED.

From kubernetes perspective, sidecars will receive the SIGTERM following with SIGKILL. If implemented right, they will exit normally and will not mark pod as "red". @kfox1111 what do you see as a Pod status when it is red?

Should it be documented that exit codes != 0 for sidecar containers are normal on main container exit and should be ignored?

Hiding or recommending to hide the bad exit of sidecar may hide real issues with it. We would really hope that sidecars will be implemented correctly and not get into this situation. So I want to make sure there are only a limited set of situations when sidecar will be marked as failed. Any additional comments on how sidecar was implemented, what graceful period was set, and how long container took to terminate, will help understand your use case better

@kfox1111
Copy link

kfox1111 commented Sep 5, 2024

phase: Succeeded
initContainerStatuses:
  - containerID: docker://e8fd1c45cd995ef68ad84f9825faf4a35f53797d3308877adb59383a48ddfb3d
    image: ghcr.io/spiffe/spiffe-helper:nightly
    imageID: docker-pullable://ghcr.io/spiffe/spiffe-helper@sha256:6b09786251ae4e3ccef193b98eceae4b3d2bed091f3a8dd92be33a4c207455f2
    lastState: {}
    name: spiffe-helper
    ready: false
    restartCount: 0
    started: false
    state:
      terminated:
        containerID: docker://e8fd1c45cd995ef68ad84f9825faf4a35f53797d3308877adb59383a48ddfb3d
        exitCode: 2
        finishedAt: "2024-09-05T20:29:29Z"
        reason: Error
        startedAt: "2024-09-05T20:29:19Z"
containerStatuses:
  - containerID: docker://eda62dbdb9196efa6723f025194d71aa92cedd3d4dd8c862cc803353d0901f38
    image: busybox:latest
    imageID: docker-pullable://busybox@sha256:34b191d63fbc93e25e275bfccf1b5365664e5ac28f06d974e8d50090fbb49f41
    lastState: {}
    name: main
    ready: false
    restartCount: 0
    started: false
    state:
      terminated:
        containerID: docker://eda62dbdb9196efa6723f025194d71aa92cedd3d4dd8c862cc803353d0901f38
        exitCode: 0
        finishedAt: "2024-09-05T20:29:29Z"
        reason: Completed
        startedAt: "2024-09-05T20:29:24Z"

We already decided we're going to update the spiffe-helper to exit 0 on sigterm. it was exiting 2 on sigterm. But may be good to clarify this behavior for other users of the sidecar api so everyone knows what to expect.

@SergeyKanzhelev
Copy link
Member

We already decided we're going to update the spiffe-helper to exit 0 on sigterm. it was exiting 2 on sigterm.

It makes sense. Please let us know if there are other cases when it will become failed unexpectedly.

I wonder if this sidecar was used before the feature was implemented. I would think in the past, sidecar (implemented as a regular container) would also receive SIGTERM on pod delete command. So it was suffering from the same issue

@SergeyKanzhelev
Copy link
Member

Definitely we can benefit from updating this document mentioning this: https://kubernetes.io/docs/tutorials/configuration/pod-sidecar-containers/

@kannon92
Copy link
Contributor

@SergeyKanzhelev I think you all are deciding to not promote this to stable for 1.32. Should we move this for not for release then?

You all can refine the tests and improve bugs but it seems that due to some of the regressions it may not quite be ready for GA. :(

@matthyx
Copy link
Contributor

matthyx commented Sep 12, 2024

@SergeyKanzhelev I think you all are deciding to not promote this to stable for 1.32. Should we move this for not for release then?

You all can refine the tests and improve bugs but it seems that due to some of the regressions it may not quite be ready for GA. :(

Yes this was the decision from this week's meeting.

@SergeyKanzhelev
Copy link
Member

SergeyKanzhelev commented Sep 13, 2024

As we are getting closer to the GA (not in 1.32 though), we want to concentrate in 1.32 on polishing the feature and fixing known bugs.

Listing issues here to have a list of changes related to this KEP in 1.32:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/node Categorizes an issue or PR as relevant to SIG Node. stage/beta Denotes an issue tracking an enhancement targeted for Beta status
Projects
Status: Removed From Milestone
Status: Tracked
Status: Tracked for Code Freeze
Status: Backlog
Status: Not for release
Development

No branches or pull requests