๐Ÿ”ง DevOps

Service Mesh

Service Mesh

Manages communication between microservices. Istio, Linkerd. Sidecar pattern.

Detailed Explanation

Service Mesh is an infrastructure layer that manages network communication between microservices. It provides traffic management, security, and observability between services without modifying application code, resolving the complexity of the microservice architecture.

A Service Mesh mainly uses the sidecar pattern to place a proxy (e.g., Envoy) alongside each service Pod. This proxy intercepts all inbound/outbound traffic and handles routing, load balancing, mTLS encryption, circuit breakers, retry logic, and more. Representative implementations include Istio, Linkerd, and Consul Connect, each with strengths in functionality, simplicity, and multi-cloud support.

Code Example

Istio VirtualService - traffic routing

# virtualservice.yaml - ์นด๋‚˜๋ฆฌ ๋ฐฐํฌ ํŠธ๋ž˜ํ”ฝ ๋ถ„ํ• 
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: product-service
  namespace: production
spec:
  hosts:
  - product-service
  http:
  - match:
    - headers:
        x-canary:
          exact: "true"
    route:
    - destination:
        host: product-service
        subset: v2
  - route:
    - destination:
        host: product-service
        subset: v1
      weight: 90
    - destination:
        host: product-service
        subset: v2
      weight: 10
    retries:
      attempts: 3
      perTryTimeout: 2s
    timeout: 10s
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: product-service
  namespace: production
spec:
  host: product-service
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 100
      http:
        h2UpgradePolicy: UPGRADE
        http1MaxPendingRequests: 100
    outlierDetection:
      consecutive5xxErrors: 5
      interval: 30s
      baseEjectionTime: 30s
      maxEjectionPercent: 50
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

Istio mTLS configuration

# peer-authentication.yaml - ์„œ๋น„์Šค ๊ฐ„ mTLS ๊ฐ•์ œ
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: default
  namespace: production
spec:
  mtls:
    mode: STRICT
---
# authorization-policy.yaml - ์„ธ๋ฐ€ํ•œ ์ ‘๊ทผ ์ œ์–ด
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: product-service-policy
  namespace: production
spec:
  selector:
    matchLabels:
      app: product-service
  action: ALLOW
  rules:
  - from:
    - source:
        principals:
        - "cluster.local/ns/production/sa/order-service"
        - "cluster.local/ns/production/sa/cart-service"
    to:
    - operation:
        methods: ["GET", "POST"]
        paths: ["/api/products/*"]

Practical Conversation

Security team

"Communication between microservices is not encrypted, and we got flagged in the security audit. Do we have to switch everything to HTTPS?"

Platform engineer

"If you adopt an Istio Service Mesh, all communication between services is automatically encrypted with mTLS. Without modifying application code."

Dev team lead

"Doesn't adding a sidecar proxy create performance overhead?"

Platform engineer

"The Envoy proxy adds about 1-3ms of latency, and needs about 50MB more memory per Pod. But it's actually more efficient if it replaces the retry and circuit breaker logic you'd otherwise have to implement between services yourself."

SRE

"Is distributed tracing automatic too?"

Platform engineer

"Yes, Istio propagates trace headers automatically, so if you integrate with Jaeger or Zipkin you can see the entire call flow. You can also visualize the service topology with the Kiali dashboard."

Cautions

  • Increased complexity: A Service Mesh is powerful but complex. For small teams or simple architectures, it can be over-engineering.
  • Resource overhead: Since a sidecar is added to each Pod, cluster resource usage increases. Plan for about 100m CPU and 128MB memory per Pod.
  • Debugging complexity: When problems occur, you have to check the application, the sidecar, and the control plane. Sufficient observability tools are needed.
  • Version compatibility: Check compatibility between Istio and Kubernetes versions. Care is needed when upgrading.
  • Gradual adoption: Don't enable all features from the start; begin with mTLS and add features gradually.

Learn More