writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
kubernetes-istioImplements Istio service mesh patterns (sidecar injection, traffic splitting, circuit breaking, retries, and mTLS) for advanced traffic management and zero-downtime deployments in Kubernetes.
Independent GitHub snapshot · Automated classification · Original documentation governs
Implements Istio service mesh patterns for advanced traffic management, security, and observability in Kubernetes clusters. When loaded, the model generates Istio CRDs (VirtualService, DestinationRule, ServiceEntry, PeerAuthentication, AuthorizationPolicy) for traffic splitting, circuit breaking, retries, and mutual TLS enforcement.
sidecar.istio.io/inject: "true" annotation or namespace-level defaultDestinationRule alongside every VirtualService for traffic policiestrafficPolicy.tls.mode: ISTIO_MUTUAL for mTLS — never plaintext in productionmaxConnections, httpMaxPendingRequests, consecutive5xxErrors) in DestinationRulesistioctl analyze before deploying traffic rulesUse this skill when:
Avoid this skill for:
kubernetes-ingress insteadkubernetes-networkpolicy for L3/L4 ruleskubernetes-statefulset for that concernVerify Istio Control Plane — Confirm Istiod is running and sidecar injection is enabled in the target namespace. Checkpoint: Run kubectl get pods -n istio-system and verify istiod is Running. Run kubectl get namespace -L istio-injection to verify injection labels.
Define DestinationRule — Create a DestinationRule that sets the subset labels, connection pool limits, and TLS mode for the target service. Checkpoint: The trafficPolicy.tls.mode must be ISTIO_MUTUAL for mTLS or DISABLE for unencrypted — never use SIMPLE (deprecated in Istio 1.7+).
Define VirtualService — Create a VirtualService that routes traffic to subsets defined in the DestinationRule, using weight-based splitting, header matching, or fault injection. Checkpoint: Every route destination must reference a valid subset name defined in a corresponding DestinationRule.
Apply PeerAuthentication — Configure namespace-wide or global mTLS policy (STRICT for production, PERMISSIVE for transition periods). Checkpoint: STRICT mode rejects all non-mTLS traffic; verify no services are broken by the policy before applying cluster-wide.
Apply and Validate — Apply all manifests and run istioctl analyze to detect misconfigurations. Checkpoint: Confirm istioctl analyze reports zero warnings and that istioctl proxy-config shows the expected routes.
Verify Traffic Splitting — Send test requests to the ingress point and confirm the expected distribution across subsets. Checkpoint: Use curl or a load generator to send enough requests to verify the weight split matches the VirtualService configuration.
A VirtualService and DestinationRule for routing 10% of traffic to a canary subset and 90% to stable.
# DestinationRule: defines subsets for stable and canary versions
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: frontend-destination
namespace: production
spec:
host: frontend.production.svc.cluster.local
subsets:
- name: stable
labels:
version: v1
- name: canary
labels:
version: v2
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100
http:
h2UpgradePolicy: DEFAULT
http1MaxPendingRequests: 100
http2MaxRequests: 1000
outlierDetection:
consecutive5xxErrors: 5
interval: 30s
baseEjectionTime: 60s
maxEjectionPercent: 50
---
# VirtualService: splits traffic 90/10 between stable and canary
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: frontend-routing
namespace: production
spec:
hosts:
- frontend.production.svc.cluster.local
http:
- route:
- destination:
host: frontend.production.svc.cluster.local
subset: stable
weight: 90
- destination:
host: frontend.production.svc.cluster.local
subset: canary
weight: 10
Improper circuit breaker and retry settings can either mask failures or cause excessive backpressure.
# ❌ BAD — No circuit breaker; cascading failures will propagate unbounded
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: backend-dr-bad
namespace: production
spec:
host: backend.production.svc.cluster.local
subsets:
- name: default
labels:
app: backend
# No trafficPolicy at all — no connection limits, no outlier detection
# ❌ No retries configured in VirtualService — transient failures are fatal
# ✅ GOOD — Circuit breaker prevents cascade, retries handle transient failures
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: backend-dr-good
namespace: production
spec:
host: backend.production.svc.cluster.local
subsets:
- name: default
labels:
app: backend
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100 # Hard cap on connections to the upstream
http:
http1MaxPendingRequests: 100 # Buffer for queued HTTP requests
http2MaxRequests: 1000
outlierDetection:
consecutive5xxErrors: 3 # Eject after 3 consecutive 5xx responses
interval: 10s # Check every 10 seconds
baseEjectionTime: 30s # Eject for 30 seconds
maxEjectionPercent: 50 # Eject at most half the hosts
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: backend-routing
namespace: production
spec:
hosts:
- backend.production.svc.cluster.local
http:
- route:
- destination:
host: backend.production.svc.cluster.local
subset: default
retries:
attempts: 3 # Retry up to 3 times
perTryTimeout: 2s # Each retry attempt has a 2s timeout
retryOn: gateway-error,connect-failure,refused-stream
# PeerAuthentication: enforce mTLS namespace-wide
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: production-mtls
namespace: production
spec:
mtls:
mode: STRICT # Reject all plaintext traffic
---
# AuthorizationPolicy: allow frontend to call backend on /api/* only
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: backend-authz
namespace: production
spec:
selector:
matchLabels:
app: backend
action: ALLOW
rules:
- from:
- source:
principals: ["cluster.local/ns/production/sa/frontend"]
to:
- operation:
paths: ["/api/*"]
methods: ["GET", "POST"]
---
# ServiceEntry: allow outbound traffic to external payment API
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
name: external-payment-api
namespace: production
spec:
hosts:
- api.payment-provider.com
ports:
- number: 443
name: https
protocol: HTTPS
resolution: DNS
location: MESH_EXTERNAL
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ab-test-routing
namespace: production
spec:
hosts:
- checkout.production.svc.cluster.local
http:
- match:
- headers:
x-ab-group:
exact: group-b
route:
- destination:
host: checkout.production.svc.cluster.local
subset: group-b
weight: 100
- route:
- destination:
host: checkout.production.svc.cluster.local
subset: group-a
weight: 100
DestinationRule for every service that will receive routed traffic — VirtualService subsets must be defined in a corresponding DestinationRuletrafficPolicy.tls.mode: ISTIO_MUTUAL in DestinationRules for mTLS between mesh servicesoutlierDetection with consecutive5xxErrors (3–5) and baseEjectionTime (30–60s) in DestinationRules for circuit breakingretries.attempts to 1–3 and retries.perTryTimeout to 1–5s in VirtualService for retry policiesPeerAuthentication with mode: STRICT in production namespaces to enforce mTLSversion or release labels so subsets can match them accuratelyistioctl analyze -A after applying any Istio CRD to catch configuration errorsconnectionPool.tcp.maxConnections and connectionPool.http.http1MaxPendingRequests to cap backpressurePeerAuthentication mode to STRICT without verifying all services can use mTLS first — it will cut off plaintext communication instantlyoutlierDetection from production DestinationRules — services without circuit breaking will cascade failuresretries.attempts higher than 3 — excessive retries amplify load spikes during incidentsretries.retryOn: 5xx as the only retry condition — 503 from circuit breakers should not trigger more retriesmode: DISABLE on PeerAuthentication in production — it allows unencrypted communication between serviceskube-system or istio-system namespaces without explicit justificationWhen implementing an Istio service mesh configuration, produce the following:
| Skill | Purpose |
|---|---|
kubernetes-ingress | Route external HTTP/HTTPS traffic into the mesh at the ingress gateway |
kubernetes-deployment | Deploy stateless workloads with version labels that Istio subsets can target |
kubernetes-statefulset | Deploy stateful workloads — Istio can still manage traffic for StatefulSet pods |
kubernetes-networkpolicy | Apply L3/L4 network policies as a defense-in-depth layer alongside Istio |
kubernetes-services-management | Create the Kubernetes Services that Istio routes traffic to |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.