Implementing Service Mesh

1. Understanding Service Mesh Architecture

PlaneRole
Data planeSidecar proxies handle traffic (Envoy)
Control planeConfigures proxies (Istiod, linkerd-control)
Sidecar patternOne proxy per pod; transparent interception
SidecarlesseBPF-based (Cilium), Istio Ambient mode

2. Using Sidecar Proxies

FunctionDetail
L7 routingHTTP/gRPC aware
mTLS terminationEncrypt all in-cluster traffic
Retries / timeoutsConfigured via CRDs
TelemetryAuto metrics, logs, traces
Cost+CPU/RAM per pod, +latency (~1–2ms)

3. Implementing Traffic Management

CapabilityMechanism
RoutingVirtualService (Istio), HTTPRoute (Gateway API)
Header-basedMatch on header for routing
MirroringSend copy to test version
SubsetsGroup endpoints by labels (version)

4. Using Circuit Breaking

SettingDetail
Max connectionsLimit pool to upstream
Max pending requestsBounded queue
Max retriesCap retry budget
Outlier detectionEject host after N consecutive 5xx

5. Implementing Load Balancing

AlgorithmNotes
ROUND_ROBINDefault
LEAST_REQUESTPower of two choices
RANDOMSimple, low state
RING_HASHSticky by header (sessions)
LOCALITY_WEIGHTEDPrefer same zone

6. Managing mTLS

AspectDetail
IdentitySPIFFE SVID (e.g. spiffe://cluster/ns/svc)
Cert rotationAuto via control plane (24h default)
ModesSTRICT, PERMISSIVE, DISABLE
MigrationStart PERMISSIVE, ratchet to STRICT

7. Implementing Traffic Splitting

Example: Istio canary 90/10

apiVersion: networking.istio.io/v1
kind: VirtualService
metadata: { name: orders }
spec:
  hosts: [orders]
  http:
    - route:
        - destination: { host: orders, subset: v1 }
          weight: 90
        - destination: { host: orders, subset: v2 }
          weight: 10
Use CaseStrategy
CanarySmall % to new version
Blue/GreenSwitch 100% atomically
A/BHeader/cookie-based

8. Using Fault Injection

FaultUse
DelayInject latency to test timeouts
AbortReturn HTTP error to test fallbacks
ScopePer-route, per-header (canary users only)
GoalValidate resilience without chaos to prod

9. Implementing Request Routing

MatchExample
URIprefix, exact, regex
MethodGET, POST, ...
Headerse.g. x-user-tier: premium
Query paramse.g. beta=true
Source labelsFrom specific service

10. Managing Service Policies

PolicyDetail
AuthorizationPolicyWho can call what (RBAC)
PeerAuthenticationmTLS modes per workload
RequestAuthenticationJWT validation
RateLimit (EnvoyFilter)Global/local rate limiting
TelemetrySampling, custom metrics

11. Implementing Observability

SignalTool
MetricsPrometheus (mesh exposes RED auto)
TracesJaeger, Tempo via B3/W3C
LogsAccess logs to stdout → Loki/ELK
TopologyKiali (Istio)

12. Comparing Istio vs Linkerd vs Consul Connect

AspectIstioLinkerdConsul Connect
ProxyEnvoylinkerd2-proxy (Rust)Envoy
FootprintHeavyLightMedium
FeaturesMost extensiveFocused, simpleMulti-runtime (VM+K8s)
Learning curveSteepGentleMedium
mTLSYesYesYes
Best forComplex K8s estatesK8s, simplicity-firstHybrid VM/cloud