Step 33 of 51
Sidecar proxy, mTLS, traffic management, observability without code changes. When service mesh is worth the complexity.
Service Mesh — Istio/Linkerd เพิ่มความสามารถโดยไม่แก้ code
Microservices need mTLS, retries, circuit breaking, observability, and traffic management. Implementing these in every service means duplicated code and inconsistent behavior. A service mesh moves these concerns to an infrastructure layer.
Diagram: Service A communicates with Service B through sidecar proxies that handle mTLS, retries, and metrics transparently.
Loading diagram...
Each service instance gets a sidecar proxy (Envoy). All network traffic goes through the proxy. The mesh control plane (Istio/Linkerd) configures the proxies.
| Use Service Mesh | Skip It |
|---|---|
| 20+ microservices | < 10 services |
| Cross-cutting security (mTLS) requirements | Simple security needs |
| Complex traffic routing (canary, blue-green) | Basic deployments |
| Polyglot services (Java, Go, Python) | Single language |
| Service-to-service observability required | Application-level observability |
Deploy two versions of your service and split traffic 90/10 for canary testing:
# destination-rule.yaml
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: product-service
spec:
host: product-service
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
# virtual-service.yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: product-service
spec:
hosts:
- product-service
http:
- route:
- destination:
host: product-service
subset: v1
weight: 90
- destination:
host: product-service
subset: v2
weight: 10
retries:
attempts: 3
perTryTimeout: 2s
timeout: 10s
90% of traffic goes to v1, 10% to v2. No code changes. No redeployment. Adjust weights and apply.
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: order-service
spec:
host: order-service
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100
http:
h2UpgradePolicy: DEFAULT
http1MaxPendingRequests: 100
http2MaxRequests: 100
outlierDetection:
consecutive5xxErrors: 5
interval: 30s
baseEjectionTime: 30s
maxEjectionPercent: 50
If an instance returns 5 consecutive 5xx errors within 30 seconds, it is ejected from the load balancer for 30 seconds.
A service mesh handles infrastructure concerns. Your application still needs:
When Istio is installed, every service automatically gets:
No code changes. No Micrometer configuration. The sidecar proxy captures all traffic metrics.