Skip to content

Add build rules and instructions for enabling Istio sidecar injection#278

Merged
ian-mi merged 14 commits intoknative:masterfrom
ian-mi:istio-inject-sidecar
Mar 9, 2018
Merged

Add build rules and instructions for enabling Istio sidecar injection#278
ian-mi merged 14 commits intoknative:masterfrom
ian-mi:istio-inject-sidecar

Conversation

@ian-mi
Copy link
Copy Markdown
Contributor

@ian-mi ian-mi commented Mar 2, 2018

This requires removing the fluentd sidecar which currently requires connectivity with services outside of the mesh. mdemirhan is looking at adding different fluentd sidecar to replace this.

Please also note that a few extra setup steps are required to enable automatic sidecar injection.

Comment thread README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this as part of "everything" and not a separate step. Otherwise, once we rip out nginx, without sidecar injection, traffic will not be properly handled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that this should only happen once for the lifetime of the cluster and not during every everything.apply for example. One solution might be to create a new build rule for initial setup only where we can add this. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea. We will need other things of this nature in the future and we can add all one-time cluster initialization in there.

Comment thread README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will enable injection for all pods in the default namespace, including the autoscale pod. Is there a way to enable injection only for ela generated pods?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind. Looking below, seems like you are explicitly disabling injection for autoscale.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will enable injection for builds too. Can we opt pods into this instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found any documentation about opt-in behavior. The istio-inject configmap has a policy field which might do what we want but perhaps builds should be explicitly opted-out or run in a separate namespace. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we already have some code that injects side cars, what's the benefit for using istio here, instead of injecting the istio sidecar in the controller? Seems odd that we have one way of injecting some sidecars than others.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the benefit would be that the istio-proxy sidecar spec can be owned by istio and be mostly transparent to us. Right now our build rules tightly couple us to an istio version but ideally elafros could be installed on any cluster with istio + automatic sidecar injection and use the same istio-proxy sidecar that is injected for other services within the cluster.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My one concern is that I can see there being different capabilities that get lit up based on the type of revision. This seems like something that could be configurable. Right now configuration/revision is something that is a self standing unit and can be used as a building block and while I think it's indeed nice to rely on Istio for this injection I can also see that this might be tuneable for different kinds of workloads. Currently it's very hardcoded what k8s resources revision creates, but this should change. Thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that ideally we would push for the capabilities we need to be supported by istio and configurable through CRDs such as RouteRules or DestinationRules rather than by modifying the sidecar spec. Note that we're also not locked into this decision as we can disable automatic injection on a per-revision basis if needed if, for example, we want to transition to something like istio/istio#3816.

@ian-mi ian-mi requested a review from mattmoor March 3, 2018 00:25
Copy link
Copy Markdown
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments inline.

I'm very impressed with your Bazel-fu! :)

Comment thread ca_bundle.bzl Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have -c _CLUSTER_NAME where the cluster name is passed through from the workspace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've copied the command used to extract the user override for the cluster role binding. It might be nice to perform extraction of these variables in another repository rule at some point.

Comment thread WORKSPACE Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this cluster_ca_bundle for more clarity?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread BUILD.istio Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can drop the kind, this is becoming vestigial

Comment thread README.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will enable injection for builds too. Can we opt pods into this instead?

Comment thread BUILD.istio Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes the current kubectl context is where you want it vs. an explicit cluster argument. You should at least make the docs note this (or how to check that their cluster variable $K8S_CLUSTER_OVERRIDE matches the current context kubectl config current-context)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking inside of this script, this looks like it would be non-trivial to incorporate into our k8s_object rules, but I think it's doable through some custom logic (and I'd like to keep our setup to :everything.apply). Can you open an issue and assign it to me?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, here's an issue describing kind of what I had in mind: bazelbuild/rules_k8s#88

@google-prow-robot google-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 8, 2018
Comment thread WORKSPACE Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this before, I'd meant: "Can we change the name or the rule to cluster_ca_bundle?"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the rule as well.

Comment thread ca_bundle.bzl Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see what you meant earlier. I didn't realize _CLUSTER was insufficient. :(

Comment thread ca_bundle.bzl Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: -n vs. --cluster

I'd use -c or --namespace :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up using --cluster since kubectl doesn't appear to have a short version for this. I've switched to --namespace to match.

Comment thread README.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my only remaining major problem is that this will break Build going in as-is since those Pods are not annotated: knative/build#73

I think we should add the opt-out for Build pods, but is there a more surgical way we should recommend that folks opt into this until we can get an updated Build into Elafros?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option would be to include an istio-inject configmap with policy: disabled. I've confirmed that the sidecar.istio.io/inject annotation will override this policy effectively making all namespaces opt-in vs. opt-out. As long as we always set this annotation elafros should work with the inject-policy enabled or disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone ahead an implemented this using an expand_template rule. It is kind of a hack but allows us to use the upstream template.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattmoor This is ready for another look.

Copy link
Copy Markdown
Member

@mattmoor mattmoor Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, if you want to TAL at: knative/build#74 I can try to merge Build into the Elafros repo tomorrow.

@ian-mi ian-mi merged commit 0b45313 into knative:master Mar 9, 2018
@ian-mi ian-mi deleted the istio-inject-sidecar branch March 9, 2018 21:28
markusthoemmes referenced this pull request in openshift/knative-serving Apr 3, 2019
…#278)

* Upgrade istio to v0.6.0

* Add build rules for setting up istio's automatic sidecar injector.

* Remove fluentd sidecar.

* Set annotations to explicitly enable/disable sidecar injection.

Sidecar injection should be enabled for ela pods and disabled for
autoscaler pods.

* Document steps for enabling Istio sidecar injection.

* Respect the cluster override when fetching CA bundle.

* Rename ca_bundle rule to cluster_ca_bundle.

* Remove unnecessary kind from istio-sidecar-injector-configmap.

* Use --namespace instead of -n in ca_bundle.bzl

* Change istio build target to disable istio sidecar injection.

This will allow istio sidecars to be injected for elafros pods without
changing the default behavior of the rest of the default namespace.

* Rename ca_bundle rule to cluster_ca_bundle.
skonto pushed a commit to skonto/serving that referenced this pull request Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants