ONNX Runtime กับ Service Mesh Setup — วิธีใช้

ONNX Runtime สำหรับ ML Inference

ONNX Runtime เป็น Inference Engine จาก Microsoft ที่ออกแบบมาให้รัน ML Models ได้เร็วที่สุดบนทุก Platform รองรับ ONNX Format ที่เป็นมาตรฐานกลางระหว่าง ML Frameworks ทำให้ Train ด้วย PyTorch แล้วรันด้วย ONNX Runtime ได้
เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ backlog agile คือ — ข้อมูลครบถ้วน 2026
Service Mesh เช่น Istio ช่วยจัดการ ML Inference Services โดยอัตโนมัติ ทำ Traffic Management ระหว่าง Model Versions, Load Balancing, mTLS, Retry/Circuit Breaker และ Observability โดยไม่ต้องเขียน Code เพิ่ม
เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ Prometheus PromQL Best Practices ที่ต้องรู้ — คู่มือฉบับสมบูรณ์ 2026
Istio Service Mesh Configuration

# === Istio Service Mesh สำหรับ ML Inference ===
# 1. Kubernetes Deployment
# k8s/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-inference-v1
namespace: ml
labels:
app: ml-inference
version: v1
spec:
replicas: 3
selector:
matchLabels:
app: ml-inference
version: v1
template:
metadata:
labels:
app: ml-inference
version: v1
annotations:
sidecar.istio.io/inject: "true"
spec:
containers:
- name: inference
image: myregistry/ml-inference:v1
ports:
- containerPort: 8080
resources:
requests:
cpu: "500m"
memory: "512Mi"
limits:
cpu: "2"
memory: "2Gi"
nvidia.com/gpu: "1"
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
---
# 2. Service
apiVersion: v1
kind: Service
metadata:
name: ml-inference
namespace: ml
spec:
ports:
- port: 80
targetPort: 8080
name: http
selector:
app: ml-inference
---
# 3. Istio VirtualService — Traffic Management
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ml-inference
namespace: ml
spec:
hosts:
- ml-inference
http:
- match:
- headers:
x-model-version:
exact: "v2"
route:
- destination:
host: ml-inference
subset: v2
- route:
- destination:
host: ml-inference
subset: v1
weight: 90
- destination:
host: ml-inference
subset: v2
weight: 10
timeout: 5s
retries:
attempts: 3
perTryTimeout: 2s
retryOn: 5xx, reset, connect-failure
---
# 4. DestinationRule — Load Balancing + Circuit Breaker
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: ml-inference
namespace: ml
spec:
host: ml-inference
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100
http:
h2UpgradePolicy: DEFAULT
http1MaxPendingRequests: 100
http2MaxRequests: 1000
outlierDetection:
consecutive5xxErrors: 3
interval: 10s
baseEjectionTime: 30s
maxEjectionPercent: 50
loadBalancer:
simple: LEAST_REQUEST
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
Best Practices
- ONNX Opset: ใช้ Opset Version ล่าสุดที่ ONNX Runtime รองรับ เพื่อ Performance ดีที่สุด
- Execution Providers: ใช้ CUDA EP สำหรับ GPU, TensorRT EP สำหรับ NVIDIA Optimization
- Service Mesh mTLS: เปิด mTLS ระหว่าง Services ป้องกัน Data ระหว่างทาง
- Circuit Breaker: ตั้ง Circuit Breaker ป้องกัน Cascade Failure
- Canary Deployment: ใช้ Istio Traffic Splitting ทดสอบ Model Version ใหม่
- Metrics: ติดตาม Latency, Throughput, Error Rate สำหรับทุก Model Version
ONNX Runtime คืออะไร
High-performance Inference Engine จาก Microsoft รัน ML Models รูปแบบ ONNX รองรับ CPU GPU NPU หลาย Platform เร็วกว่า Native Framework 2-3 เท่า
แนะนำเพิ่มเติม — ดูสัญญาณเทรดที่ XM Signal
เนื้อหาเกี่ยวข้อง — MLflow Experiment Freelance IT Career





