Skip to content

[DISCUSS] Sidecar vs init containers differences #12102

Closed

Description

@skonto

This is issue is meant for discussing with the community, sidecar vs init containers semantics/differences, related comment here. This discussion would affect among others the k8s validation logic. Right now init containers are considered to have more freedom as they run before the app code and not along with it. For example there is no restriction for the ports to have a specific name. However, init containers for the most part share the same restrictions as the rest of the containers eg. forbidden ports. Shared common cases here.

/cc @dprotaso @markusthoemmes @julz @evankanderson

Activity

  1. added
    kind/feature
    on Oct 7, 2021
  2. julz commented on Oct 7, 2021

    @julz
    Contributor

    questions off the top of my head:

    1. Are there any use cases we can identify for opening the ports (etc)? (This may be the most important factor, to me, because if we can't think of a good use case, I'd err on the side of keeping surface area smaller at first and expanding later)
    2. How difficult is it to open/not open things, are we talking about a lot more complexity/maintenance one way or another or is it roughly the same?
    3. If we allow init containers to have ports, does that open the possibility of (for example) exceeding containerConcurrency? If so, do we care?
    4. Does allowing init containers to have ports work reasonably with the activator's "probe the queue port for readiness so that we can detect readiness before k8s does" optimisation? If an init container was on the queue port it might report success when it shouldn't (although that's probably easy to validate specifically).
  3. skonto commented on Oct 7, 2021

    @skonto
    ContributorAuthor

    @julz here is my pov:

    1. Init container ports can be useful eg. debugging with a profiler, scraping metrics, custom logic that opens some port waiting to get notified for some other service to be available etc.

    2. This affects mostly validation logic.

    3. Autoscaler should skip scraping pods that are not in ready state eg. running init containers. Also Init containers ports are not exposed under a service so they should not be accessible that way.

    4. looking at the kubelet's probe manager logic here, readiness probing happens after init containers are run to completion. Readiness probe cannot happen if the normal containers are not in running state also there is no probe worker registered for init containers. This is reasonable as:

      init containers do not support lifecycle, livenessProbe, readinessProbe, or startupProbe because they must run to completion before the Pod can be ready

    We could avoid ports completely if we see that 1) is not important.

  4. julz commented on Oct 8, 2021

    @julz
    Contributor

    I think I need more specific examples for some of the things in 1 to get my head around them. An init container (as opposed to a sidecar) presumably exits before anything else, so wouldn't be much use for debuggers/metrics etc, or is that assumption incorrect?

  5. skonto commented on Oct 11, 2021

    @skonto
    ContributorAuthor

    @julz here is a similar discussion prometheus/prometheus#5563 about including initContainers for Prometheus scraping and why they are added.

  6. julz commented on Oct 11, 2021

    @julz
    Contributor

    But since we don't recommend (I think?) scraping for regular or sidecar containers, does it seem a bit odd to enable it just for init containers? I understand in a use case where it's a good idea to scrape in general that scraping init containers too might make sense, but we've always said that since scraping wasn't a good idea for the ephemeral containers knative creates that we wouldn't add features like extra ports etc for scraping. It seems at fist pass like maybe a feature we'd either want to support generically, or not. Are there users/use cases where you don't need an extra port to scrape on the main or any sidecar containers, but you really want one on the init containers only?

  7. skonto commented on Oct 11, 2021

    @skonto
    ContributorAuthor

    But since we don't recommend (I think?) scraping for regular or sidecar containers, does it seem a bit odd to enable it just for init containers?

    I am not sure I follow. This is already done by users via the Prometheus exporter eg. port 9090. User containers can be scraped via a service monitor as usual. Not all users are moving at once to the OTEL architecture (push model) and not all workloads are that short-lived.

    Are there users/use cases where you don't need an extra port to scrape on the main or any sidecar containers, but you really want one on the init containers only?

    There might be if you want to debug some slow step eg. have an init container that downloads a big ML model for whatever reason. As in the case of Prometheus scraping there might be a good reason. So I cant say definitely no there aren't.

  8. skonto commented on Oct 12, 2021

    @skonto
    ContributorAuthor

    Btw additionally right now we do no image resolution for the init containers. Does it make sense to have it? I am inclined to say yes.

  9. markusthoemmes commented on Oct 12, 2021

    @markusthoemmes
    Contributor

    Yes, we have to have it. I'd consider it a bug if we don't currently.

  10. skonto commented on Oct 12, 2021

    @skonto
    ContributorAuthor

    @markusthoemmes this is wip, the feature is not alpha yet. The work is being tracked in #12024 I will add this one too.

  11. markusthoemmes commented on Oct 12, 2021

    @markusthoemmes
    Contributor

    Sure, that's fine. Just wanted to underline that I think container resolution is absolutely necessary.

  12. ggaaooppeenngg commented on Nov 30, 2021

    @ggaaooppeenngg

    In our environment, we want to secure pod egress traffic by adding iptables rules in the init containers to redirect traffic to our proxy. Can the security context (like add NET_ADMIN capability) check be removed for init containers?

  13. skonto commented on Nov 30, 2021

    @skonto
    ContributorAuthor

    Hi @ggaaooppeenngg could you try enable the capabilities feature via the features configmap and then define the right Drop: rule? Security context should be also supported for init containers.

  14. ggaaooppeenngg commented on Dec 1, 2021

    @ggaaooppeenngg

    By applying the config below, it works!

    kubernetes.containerspec-addcapabilities: enabled
    kubernetes.podspec-init-containers: enabled
    kubernetes.podspec-securitycontext: enabled
    
  15. github-actions commented on Mar 2, 2022

    @github-actions

    This issue is stale because it has been open for 90 days with no
    activity. It will automatically close after 30 more days of
    inactivity. Reopen the issue with /reopen. Mark the issue as
    fresh by adding the comment /remove-lifecycle stale.

  16. added
    lifecycle/stale
    on Mar 2, 2022
  17. moved this from In Progress to In Design in Serving API Roadmapon Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featurelifecycle/stale

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions