Skip to main content
Welcome to the Sidecars lab — the first hands-on exercise in Traffic Management. This guide preserves the original flow while clarifying steps, commands, and outcomes so you can reproduce and understand how Istio sidecars, PeerAuthentication (mTLS), and Sidecar resources interact.

Goals

  • Verify Istio injection labels on namespaces
  • Deploy the Bookinfo sample app
  • Observe sidecar injection behavior
  • Apply a PeerAuthentication (mTLS STRICT) to the default namespace and see the effect
  • Enable injection on a client namespace to restore connectivity
  • Create Sidecar resources to restrict egress for workloads and observe how workload selectors change behavior

1) Verify namespace labels and deploy Bookinfo

Confirm the default namespace has Istio injection enabled:
Example output:
Apply the Bookinfo sample manifest:
You should see resources being created, e.g.:
Check pods. Initially, some pods may show 0/2 while they initialize — those indicate the Envoy sidecar is being injected (1 container for your app + 1 for Envoy):
Example:

2) Create a non-injected namespace and run a client pod

Create a new namespace test (by default it will not have the istio-injection=enabled label):
Example output showing test is not injected:
Run a simple nginx pod in the test namespace (no sidecar will be injected):
Example:
Exec into the test pod and curl the Bookinfo productpage service in the default namespace (productpage runs on port 9080):
You should get an HTTP 200 response proxied through Envoy, indicating the request reached Bookinfo (Envoy is the server in headers):
Note: Istio by default allows traffic to flow (so you can adopt policies later without breaking initial connectivity).

3) Apply PeerAuthentication (mTLS STRICT) in default namespace

Create a PeerAuthentication resource to enforce strict mTLS for the default namespace: peer_auth.yaml
Apply it:
Then from your non-injected test pod, try to curl productpage again:
You will see a failure like:
This happens because default now requires mTLS. Only traffic routed through an Istio sidecar (Envoy) can satisfy that requirement — and the test pod currently has no sidecar.
Applying a PeerAuthentication with mtls: STRICT enforces mutual TLS for all workloads in the target namespace. Clients without an Envoy sidecar will fail to connect until they are inside an injected namespace or a policy allows plaintext.

4) Enable injection on the test namespace and re-run the client

Label the test namespace to enable automatic sidecar injection:
Example output:
Delete and recreate the test pod (or simply delete it and let the controller recreate it) so the sidecar gets injected:
You should now see 1/2 or 2/2 as the pod becomes injected and ready (1 app container + 1 envoy) — e.g. 1/2 then 2/2. Exec into the test pod and curl again:
Now the request should succeed because the Envoy sidecar on the client pod performs mTLS with the server sidecar. Example response:

5) Introduce a Sidecar resource to restrict egress

A Sidecar resource allows you to restrict egress (outbound) and ingress for sidecars in a namespace or for selected workloads. Create a Sidecar that restricts egress to itself and the istio-system namespace: sidecar_default_namespace.yaml
Apply it:
Now exec into the test pod and try curling productpage (in default namespace):
You may see:
Why? Because the Sidecar resource limited egress to only workloads in the same namespace (./*) and istio-system/*. The default namespace is not allowed, so traffic to default is blocked.

Allow the default namespace in the Sidecar

Update the Sidecar to permit default/* as well: sidecar_default_namespace.yaml (updated)
Apply and retry; the curl should return HTTP 200 again.

6) Restrict only selected workloads via workloadSelector

You can target only specific workloads (pods) in the namespace using workloadSelector and labels. Example: restrict egress for workloads labeled run=test: sidecar_default_namespace.yaml (workload-scoped)
Apply this configuration:
Effect:
  • Pods in the test namespace with label run=test will be limited to ./* and istio-system/* — they cannot access default/*.
  • Other pods in the same namespace (for example, a pod labeled run=nginx) will not be affected and can still access default/* (unless another Sidecar matches them).
Demonstration:
  • Create another pod in test named nginx (default label will be run=nginx).
  • kubectl exec into nginx and curl productpage — it will succeed.
  • kubectl exec into the test pod (run=test) and curl productpage — it will fail with Empty reply from server.
This shows how Sidecars with workloadSelector allow per-workload egress control.

Sidecar quick reference


Useful commands summary


References and further reading


Wrap-up

  • Applying a PeerAuthentication with mtls: STRICT enforces mutual TLS and requires clients to use sidecars for encryption.
  • Enabling istio-injection=enabled on a namespace ensures sidecars are injected into pods and allows them to participate in mTLS.
  • Sidecar resources allow fine-grained egress and ingress control at namespace or workload level using egress, ingress, and workloadSelector.
  • Use the Istio docs to copy Sidecar/PeerAuth examples rather than typing them during troubleshooting or exams.
Next up: VirtualServices and traffic routing.

Watch Video

Practice Lab