Skip to main content

Sidecar Injection

Sidecar injection is the automatic process by which a service mesh adds its proxy container to new pods. A Kubernetes mutating admission webhook rewrites the pod spec at creation time, so your manifests do not change.

How it works

When a pod creation request reaches the API server, the mesh's webhook intercepts it and adds the proxy container (and an init container or CNI step that sets up traffic redirection). The pod then starts with the app and the sidecar together.

flowchart TD D["Deployment creates pod"] --> A["API server"] A -->|"admission call"| W["Mutating webhook
mesh injector"] W -->|"adds proxy container"| A A --> P["Pod starts
app + sidecar"] classDef step fill:#DBEAFE,color:#1E293B classDef hook fill:#EDE9FE,color:#1E293B classDef out fill:#D1FAE5,color:#1E293B class D,A step class W hook class P out

Enable it

Bash
kubectl label namespace production istio-injection=enabled
kubectl get namespace production --show-labels
kubectl rollout restart deployment -n production # existing pods need a restart

Istio also supports revision labels (istio.io/rev=<revision>) for canary upgrades of the mesh. Per-pod control uses the sidecar.istio.io/inject label.

Verify

Bash
kubectl get pods -n production
# orders-api-abc-xyz 2/2 Running
# 2/2 means app and sidecar. 1/1 means injection did not happen.

Manual injection

Bash
istioctl kube-inject -f deployment.yaml | kubectl apply -f -
Remember

Labeling a namespace only affects new pods. Existing pods keep running without a sidecar until recreated.

Common Mistake

Enabling injection in kube-system or istio-system. Core components should not have their traffic proxied.

Tip

Injection is a prerequisite for sidecar-based mTLS, so run PERMISSIVE mTLS while you roll it out.

Frequently Asked Questions

How does a sidecar get added without editing my YAML?

A mutating admission webhook intercepts pod creation and modifies the pod spec before it is persisted. Your Deployment manifest is untouched, and the change happens at the API server.

What is a common gotcha with injection?

Jobs may never complete because the sidecar keeps running, and startup ordering can cause early outbound calls to fail. Native sidecar containers and mesh settings address this.

How do I skip injection for one pod?

Label the pod with sidecar.istio.io/inject set to false.

Found a mistake, an outdated step or a broken link?