This lesson demonstrates Istio Sidecars and how they affect traffic management. You’ll see how sidecar injection, PeerAuthentication (STRICT mTLS), and the Sidecar CRD interact to control connectivity between workloads. What you’ll learn:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Verify namespace injection labels
- Deploy the Bookinfo sample
- Observe sidecar injection and pod initialization behavior
- Enforce mTLS with PeerAuthentication
- See how namespace labels change connectivity
- Restrict egress with a Sidecar resource and narrow scope with workloadSelector
Prerequisites
- kubectl configured to a cluster with Istio installed
- Istio sidecar injector webhook running
- Basic familiarity with Kubernetes namespaces, pods, and services
1) Verify namespace labels and deploy Bookinfo
Confirm thedefault namespace is labeled for Istio injection:
default:
0/2 or Init:0/1 typically means the Istio sidecar is being injected and is starting:
2/2 Running.
2) Create a test namespace (no injection) and run a client pod
Create a namespacetest that initially has no Istio injection:
test has no istio-injection label):
test:
default and note productpage ClusterIP:
test pod and curl the productpage. Because Istio defaults to permissive behavior (no mTLS enforced), this call should succeed even though the test pod has no sidecar:
3) Enforce mTLS in the default namespace (PeerAuthentication)
Warning: applying a PeerAuthentication mode STRICT will immediately require mTLS for all workloads in the namespace. Clients without an Istio sidecar will not be able to connect.Applying PeerAuthentication with
mode: STRICT will block non-mTLS traffic to workloads in the target namespace. Make sure you understand the impact before applying to production namespaces.default in the default namespace to enforce mTLS:
peer_auth.yaml
productpage from the test pod (still without a sidecar). The call will fail because the default namespace now requires mTLS at the peer level, which is normally provided by the Istio sidecar proxy:
PeerAuthentication in
STRICT mode forces mTLS for peer connections in the targeted namespace. Clients without an Istio sidecar cannot establish mTLS and will be blocked.4) Enable sidecar injection on the test namespace
Label thetest namespace for automatic sidecar injection:
test pod so the injector adds the sidecar:
1/2 (sidecar injecting) to 2/2 (both containers ready):
test pod; the request should succeed because the sidecar negotiates mTLS:
5) Restrict egress with a Sidecar resource (namespace-wide)
By default, Istio sidecars allow egress to all services discovered in the mesh. A Sidecar CRD can restrict which hosts a workload’s sidecar may discover and talk to. Create a Sidecar in thetest namespace that restricts egress to only the local namespace and istio-system:
sidecar_default_namespace.yaml
test pod and attempt to curl productpage in default:
test, limiting allowed hosts to ./* (the same namespace) and istio-system/*. Because default/* is not permitted, the local client-side Envoy proxy blocks the outbound request and returns an empty reply.
To restore access to default services, include default/* in egress.hosts:
sidecar_default_namespace.yaml
6) Narrow the Sidecar scope with workloadSelector
UseworkloadSelector to target a Sidecar only to workloads with specific labels, enabling fine-grained control.
Example Sidecar that only affects workloads labeled run=test:
- Pods matching
run=test(for example thetestpod) will be limited to./*andistio-system/*. Attempts to reachproductpage.default.svcwill return an empty reply. - Pods without
run=testare unaffected and can still reachdefaultservices.
- Launch another pod without the target label:
- From the
nginxpod (norun=test), curl the productpage — it should succeed:
- From the
testpod (labelrun=test), curl the productpage — it will fail:
workloadSelector limits Sidecar effects to specific workloads, enabling multi-tenant or progressive rollout patterns.
7) Sidecar examples and quick references
Use these snippets as a starting point when authoring Sidecar resources.- Restricting egress to production namespaces:
- Advanced Sidecar with ingress, defaultEndpoint, and egress ports:

Commands and expected effects (quick reference)
| Command | Purpose | Expected effect |
|---|---|---|
kubectl get ns --show-labels | Check injection labels | See istio-injection=enabled if automatic injection is active |
kubectl apply -f <bookinfo.yaml> | Deploy Bookinfo | Bookinfo services and deployments start with sidecars in labeled namespaces |
kubectl run test --image=nginx -n test | Create test client pod | Creates a pod to validate connectivity |
kubectl apply -f peer_auth.yaml | Enforce mTLS in a namespace | Non-sidecar clients are blocked (STRICT) |
kubectl label ns test istio-injection=enabled | Enable injection for a namespace | New pods in namespace receive sidecars |
kubectl apply -f sidecar_default_namespace.yaml | Limit egress hosts | Sidecar proxies restrict outbound discovery and traffic |
workloadSelector in Sidecar | Target specific workloads | Only pods matching labels are affected |
Links and references
- Istio Sidecar docs: https://istio.io/latest/docs/reference/config/networking/sidecar/
- Istio PeerAuthentication: https://istio.io/latest/docs/reference/config/security/peer_authentication/
- Kubernetes namespaces: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
That concludes this Sidecar lesson. Next: VirtualServices and more advanced traffic routing.