domains / devops / ai-inference-service-mesh / ai-inference-service-mesh
The sickn33 copy is a mirror of the BagelHole copy (it explicitly cites BagelHole as the source) but it adds material safety constraints and corrections that the original lacks. The original presents the egress policy as a complete firewall and includes a DestinationRule that originates TLS for an external HTTPS host, which the mirror explicitly warns against (double TLS breaks the connection). The mirror also adds a prerequisite to confirm cluster context, mesh version, and CRD schemas, and warns that multiple DestinationRules for the same host must be consolidated. Because the mirror corrects a real operational hazard in the original, crowning the original would hide a safer alternative, so the copies should be combined.
| Repository | Path |
|---|---|
| BagelHole/DevOps-Security-Agent-Skills | infrastructure/networking/ai-inference-service-mesh/SKILL.md |
| sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills-claude/skills/ai-inference-service-mesh/SKILL.md |
| Role | Repository | Path |
|---|---|---|
| peer | BagelHole/DevOps-Security-Agent-Skills | infrastructure/networking/ai-inference-service-mesh/SKILL.md |
| peer | sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills-claude/skills/ai-inference-service-mesh/SKILL.md |
| adapter | sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills/skills/ai-inference-service-mesh/SKILL.md |
| adapter | sickn33/agentic-awesome-skills | skills/ai-inference-service-mesh/SKILL.md |
---
name: ai-inference-service-mesh
description: Use verified service mesh patterns for AI inference traffic management, mTLS, canary releases, policy enforcement, and cross-cluster resilience.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# AI Inference Service Mesh
Apply Istio/Linkerd mesh controls to secure and optimize east-west AI traffic across inference microservices.
## Why Mesh for AI
- Enforce mTLS between gateway, retriever, reranker, and model services
- Apply fine-grained traffic policies without app code changes
- Run progressive delivery for model-serving backends
- Observe latency hops for retrieval + generation chains
- Route inference requests by model version, tenant, or priority tier
- Protect expensive GPU-backed services from cascading failures
## Prerequisites
Confirm the exact cluster/context, mesh version, CRD schemas, owned namespace, and authorized mutation scope before applying any changes. Examples below are alternative fragments, not a manifest to apply wholesale: multiple DestinationRules for the same host must be consolidated under the installed version's merge rules. Preview and validate in a disposable environment; protect production routes and retain rollback evidence.
```bash
# Illustrative mutating install; default is not a validated production configuration
istioctl install --set profile=default \
--set meshConfig.accessLogFile=/dev/stdout \
--set meshConfig.defaultConfig.holdApplicationUntilProxyStarts=true
# Label inference namespace for sidecar injection
kubectl create namespace ai-inference
kubectl label namespace ai-inference istio-injection=enabled
# Verify installation
istioctl verify-install
istioctl analyze -n ai-inference
```
## Core Patterns
### mTLS Strict Mode Cluster-Wide
```yaml
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system
spec:
mtls:
mode: STRICT
---
# Namespace-level override if needed for gradual rollout
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: ai-inference-mtls
namespace: ai-inference
spec:
mtls:
mode: STRICT
portLevelMtls:
# gRPC inference port
8081:
mode: STRICT
# Prometheus metrics port - allow plaintext scraping
9090:
mode: PERMISSIVE
```
### AuthorizationPolicy Per Service Account
```yaml
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: model-server-access
namespace: ai-inference
spec:
selector:
matchLabels:
app: model-server
action: ALLOW
rules:
- from:
- source:
principals:
- "cluster.local/ns/ai-inference/sa/api-gateway"
- "cluster.local/ns/ai-inference/sa/orchestrator"
to:
- operation:
methods: ["POST"]
paths: ["/v1/predict", "/v1/embeddings", "/v2/models/*/infer"]
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: deny-external-to-retriever
namespace: ai-inference
spec:
selector:
matchLabels:
app: vector-retriever
action: DENY
rules:
- from:
- source:
notNamespaces: ["ai-inference"]
```
### Egress Policy for Approved Model Endpoints
A `ServiceEntry` registers a service; it is not a complete egress firewall. Namespace `AuthorizationPolicy` controls requests to selected workloads, not arbitrary outbound HTTPS by destination host. Enforce approved egress through a verified gateway or network policy and test bypass routes. For application-originated HTTPS, do not also originate TLS in a DestinationRule without a designed HTTP-to-TLS route (double TLS breaks the connection).
```yaml
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: openai-api
namespace: ai-inference
spec:
hosts:
- api.openai.com
ports:
- number: 443
name: https
protocol: TLS
resolution: DNS
location: MESH_EXTERNAL
```
Official guidance: [Istio egress control](https://istio.io/latest/docs/tasks/traffic-management/egress/egress-control/).
## Traffic Management
### VirtualService for A/B Model Testing
```yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: model-server
namespace: ai-inference
spec:
hosts:
- model-server
http:
# Route by header for explicit model version selection
- match:
- headers:
x-model-version:
exact: "v2-experimental"
route:
- destination:
host: model-server
subset: v2-experimental
timeout: 120s
# Route by header for A/B test cohort
- match:
- headers:
x-ab-cohort:
exact: "treatment"
route:
- destination:
host: model-server
subset: v2-experimental
weight: 100
timeout: 120s
# Default traffic split: 90/10 canary
- route:
- destination:
host: model-server
subset: v1-stable
weight: 90
- destination:
host: model-server
subset: v2-experimental
weight: 10
timeout: 60s
retries:
attempts: 2
perTryTimeout: 30s
retryOn: unavailable,resource-exhausted
```
### DestinationRule with Subsets
```yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: model-server
namespace: ai-inference
spec:
host: model-server
trafficPolicy:
connectionPool:
http:
h2UpgradePolicy: UPGRADE
maxRequestsPerConnection: 100
tcp:
maxConnections: 200
connectTimeout: 5s
loadBalancer:
simple: LEAST_REQUEST
subsets:
- name: v1-stable
labels:
version: v1
trafficPolicy:
connectionPool:
http:
maxRequestsPerConnection: 50
- name: v2-experimental
labels:
version: v2
trafficPolicy:
connectionPool:
http:
maxRequestsPerConnection: 20
```
### Circuit Breaking for Inference Backends
```yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: model-server-circuit-breaker
namespace: ai-inference
spec:
host: model-server
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100
connectTimeout: 10s
http:
http1MaxPendingRequests: 50
http2MaxRequests: 200
maxRequestsPerConnection: 10
maxRetries: 3
outlierDetection:
consecutive5xxErrors: 3
interval: 15s
baseEjectionTime: 30s
maxEjectionPercent: 50
```
## Conflicts
- **BagelHole/DevOps-Security-Agent-Skills** presents the egress policy (ServiceEntry + DestinationRule with TLS SIMPLE + AuthorizationPolicy) as a complete egress firewall for approved model endpoints. **sickn33/agentic-awesome-skills** states that a ServiceEntry is not a complete egress firewall, that namespace AuthorizationPolicy does not control arbitrary outbound HTTPS by destination host, and that approved egress must be enforced through a verified gateway or network policy with bypass-route testing.
- **BagelHole/DevOps-Security-Agent-Skills** includes a DestinationRule for api.openai.com that sets trafficPolicy.tls.mode to SIMPLE, which would originate TLS to an already-TLS endpoint. **sickn33/agentic-awesome-skills** warns that for application-originated HTTPS, one must not also originate TLS in a DestinationRule without a designed HTTP-to-TLS route, because double TLS breaks the connection.
- **BagelHole/DevOps-Security-Agent-Skills** presents the istioctl install command as a production prerequisite. **sickn33/agentic-awesome-skills** labels it as an illustrative mutating install and notes that the default profile is not a validated production configuration, and adds a prerequisite to confirm the exact cluster/context, mesh version, CRD schemas, owned namespace, and authorized mutation scope before applying any changes.