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
{{ message }}
Repository navigation
[DISCUSS] Sidecar vs init containers differences #12102
kind/featureWell-understood/specified features, ready for coding.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
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.
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)
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?
If we allow init containers to have ports, does that open the possibility of (for example) exceeding containerConcurrency? If so, do we care?
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).
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.
This affects mostly validation logic.
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.
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.
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?
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?
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.
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?
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.
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.
kind/featureWell-understood/specified features, ready for coding.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
Activity
julz commentedon Oct 7, 2021
questions off the top of my head:
skonto commentedon Oct 7, 2021
@julz here is my pov:
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.
This affects mostly validation logic.
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.
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:
We could avoid ports completely if we see that 1) is not important.
julz commentedon Oct 8, 2021
I think I need more specific examples for some of the things in
1to 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?skonto commentedon Oct 11, 2021
@julz here is a similar discussion prometheus/prometheus#5563 about including initContainers for Prometheus scraping and why they are added.
julz commentedon Oct 11, 2021
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?
skonto commentedon Oct 11, 2021
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.
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.
skonto commentedon Oct 12, 2021
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.
markusthoemmes commentedon Oct 12, 2021
Yes, we have to have it. I'd consider it a bug if we don't currently.
skonto commentedon Oct 12, 2021
@markusthoemmes this is wip, the feature is not alpha yet. The work is being tracked in #12024 I will add this one too.
markusthoemmes commentedon Oct 12, 2021
Sure, that's fine. Just wanted to underline that I think container resolution is absolutely necessary.
ggaaooppeenngg commentedon Nov 30, 2021
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?
skonto commentedon Nov 30, 2021
Hi @ggaaooppeenngg could you try enable the capabilities feature via the
featuresconfigmap and then define the rightDrop:rule? Security context should be also supported for init containers.ggaaooppeenngg commentedon Dec 1, 2021
By applying the config below, it works!
github-actions commentedon Mar 2, 2022
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 asfresh by adding the comment
/remove-lifecycle stale.