Overview and What You Will Learn
A service mesh is an infrastructure layer of proxies that handles service-to-service traffic in a Kubernetes cluster. It adds mutual TLS, traffic shifting, retries, circuit breaking and request metrics without any change to application code, because the proxies sit next to your workloads and the control plane configures them centrally.
By the end of this lab you will be able to:
- Explain the data plane and control plane, and the difference between sidecar and ambient modes
- Enforce mTLS between services and prove it works
- Run a canary release with exact traffic percentages and roll it back safely
- Configure retries, timeouts, connection limits and outlier detection
- Restrict which services can call each other with authorization policies
- Read live service topology and metrics in Kiali
- Choose between Istio and Linkerd for your team
Why This Matters in Production
With 40 microservices, one slow dependency can take down the rest. Suppose the payments service slows down, so the orders service waits on it, runs out of threads and also slows down, and every caller of orders then does the same. This chain is called a cascading failure. Plain Kubernetes gives each pod an IP address and each Service a stable name, but it does not retry, encrypt, measure latency per service or stop calling an unhealthy backend. You could write that logic into every service in every language, or you can put it in the mesh once. Teams that handle sensitive internal traffic, such as a trading platform like Zerodha or a payments platform like Razorpay, also use the mesh to meet requirements for encrypted and authenticated service-to-service calls.
Core Principles
A mesh has a data plane and a control plane. The data plane is the proxies that carry every request, and the control plane (istiod in Istio) watches the cluster, computes configuration and pushes it to the proxies. The control plane never sees your request traffic.
control plane] -.->|Config| B E -.->|Config| C classDef app fill:#326CE5,color:#FFFFFF classDef proxy fill:#F97316,color:#FFFFFF classDef control fill:#8B5CF6,color:#FFFFFF class A,D app class B,C proxy class E control
In the classic sidecar mode, the mesh injects a proxy container into every pod. The proxy shares the pod's network namespace and captures traffic with iptables rules, so the app opens a plain connection and the two sidecars set up the encrypted tunnel between them. Istio uses Envoy as its proxy, and Linkerd uses its own lightweight Rust proxy.
Istio also offers ambient mode, which became generally available in Istio 1.24 (November 2024). It removes per-pod sidecars. A node-level ztunnel handles identity, mTLS and L4 policy, and an optional waypoint proxy handles L7 features such as routing and retries for the services that need them.
| Sidecar mode | Ambient mode (Istio) | |
|---|---|---|
| Proxy location | One proxy per pod | ztunnel per node, optional waypoint per service |
| Enable per namespace | istio-injection=enabled label |
istio.io/dataplane-mode=ambient label |
| Pods restarted to join | Yes | No |
| L7 features | Always available | Need a waypoint proxy |
Istio and Linkerd solve the same core problems with different trade-offs:
| Dimension | Istio | Linkerd |
|---|---|---|
| Scope and complexity | Largest feature set, many CRDs, steeper learning curve | Smaller feature set, simpler mental model |
| Data plane | Envoy sidecars or ambient mode | Rust micro-proxy sidecars |
| Resource use | Higher in sidecar mode, lower in ambient | Generally lighter in published comparisons (measure your own) |
| Traffic splitting | VirtualService and DestinationRule, or Gateway API |
Gateway API HTTPRoute |
| Resilience | Retries, timeouts, outlier detection, connection limits, fault injection | Retries, timeouts and circuit breaking (confirm which distribution includes it) |
| Releases | Open-source releases from the Istio project | Open-source edge releases are free, and stable builds come from Buoyant Enterprise for Linkerd |
Two points about Linkerd deserve care. First, since Linkerd 2.15 (February 2024) the open-source project no longer publishes artifacts tagged stable. The source stays Apache 2.0 and weekly edge releases remain free, while stable builds are distributed through Buoyant Enterprise for Linkerd, which has been free for small organisations and trials (check current terms). Second, its feature set around circuit breaking has changed across versions, so check the documentation for the version you plan to run.
RememberBoth Istio and Linkerd are CNCF graduated projects, so maturity is not the deciding factor. The deciding factors are operational complexity, the features you need (fault injection, advanced routing, multi-cluster) and how you want to receive releases.
Detailed Step-by-Step Practical Lab
How to Install Istio on a Local Kubernetes Cluster
Install the CLI, then install the control plane with the demo profile, which includes gateways and generous telemetry settings suited to learning. For production clusters use the default profile (or ambient) and manage the install with Helm or GitOps rather than interactive commands.
curl -L https://istio.io/downloadIstio | sh -cd istio-*export PATH=$PWD/bin:$PATHistioctl version # Install with the demo profile (learning only)istioctl install --set profile=demo -y # istiod and the gateways should be Runningkubectl get pods -n istio-systemThe networking and security APIs used below (networking.istio.io/v1, security.istio.io/v1) need Istio 1.22 or newer. Run istioctl analyze after every change, because it catches many configuration mistakes before they reach traffic.
How to Enable Sidecar Injection and Deploy Two Versions of a Service
Label a namespace and the mesh injects a sidecar into every new pod created in it. Pods that existed before the label need a restart. The example uses http-echo so each version answers with its own name, which makes traffic splitting easy to see.
kubectl create namespace shopkubectl label namespace shop istio-injection=enabled kubectl apply -n shop -f - << 'EOF'apiVersion: apps/v1kind: Deploymentmetadata: name: orders-v1spec: replicas: 2 selector: matchLabels: app: orders version: v1 template: metadata: labels: app: orders version: v1 spec: containers: - name: orders image: hashicorp/http-echo:1.0 args: ["-text=orders v1"] ports: - containerPort: 5678 resources: requests: cpu: 50m memory: 64Mi limits: memory: 128Mi---apiVersion: apps/v1kind: Deploymentmetadata: name: orders-v2spec: replicas: 2 selector: matchLabels: app: orders version: v2 template: metadata: labels: app: orders version: v2 spec: containers: - name: orders image: hashicorp/http-echo:1.0 args: ["-text=orders v2"] ports: - containerPort: 5678 resources: requests: cpu: 50m memory: 64Mi limits: memory: 128Mi---apiVersion: v1kind: Servicemetadata: name: ordersspec: selector: app: orders ports: - name: http port: 80 targetPort: 5678EOF # A client pod inside the mesh to send test traffickubectl run client -n shop --image=curlimages/curl:8.10.1 --command -- sleep 36000 kubectl get pods -n shopEvery pod should show 2/2 ready containers, which means the application and the sidecar are both running. If you see 1/1, injection did not happen: check the namespace label and restart the deployment with kubectl rollout restart deployment -n shop.
TipName Service ports with a protocol prefix such as
httporgrpc. Istio uses the name to choose HTTP behaviour (metrics, routing, retries), and an unnamed port is treated more conservatively.
How to Run a Canary Release with Traffic Splitting
A canary release sends a small share of real traffic to a new version and promotes it only if error rate and latency stay healthy. In Istio, a DestinationRule defines the subsets (which pods are v1 and v2) and a VirtualService assigns the weights. You need both, and the weights do not depend on pod counts.
kubectl apply -n shop -f - << 'EOF'apiVersion: networking.istio.io/v1kind: DestinationRulemetadata: name: ordersspec: host: orders subsets: - name: v1 labels: version: v1 - name: v2 labels: version: v2---apiVersion: networking.istio.io/v1kind: VirtualServicemetadata: name: ordersspec: hosts: - orders http: - route: - destination: host: orders subset: v1 weight: 90 - destination: host: orders subset: v2 weight: 10EOF # Send 100 requests and count the answerskubectl exec -n shop client -c client -- sh -c 'for i in $(seq 1 100); do curl -s http://orders; done' | sort | uniq -cExpect roughly 90 answers from v1 and 10 from v2. To promote, change the weights to 0 and 100 and apply again. To roll back, set v1 to 100 and v2 to 0.
Common MistakeRolling back by deleting the
VirtualService. Without it, the plain Kubernetes Service spreads traffic across all matching pods, which means roughly half of requests would still hit v2 in this lab. Roll back by setting the weights explicitly.
Header-based routing lets internal testers reach v2 before any real user does:
http: - match: - headers: x-canary: exact: "true" route: - destination: host: orders subset: v2 - route: - destination: host: orders subset: v1How to Enforce and Verify mTLS Between Services
mTLS (mutual TLS) means both sides of a connection prove their identity with certificates, so traffic between services is encrypted and each caller is authenticated. The mesh issues workload certificates automatically and rotates them (Istio's default lifetime is 24 hours). In sidecar mode and ambient mode, mTLS between mesh workloads is on by default in permissive form, and STRICT mode rejects any plain-text traffic.
kubectl apply -n shop -f - << 'EOF'apiVersion: security.istio.io/v1kind: PeerAuthenticationmetadata: name: defaultspec: mtls: mode: STRICTEOFProve it from both sides. A client outside the mesh must now be refused, and a client inside the mesh must still work:
# Outside the mesh: a namespace without injection (this call should fail)kubectl create namespace legacykubectl run plain -n legacy --image=curlimages/curl:8.10.1 --restart=Never --rm -it -- \ curl -sv --max-time 5 http://orders.shop.svc.cluster.local # Inside the mesh: still works, and the metric shows the connection was mutual TLSkubectl exec -n shop client -c client -- curl -s http://orders POD=$(kubectl get pod -n shop -l app=orders -o jsonpath='{.items[0].metadata.name}')kubectl exec -n shop "$POD" -c istio-proxy -- \ curl -s localhost:15020/stats/prometheus | grep 'istio_requests_total' | grep mutual_tls | head -3Look for the label connection_security_policy="mutual_tls" on istio_requests_total. In Kiali, encrypted edges on the service graph show a lock icon.
SecuritySwitching to
STRICTon an existing cluster breaks any workload that has no sidecar yet. Start inPERMISSIVEmode, roll out injection namespace by namespace, confirm the metrics show mutual TLS everywhere, and only then switch toSTRICT.
How to Restrict Which Services Can Call Each Other
mTLS proves who is calling, and an authorization policy decides what that caller may do. As soon as one ALLOW policy applies to a workload, any request that does not match an allow rule is denied, so a single policy turns the workload into a closed door with an explicit guest list.
apiVersion: security.istio.io/v1kind: AuthorizationPolicymetadata: name: orders-allow-checkout namespace: shopspec: selector: matchLabels: app: orders action: ALLOW rules: - from: - source: principals: ["cluster.local/ns/shop/sa/checkout"] to: - operation: methods: ["GET", "POST"]The principal is the caller's service account identity, so give each service its own Kubernetes service account and never share one account between services. Roll these policies out namespace by namespace and test them, because a missing rule produces 403 or connection errors.
How to Configure Retries, Timeouts and Circuit Breaking
Resilience settings stop one slow or failing backend from taking down its callers. Retries and timeouts live in the VirtualService. Connection limits and outlier detection (which ejects failing endpoints from the load-balancing pool) live in the DestinationRule. A host can have only one DestinationRule, so add trafficPolicy to the existing orders rule rather than creating a second one.
kubectl apply -n shop -f - << 'EOF'apiVersion: networking.istio.io/v1kind: DestinationRulemetadata: name: ordersspec: host: orders trafficPolicy: connectionPool: tcp: maxConnections: 100 http: http1MaxPendingRequests: 50 http2MaxRequests: 200 maxRequestsPerConnection: 10 outlierDetection: consecutive5xxErrors: 5 interval: 10s baseEjectionTime: 30s maxEjectionPercent: 50 subsets: - name: v1 labels: version: v1 - name: v2 labels: version: v2---apiVersion: networking.istio.io/v1kind: VirtualServicemetadata: name: ordersspec: hosts: - orders http: - timeout: 5s retries: attempts: 2 perTryTimeout: 2s retryOn: 5xx,connect-failure route: - destination: host: orders subset: v1 weight: 100EOFWhat each part does:
connectionPoollimits queued and concurrent requests, so a slow backend gets overflow rejections (HTTP 503) instead of unlimited queueingoutlierDetectionejects an endpoint after 5 consecutive 5xx responses and returns it to the pool after the ejection time, with a cap on how many endpoints may be ejected at oncetimeoutandretriesbound how long a caller waits and how many times a failed request is retried
Two behaviours surprise people. First, outlier detection is tracked by each calling proxy separately, so each caller's sidecar decides for itself which endpoints to eject. It is not a single circuit state shared by the whole mesh and it is not the same as application-level breakers such as Resilience4j. Second, retries multiply load. Retry only idempotent operations, keep attempts low and always pair retries with timeouts, or a struggling backend gets even more traffic.
Common MistakeSetting
maxEjectionPercentto 100. If every endpoint is ejected, callers have nowhere to send traffic. Keep it at 50 or lower so part of the pool always stays in rotation.
How to Observe Traffic with Kiali and Prometheus Metrics
Every request passes through a proxy, so the mesh produces latency, error rate and volume metrics for every service pair with no instrumentation in your code. Kiali draws these as a live service graph, and Prometheus stores the underlying metrics.
# From the istio-* directory: install the sample observability addonskubectl apply -f samples/addons/prometheus.yamlkubectl apply -f samples/addons/kiali.yaml # Generate steady traffic in the background, then open the dashboardkubectl exec -n shop client -c client -- sh -c 'while true; do curl -s http://orders > /dev/null; sleep 0.2; done' &istioctl dashboard kialiIn Kiali, open the Graph view for the shop namespace to see which services call which, the share of traffic on v1 and v2, error rates, and lock icons for mTLS. The addons are for evaluation. In production, run your own Prometheus and Grafana and follow the Istio documentation for scraping.
| Metric | What it measures |
|---|---|
istio_requests_total |
Request count by source, destination, response code and security policy |
istio_request_duration_milliseconds |
Latency histogram per service pair |
istio_tcp_connections_opened_total |
TCP connection rate for non-HTTP traffic |
How to Try Istio Ambient Mode
Ambient mode gives you mTLS and L4 policy without injecting sidecars. Install the ambient profile on a clean cluster and label a namespace. Pods keep running without restarts, and ztunnel picks up their traffic.
istioctl install --set profile=ambient -y kubectl create namespace ambient-labkubectl label namespace ambient-lab istio.io/dataplane-mode=ambient # One ztunnel pod per nodekubectl get pods -n istio-system -l app=ztunnelistioctl ztunnel-config workloadsL7 features such as header routing and retries need a waypoint proxy for the namespace or service, which uses the Kubernetes Gateway API. Do not label the same namespace for both sidecar injection and ambient mode.
How to Get Started with Linkerd
Linkerd installs with a CLI that checks the cluster, installs its CRDs and control plane, and then injects its proxy into annotated namespaces. Follow the current getting-started guide for the release you choose, since the open-source path uses edge releases.
linkerd check --prelinkerd install --crds | kubectl apply -f -linkerd install | kubectl apply -f -linkerd check # Opt a namespace in, then restart workloads to inject the proxykubectl annotate namespace shop linkerd.io/inject=enabledkubectl rollout restart deployment -n shopLinkerd enables mTLS automatically between meshed pods. It splits traffic with Gateway API HTTPRoute resources that give weighted backends, which means each version needs its own Service. Check the documentation for your version for the exact API group and fields.
How to Clean Up the Lab
kubectl delete namespace shop legacy ambient-labistioctl uninstall --purge -ykubectl delete namespace istio-systemProduction Best Practices & Common Pitfalls
- Adopt in stages. Start with observability and
PERMISSIVEmTLS, then move toSTRICTand authorization policies. - Set sidecar resources. A sidecar's memory and CPU use depends on mesh size and traffic, so set requests and limits, and measure real usage before sizing the cluster. In Istio you can set them globally or per pod with annotations such as
sidecar.istio.io/proxyCPU. - Delay the app until the proxy is ready. If your app calls out at startup, set
holdApplicationUntilProxyStartsin the proxy config for that pod, or the first requests can fail. - Keep system namespaces out of the mesh. Do not inject
kube-systemoristio-system. - Restart after labelling. Existing pods only get sidecars when they are recreated.
- Validate every change. Run
istioctl analyzeand checkistioctl proxy-statusto confirm proxies are in sync. - Version carefully. Check which Kubernetes versions your Istio or Linkerd release supports before you upgrade either one.
| Mistake | Problem | Fix |
|---|---|---|
STRICT mTLS on day one |
Workloads without sidecars cannot connect | Start in PERMISSIVE, then switch |
Subset in a VirtualService with no DestinationRule |
503 errors for that route | Define the subsets, run istioctl analyze |
Two DestinationRule resources for one host |
Settings conflict or are ignored | One rule per host, with all policies in it |
Rolling back by deleting the VirtualService |
Traffic falls back to even pod-level balancing | Set explicit 100 and 0 weights |
| Shared service account across services | Authorization cannot tell callers apart | One service account per workload |
| Unbounded retries | Retry storms against a struggling backend | Low attempts, per-try timeouts |
Quick Reference & Troubleshooting Commands
| Resource or command | What it does |
|---|---|
PeerAuthentication |
Sets mTLS mode (STRICT or PERMISSIVE) per namespace or workload |
VirtualService |
Routing rules: weights, header matches, retries, timeouts |
DestinationRule |
Subsets, load balancing, connection pool and outlier detection |
AuthorizationPolicy |
Which identities may call which workloads |
istioctl analyze -n shop |
Checks configuration for errors |
istioctl proxy-status |
Shows whether each proxy is in sync with the control plane |
istioctl proxy-config routes POD -n shop |
Shows the routes a proxy actually received |
istioctl dashboard kiali |
Opens the Kiali service graph |
| Symptom | First check | What to look for |
|---|---|---|
Pod shows 1/1 instead of 2/2 |
Namespace label and pod age | Label missing, or pod created before the label |
| 503 after applying a route | istioctl analyze |
Missing subset, host name mismatch |
Calls fail after STRICT |
Client namespace | Caller has no sidecar, or is outside the mesh |
| 403 from a service | AuthorizationPolicy list |
Caller identity not in an allow rule |
| Config not taking effect | istioctl proxy-status |
Proxy shown as stale or not synced |
Interview Questions This Topic Maps To
- How does a service mesh provide mTLS without application code changes, and what happens on the network when one service calls another?
- How would you canary 5% of traffic to a new payments version with an instant rollback path, and why is deleting the routing resource a poor rollback?
- Compare Istio's outlier detection with an application-level circuit breaker. Where can it fail to protect a caller?
- What would you check before turning on
STRICTmTLS in a cluster with 200 pods, and what is the risk of skipping that check? - When would you choose Istio ambient mode over sidecars, and what do you lose without a waypoint proxy?