Istio is an open-source service mesh that provides traffic management, security, and observability for microservices. It transparently layers onto existing distributed applications without changing code.
What Is Istio?
Istio is a CNCF graduated project that adds a proxy sidecar to every pod in your Kubernetes cluster. These proxies handle all network traffic, providing mutual TLS, traffic routing, circuit breaking, and detailed telemetry automatically.
Key Features:
- Automatic mutual TLS encryption
- Traffic routing and splitting
- Circuit breaking and fault injection
- Rate limiting
- Distributed tracing (Jaeger, Zipkin)
- Metrics (Prometheus + Grafana)
- Access logging
- Authorization policies
Installation
# Install istioctl
curl -L https://istio.io/downloadIstio | sh -
export PATH=$PWD/istio-*/bin:$PATH
# Install Istio with demo profile
istioctl install --set profile=demo -y
# Enable sidecar injection for namespace
kubectl label namespace default istio-injection=enabled
# Verify
istioctl verify-install
Traffic Management
Canary Deployment
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: my-app
spec:
hosts:
- my-app
http:
- route:
- destination:
host: my-app
subset: v1
weight: 90
- destination:
host: my-app
subset: v2
weight: 10
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: my-app
spec:
host: my-app
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
Circuit Breaker
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: payment-service
spec:
host: payment-service
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100
http:
h2UpgradePolicy: DEFAULT
http1MaxPendingRequests: 100
http2MaxRequests: 1000
outlierDetection:
consecutive5xxErrors: 5
interval: 30s
baseEjectionTime: 30s
maxEjectionPercent: 50
Istio API: Programmatic Mesh Management
from kubernetes import client, config
config.load_kube_config()
custom = client.CustomObjectsApi()
# List all VirtualServices
vs_list = custom.list_namespaced_custom_object(
group="networking.istio.io",
version="v1beta1",
namespace="default",
plural="virtualservices"
)
for vs in vs_list["items"]:
print(f"VirtualService: {vs['metadata']['name']}")
for route in vs["spec"].get("http", []):
for dest in route.get("route", []):
host = dest["destination"]["host"]
weight = dest.get("weight", 100)
print(f" -> {host} ({weight}%)")
# Update traffic split programmatically
custom.patch_namespaced_custom_object(
group="networking.istio.io",
version="v1beta1",
namespace="default",
plural="virtualservices",
name="my-app",
body={
"spec": {
"http": [{
"route": [
{"destination": {"host": "my-app", "subset": "v1"}, "weight": 50},
{"destination": {"host": "my-app", "subset": "v2"}, "weight": 50}
]
}]
}
}
)
Security: Authorization Policy
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: allow-frontend-only
namespace: default
spec:
selector:
matchLabels:
app: backend-api
rules:
- from:
- source:
principals: ["cluster.local/ns/default/sa/frontend"]
to:
- operation:
methods: ["GET", "POST"]
paths: ["/api/*"]
Resources
- Istio Docs
- Istio GitHub — 36K+ stars
- Kiali Dashboard
Need to scrape web data for your microservices? Check out my web scraping tools on Apify — production-ready actors for Reddit, Google Maps, and more. Questions? Email me at spinov001@gmail.com
Top comments (0)