Goals
- Verify Istio injection labels on namespaces
- Deploy the Bookinfo sample app
- Observe sidecar injection behavior
- Apply a
PeerAuthentication(mTLS STRICT) to thedefaultnamespace and see the effect - Enable injection on a client namespace to restore connectivity
- Create
Sidecarresources 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:0/2 while they initialize — those indicate the Envoy sidecar is being injected (1 container for your app + 1 for Envoy):
2) Create a non-injected namespace and run a client pod
Create a new namespacetest (by default it will not have the istio-injection=enabled label):
test is not injected:
test namespace (no sidecar will be injected):
productpage service in the default namespace (productpage runs on port 9080):
3) Apply PeerAuthentication (mTLS STRICT) in default namespace
Create aPeerAuthentication resource to enforce strict mTLS for the default namespace:
peer_auth.yaml
test pod, try to curl productpage again:
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:
test pod (or simply delete it and let the controller recreate it) so the sidecar gets injected:
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:
5) Introduce a Sidecar resource to restrict egress
ASidecar 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
test pod and try curling productpage (in default namespace):
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)
6) Restrict only selected workloads via workloadSelector
You can target only specific workloads (pods) in the namespace usingworkloadSelector and labels.
Example: restrict egress for workloads labeled run=test:
sidecar_default_namespace.yaml (workload-scoped)
- Pods in the
testnamespace with labelrun=testwill be limited to./*andistio-system/*— they cannot accessdefault/*. - Other pods in the same namespace (for example, a pod labeled
run=nginx) will not be affected and can still accessdefault/*(unless another Sidecar matches them).
- Create another pod in
testnamednginx(default label will berun=nginx). kubectl execintonginxand curl productpage — it will succeed.kubectl execinto thetestpod (run=test) and curl productpage — it will fail withEmpty reply from server.
workloadSelector allow per-workload egress control.
Sidecar quick reference
Useful commands summary
References and further reading
Helpful resources:
- Istio Sidecar reference: https://istio.io/latest/docs/reference/config/networking/sidecar/
- Istio PeerAuthentication reference: https://istio.io/latest/docs/reference/config/security/peer_authentication/
Wrap-up
- Applying a
PeerAuthenticationwithmtls: STRICTenforces mutual TLS and requires clients to use sidecars for encryption. - Enabling
istio-injection=enabledon a namespace ensures sidecars are injected into pods and allows them to participate in mTLS. Sidecarresources allow fine-grained egress and ingress control at namespace or workload level usingegress,ingress, andworkloadSelector.- Use the Istio docs to copy Sidecar/PeerAuth examples rather than typing them during troubleshooting or exams.