Knative: Operator’s Handbook

Multiple or sidecar containers

You might need to run sidecar containers in the same Kubernetes Pod as your web application server for various reasons.

If you look at Service manifest, the spec.template.spec.containers field is an array.

However, Knative currently doesn't support specifying more than 1 item in the containers field.

Currently, you'll get an error like:

Internal error occurred: admission webhook “webhook.serving.knative.dev” denied the request: mutation failed: expected exactly one, got both: spec.template.spec.containers.

Workaround

If you are a pro Kubernetes user who really wants to inject sidecar containers to certain pods, consider writing a MutationAdmissionWebhook (an admission controller type for Kubernetes).

Using this, you can intercept Pod objects being submitted by Knative Service (through Kubernetes Deployment → ReplicaSet) and modify the Pod object with the sidecar container, before the Pod is created.