Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy and manage Kubernetes workloads: manifests, RBAC, Helm charts, service mesh, GitOps, and troubleshooting.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/service-mesh.md
1# Service Mesh23---45## Istio Installation67```bash8# Install Istio CLI9curl -L https://istio.io/downloadIstio | sh -10export PATH=$PWD/istio-*/bin:$PATH1112# Install Istio with default profile13istioctl install --set profile=default -y1415# Enable sidecar injection for namespace16kubectl label namespace production istio-injection=enabled1718# Verify installation19istioctl verify-install20kubectl get pods -n istio-system21```2223## Istio Profiles2425```bash26# Minimal - only control plane27istioctl install --set profile=minimal2829# Default - control plane + ingress gateway30istioctl install --set profile=default3132# Demo - includes egress gateway, extra features33istioctl install --set profile=demo3435# Production - tuned for production36istioctl install --set profile=default \37--set values.global.proxy.resources.requests.cpu=100m \38--set values.global.proxy.resources.requests.memory=128Mi \39--set values.global.proxy.resources.limits.cpu=500m \40--set values.global.proxy.resources.limits.memory=256Mi41```4243## VirtualService4445```yaml46apiVersion: networking.istio.io/v1beta147kind: VirtualService48metadata:49name: myapp50namespace: production51spec:52hosts:53- myapp54- myapp.example.com55gateways:56- mesh # Internal mesh traffic57- myapp-gateway # External gateway58http:59# Route based on headers60- match:61- headers:62x-version:63exact: "v2"64route:65- destination:66host: myapp67subset: v26869# Canary release (90/10 split)70- match:71- uri:72prefix: /api73route:74- destination:75host: myapp76subset: v177weight: 9078- destination:79host: myapp80subset: v281weight: 108283# Default route84- route:85- destination:86host: myapp87subset: v188timeout: 30s89retries:90attempts: 391perTryTimeout: 10s92retryOn: connect-failure,refused-stream,50393```9495## DestinationRule9697```yaml98apiVersion: networking.istio.io/v1beta199kind: DestinationRule100metadata:101name: myapp102namespace: production103spec:104host: myapp105trafficPolicy:106connectionPool:107tcp:108maxConnections: 100109connectTimeout: 5s110http:111h2UpgradePolicy: UPGRADE112http1MaxPendingRequests: 100113http2MaxRequests: 1000114maxRequestsPerConnection: 100115loadBalancer:116simple: LEAST_REQUEST117outlierDetection:118consecutive5xxErrors: 5119interval: 10s120baseEjectionTime: 30s121maxEjectionPercent: 50122subsets:123- name: v1124labels:125version: v1126trafficPolicy:127loadBalancer:128simple: ROUND_ROBIN129- name: v2130labels:131version: v2132```133134## Gateway135136```yaml137apiVersion: networking.istio.io/v1beta1138kind: Gateway139metadata:140name: myapp-gateway141namespace: production142spec:143selector:144istio: ingressgateway145servers:146- port:147number: 80148name: http149protocol: HTTP150hosts:151- myapp.example.com152tls:153httpsRedirect: true154- port:155number: 443156name: https157protocol: HTTPS158hosts:159- myapp.example.com160tls:161mode: SIMPLE162credentialName: myapp-tls-secret163```164165## Traffic Mirroring (Shadow Traffic)166167```yaml168apiVersion: networking.istio.io/v1beta1169kind: VirtualService170metadata:171name: myapp-mirror172namespace: production173spec:174hosts:175- myapp176http:177- route:178- destination:179host: myapp180subset: v1181mirror:182host: myapp183subset: v2184mirrorPercentage:185value: 100.0186```187188## mTLS Configuration189190```yaml191# Strict mTLS for namespace192apiVersion: security.istio.io/v1beta1193kind: PeerAuthentication194metadata:195name: default196namespace: production197spec:198mtls:199mode: STRICT200---201# Per-workload mTLS202apiVersion: security.istio.io/v1beta1203kind: PeerAuthentication204metadata:205name: legacy-service206namespace: production207spec:208selector:209matchLabels:210app: legacy-service211mtls:212mode: PERMISSIVE # Allow both mTLS and plaintext213---214# Mesh-wide mTLS policy215apiVersion: security.istio.io/v1beta1216kind: PeerAuthentication217metadata:218name: default219namespace: istio-system220spec:221mtls:222mode: STRICT223```224225## Authorization Policy226227```yaml228apiVersion: security.istio.io/v1beta1229kind: AuthorizationPolicy230metadata:231name: myapp-authz232namespace: production233spec:234selector:235matchLabels:236app: myapp237action: ALLOW238rules:239# Allow from specific service accounts240- from:241- source:242principals:243- "cluster.local/ns/production/sa/frontend"244- "cluster.local/ns/production/sa/api-gateway"245to:246- operation:247methods: ["GET", "POST"]248paths: ["/api/*"]249250# Allow health checks from anywhere251- to:252- operation:253methods: ["GET"]254paths: ["/health", "/ready"]255256# Deny all other traffic (implicit deny when rules exist)257```258259## Circuit Breaker260261```yaml262apiVersion: networking.istio.io/v1beta1263kind: DestinationRule264metadata:265name: myapp-circuit-breaker266namespace: production267spec:268host: myapp269trafficPolicy:270connectionPool:271tcp:272maxConnections: 50273http:274http1MaxPendingRequests: 100275http2MaxRequests: 100276maxRequestsPerConnection: 10277outlierDetection:278consecutive5xxErrors: 3279interval: 10s280baseEjectionTime: 30s281maxEjectionPercent: 100282minHealthPercent: 0283```284285## Fault Injection (Testing)286287```yaml288apiVersion: networking.istio.io/v1beta1289kind: VirtualService290metadata:291name: myapp-fault292namespace: production293spec:294hosts:295- myapp296http:297- match:298- headers:299x-test-fault:300exact: "inject"301fault:302delay:303percentage:304value: 50305fixedDelay: 5s306abort:307percentage:308value: 10309httpStatus: 503310route:311- destination:312host: myapp313- route:314- destination:315host: myapp316```317318## Linkerd Installation319320```bash321# Install Linkerd CLI322curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh323export PATH=$HOME/.linkerd2/bin:$PATH324325# Validate cluster326linkerd check --pre327328# Install CRDs329linkerd install --crds | kubectl apply -f -330331# Install control plane332linkerd install | kubectl apply -f -333334# Check installation335linkerd check336337# Enable injection for namespace338kubectl annotate namespace production linkerd.io/inject=enabled339340# Inject existing deployments341kubectl get deploy -n production -o yaml | linkerd inject - | kubectl apply -f -342```343344## Linkerd Service Profile345346```yaml347apiVersion: linkerd.io/v1alpha2348kind: ServiceProfile349metadata:350name: myapp.production.svc.cluster.local351namespace: production352spec:353routes:354- name: GET /api/users355condition:356method: GET357pathRegex: /api/users358responseClasses:359- condition:360status:361min: 500362max: 599363isFailure: true364timeout: 5s365366- name: POST /api/orders367condition:368method: POST369pathRegex: /api/orders370isRetryable: true371timeout: 10s372373retryBudget:374retryRatio: 0.2375minRetriesPerSecond: 10376ttl: 10s377```378379## Linkerd Traffic Split (Canary)380381```yaml382apiVersion: split.smi-spec.io/v1alpha1383kind: TrafficSplit384metadata:385name: myapp-canary386namespace: production387spec:388service: myapp389backends:390- service: myapp-v1391weight: 900m # 90%392- service: myapp-v2393weight: 100m # 10%394```395396## Multi-Cluster Mesh (Istio)397398```yaml399# Primary cluster - create remote secret400istioctl x create-remote-secret \401--context=cluster1 \402--name=cluster1 | kubectl apply -f - --context=cluster2403404# Enable endpoint discovery405apiVersion: install.istio.io/v1alpha1406kind: IstioOperator407spec:408values:409global:410meshID: mesh1411multiCluster:412clusterName: cluster1413network: network1414```415416## Kiali Dashboard417418```bash419# Install Kiali420kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/addons/kiali.yaml421422# Access dashboard423istioctl dashboard kiali424```425426## Jaeger Tracing427428```bash429# Install Jaeger430kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/addons/jaeger.yaml431432# Access dashboard433istioctl dashboard jaeger434```435436## Service Mesh Comparison437438| Feature | Istio | Linkerd |439|---------|-------|---------|440| Sidecar | Envoy | linkerd2-proxy (Rust) |441| Resource usage | Higher | Lower |442| Features | More extensive | Focused/simpler |443| mTLS | Built-in | Built-in |444| Traffic management | Advanced | Basic (SMI) |445| Multi-cluster | Native support | Requires setup |446| Learning curve | Steeper | Gentler |447448## Best Practices4494501. **Start with permissive mTLS**, migrate to strict gradually4512. **Use circuit breakers** to prevent cascade failures4523. **Set reasonable timeouts** and retry budgets4534. **Enable distributed tracing** for observability4545. **Test with fault injection** before production4556. **Monitor sidecar resource usage** and tune accordingly4567. **Use traffic mirroring** to validate new versions safely4578. **Implement authorization policies** for zero-trust4589. **Keep service mesh version updated** for security patches45910. **Document traffic routing decisions** in VirtualServices460