In this post we'll learn how to use the Istio service mesh by building one. We create an Amazon EKS cluster with Terraform, install Istio with Helm, and deploy two versions of a small Node.js app. Then we apply six YAML files, one at a time. After each file you run a command and see what changed.
By the end you'll have done each of these yourself:
- Added a proxy to every pod without changing the app
- Sent 80% of users to v1 and 20% to v2 (a canary release)
- Routed testers straight to v2 using a request header
- Shifted traffic between versions without redeploying
- Encrypted service-to-service traffic and blocked a client that wasn't in the mesh
- Allowed
GETrequests and blockedPOSTrequests based on the caller's identity
All the code is in the GitHub repo.
What is a service mesh?
Picture every pod in your cluster with a small assistant standing next to it. Every request in or out of the pod goes through that assistant first. Because it sees every request, the assistant can encrypt traffic, decide which version of a service gets a request, retry failed calls, and turn away callers who aren't allowed in.
In Istio:
- The assistant is an Envoy proxy, called the sidecar. It runs as an extra container in each pod.
- istiod is the control plane. It sends routing rules to every sidecar and gives each one a certificate.
Your application code doesn't change. You describe what you want in YAML, and the sidecars do it.
Istio resources used in this post
| Resource | What it does |
|---|---|
| Gateway | The front door that lets traffic from outside into the mesh. |
| VirtualService | Routing rules. They decide where a request goes. |
| DestinationRule | Names the versions (subsets) of a service and sets how to connect to them. |
| PeerAuthentication | Decides whether services must use mutual TLS (mTLS) to talk to each other. |
| AuthorizationPolicy | Decides who may call a service and what they may do. |
Architecture
You (curl) │ ▼ AWS Load Balancer │ ▼ ┌────────────────────────────────┐ │ Istio ingress gateway (Envoy) │ namespace: istio-ingress └───────────────┬────────────────┘ │ VirtualService: 80% / 20% ┌─────────┴─────────┐ ▼ ▼ ┌───────────┐ ┌───────────┐ │ app v1 │ │ app v2 │ namespace: istio-demo │ + sidecar │ │ + sidecar │ (Service: nodejs-app) └───────────┘ └───────────┘ istiod (namespace: istio-system) sends routing rules and mTLS certificates to every Envoy proxy shown above. What Terraform builds:
- VPC: two Availability Zones, public and private subnets, and one NAT gateway (
terraform-aws-modules/vpc/aws). - EKS: a managed cluster with one managed node group of
t3.largenodes (terraform-aws-modules/eks/aws). - Istio 1.32: three Helm releases.
baseinstalls the CRDs,istiodis the control plane, andgatewayis the ingress gateway.
What the YAML files deploy:
- Demo app: two Deployments (
nodejs-app-v1andnodejs-app-v2) behind one Service callednodejs-app. - Mesh rules: a DestinationRule, a Gateway, a VirtualService, a PeerAuthentication, and an AuthorizationPolicy.
Repository layout
infrastructure/ main.tf VPC, EKS cluster, node group, security group rule for Istio istio.tf Istio Helm releases: base, istiod, gateway variables.tf Region, cluster name, Istio version and namespaces outputs.tf Cluster and Istio outputs providers.tf AWS, Kubernetes, and Helm providers, S3 backend k8s-manifests/istio/ 01-namespace.yaml Turn on sidecar injection 02-deployments.yaml Two app versions behind one Service 03-destinationrule.yaml Define v1/v2, mTLS, circuit breaking 04-gateway-virtualservice.yaml Front door and routing rules 05-peer-authentication.yaml Require mTLS 06-authorization-policy.yaml Allow or block requests Prerequisites
- Terraform
>= 1.9 - AWS CLI v2, logged in with permission to create VPC, EKS, IAM, and load balancer resources
kubectl- A bash shell (on Windows, Git Bash works) and curl 7.84 or newer
- An S3 bucket for Terraform state
Step 1: Create the cluster and install Istio
1.1 How Istio is installed
istio.tf installs Istio as three Helm releases. The order matters, so each one depends on the previous one.
# infrastructure/istio.tf (excerpt) resource "helm_release" "istio_base" { name = "istio-base" repository = "https://blob.istio.io/istio-release/charts" chart = "base" # Istio CRDs version = var.istio_version # 1.32.0 namespace = "istio-system" create_namespace = true } resource "helm_release" "istiod" { name = "istiod" repository = "https://blob.istio.io/istio-release/charts" chart = "istiod" # control plane version = var.istio_version namespace = "istio-system" wait = true values = [yamlencode({ meshConfig = { enableAutoMtls = true } })] depends_on = [helm_release.istio_base] } resource "helm_release" "istio_ingressgateway" { name = "istio-ingressgateway" repository = "https://blob.istio.io/istio-release/charts" chart = "gateway" # ingress gateway version = var.istio_version namespace = "istio-ingress" create_namespace = true wait = false # don't block while AWS creates the load balancer values = [yamlencode({ service = { type = "LoadBalancer" } })] depends_on = [helm_release.istiod] } 1.2 Two things that break Istio on EKS
Port 15017 must be open to istiod. When a pod is created in a meshed namespace, Kubernetes calls istiod on port 15017 to add the sidecar. The EKS module's default node security group blocks that port. Kubernetes then refuses to create the pod, and the gateway stays at 0/1 with no pods. This rule in main.tf fixes it:
# infrastructure/main.tf, inside module "eks" node_security_group_additional_rules = { ingress_istiod_webhook = { description = "Cluster API to istiod webhook" protocol = "tcp" from_port = 15017 to_port = 15017 type = "ingress" source_cluster_security_group = true } } The Istio version must support your Kubernetes version. The cluster runs Kubernetes 1.36, so we use Istio 1.32, which supports Kubernetes 1.33 to 1.37 (support matrix). Get the charts from https://blob.istio.io/istio-release/charts. The older storage.googleapis.com repository has nothing newer than 1.30.
1.3 Apply
cd infrastructure terraform init terraform apply This takes about 15 to 20 minutes. Terraform also runs aws eks update-kubeconfig, so kubectl points at the new cluster when it finishes.
1.4 Check Istio
kubectl get pods -n istio-system kubectl get pods -n istio-ingress kubectl get svc -n istio-ingress You should see istiod and istio-ingressgateway both 1/1 Running. The istio-ingressgateway Service shows an EXTERNAL-IP ending in elb.amazonaws.com. If it still says <pending>, wait a few minutes.
Save that address for later:
GW=$(kubectl -n istio-ingress get svc istio-ingressgateway \ -o jsonpath='{.status.loadBalancer.ingress[0].hostname}') echo $GW Step 2: Use Istio one YAML file at a time
Go back to the repo root. Apply the files in order, and run the check after each one.
cd .. 2.1 Turn on sidecar injection (01-namespace.yaml)
What it does: The istio-injection: enabled label tells istiod to add an Envoy sidecar to every pod created in this namespace. Turning on the mesh for a namespace takes nothing else.
apiVersion: v1 kind: Namespace metadata: name: istio-demo labels: istio-injection: enabled Apply:
kubectl apply -f k8s-manifests/istio/01-namespace.yaml Check: The namespace exists, but it has no pods yet. You'll see the effect in the next step.
kubectl get namespace istio-demo --show-labels 2.2 Deploy two versions behind one Service (02-deployments.yaml)
What it does: It creates two Deployments of the same app, labeled version: v1 and version: v2, with two replicas each. One Service, nodejs-app, selects only on app: nodejs-app, so it sends traffic to both versions.
The two images listen on different ports: 8080 for v1 and 8081 for v2. Each Deployment names its port http, and the Service targets that name. Kubernetes looks up the named port on each pod, so one Service works for both versions.
# v1 (v2 is the same except the image and containerPort 8081) apiVersion: apps/v1 kind: Deployment metadata: name: nodejs-app-v1 namespace: istio-demo spec: replicas: 2 selector: matchLabels: { app: nodejs-app, version: v1 } template: metadata: labels: { app: nodejs-app, version: v1 } spec: containers: - name: nodejs-app image: public.ecr.aws/n4o6g6h8/simple-nodejs-app-1:latest ports: - name: http containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: nodejs-app namespace: istio-demo spec: selector: app: nodejs-app # matches v1 AND v2 ports: - name: http # the "http" name tells Istio this is HTTP traffic port: 80 targetPort: http # 8080 on v1 pods, 8081 on v2 pods Apply:
kubectl apply -f k8s-manifests/istio/02-deployments.yaml We'll also start two test pods. One runs inside the mesh, and one runs in a namespace outside the mesh. We use them in later steps.
kubectl -n istio-demo run client --image=curlimages/curl --command -- sleep 3600 kubectl create namespace no-mesh kubectl -n no-mesh run client --image=curlimages/curl --command -- sleep 3600 Check:
kubectl get pods -n istio-demo kubectl get pods -n no-mesh # istio-demo NAME READY STATUS client 2/2 Running nodejs-app-v1-xxxxx 2/2 Running nodejs-app-v2-xxxxx 2/2 Running # no-mesh NAME READY STATUS client 1/1 Running What this shows: Every pod in istio-demo has 2 containers, the app and istio-proxy. The same curl pod in no-mesh has only 1. Nothing in the Deployment asks for a sidecar. The namespace label added it.
2.3 Define the versions (03-destinationrule.yaml)
What it does: It tells Istio that subset v1 means pods labeled version: v1 and subset v2 means pods labeled version: v2. The routing rules in the next file use these names. It also sets how sidecars connect to the app:
-
ISTIO_MUTUAL: sidecars talk to each other over mTLS, using certificates from istiod. -
connectionPool: limits how many connections and queued requests the app gets. -
outlierDetection: if a pod returns five errors in a row, it's taken out of rotation for 30 seconds. This is called circuit breaking.
apiVersion: networking.istio.io/v1 kind: DestinationRule metadata: name: nodejs-app namespace: istio-demo spec: host: nodejs-app.istio-demo.svc.cluster.local trafficPolicy: tls: mode: ISTIO_MUTUAL connectionPool: tcp: maxConnections: 100 http: http1MaxPendingRequests: 100 maxRequestsPerConnection: 10 outlierDetection: consecutive5xxErrors: 5 interval: 10s baseEjectionTime: 30s maxEjectionPercent: 50 subsets: - name: v1 labels: { version: v1 } - name: v2 labels: { version: v2 } Apply:
kubectl apply -f k8s-manifests/istio/03-destinationrule.yaml Check:
kubectl get destinationrule -n istio-demo Apply this file before the VirtualService. If a route points to a subset that no DestinationRule defines, Istio returns
503errors.
2.4 Open the front door and add routing rules (04-gateway-virtualservice.yaml)
What it does: The Gateway opens port 80 on the ingress gateway. The VirtualService decides which version gets each request:
- Rule 1: a request with the header
x-version: v2always goes to v2. - Rule 2: every other request goes to v1 80% of the time and to v2 20% of the time.
- Every route adds an
x-served-byheader to the response. The app doesn't know about this header. The proxy adds it so you can see which version answered. - Requests time out after 5 seconds. Failed requests are retried up to 3 times.
apiVersion: networking.istio.io/v1 kind: Gateway metadata: name: nodejs-app-gateway namespace: istio-demo spec: selector: istio: ingressgateway # the gateway pods installed by Helm servers: - port: { number: 80, name: http, protocol: HTTP } hosts: ["*"] --- apiVersion: networking.istio.io/v1 kind: VirtualService metadata: name: nodejs-app namespace: istio-demo spec: hosts: ["*"] gateways: [nodejs-app-gateway] http: # Rule 1: testers who send "x-version: v2" always get v2 - match: - headers: x-version: { exact: v2 } route: - destination: { host: nodejs-app.istio-demo.svc.cluster.local, subset: v2 } headers: { response: { set: { x-served-by: v2 } } } # Rule 2: everyone else gets an 80/20 split - route: - destination: { host: nodejs-app.istio-demo.svc.cluster.local, subset: v1 } weight: 80 headers: { response: { set: { x-served-by: v1 } } } - destination: { host: nodejs-app.istio-demo.svc.cluster.local, subset: v2 } weight: 20 headers: { response: { set: { x-served-by: v2 } } } timeout: 5s retries: attempts: 3 perTryTimeout: 2s retryOn: 5xx,reset,connect-failure Apply:
kubectl apply -f k8s-manifests/istio/04-gateway-virtualservice.yaml Check 1, the canary split. Send 20 requests and count which version answered each one:
for i in $(seq 1 20); do curl -s -o /dev/null -w '%header{x-served-by}\n' "http://$GW/" done | sort | uniq -c 16 v1 4 v2 Istio picks the version at random for each request, so you may see 15/5 or 17/3. With 100 requests the result gets closer to 80/20. This is a canary release: a new version goes to a small share of users first.
Check 2, header routing. Send the same requests with the tester header:
for i in $(seq 1 10); do curl -s -o /dev/null -H "x-version: v2" -w '%header{x-served-by}\n' "http://$GW/" done | sort | uniq -c 10 v2 Requests with the header skip the 80/20 split. Your QA team can test v2 in production while most users still get v1.
Check 3, shift traffic without redeploying. In 04-gateway-virtualservice.yaml, change the weights from 80/20 to 50/50, then re-apply and run the loop again:
kubectl apply -f k8s-manifests/istio/04-gateway-virtualservice.yaml for i in $(seq 1 20); do curl -s -o /dev/null -w '%header{x-served-by}\n' "http://$GW/" done | sort | uniq -c kubectl get pods -n istio-demo # look at the AGE column You'll see about 10 v1 and 10 v2, and the pods keep their original age. The split changed within seconds and no pod restarted. To finish the rollout, set the weights to 0/100. To roll back, set them to 100/0. Set them back to 80/20 before you continue.
With curl older than 7.84, replace the
-w '%header{x-served-by}\n'part with
-D - | grep -i x-served-byto print the header.
2.5 Require mTLS (05-peer-authentication.yaml)
What it does: istiod gives every sidecar a short-lived certificate that identifies the workload. With STRICT mode, sidecars in istio-demo accept only mTLS connections from other sidecars. Plain, unencrypted requests are rejected.
apiVersion: security.istio.io/v1 kind: PeerAuthentication metadata: name: default namespace: istio-demo spec: mtls: mode: STRICT Apply:
kubectl apply -f k8s-manifests/istio/05-peer-authentication.yaml Check: Call the app from both test pods.
# Inside the mesh (has a sidecar) kubectl -n istio-demo exec client -c client -- \ curl -s -o /dev/null -w '%{http_code}\n' http://nodejs-app/ # Outside the mesh (no sidecar) kubectl -n no-mesh exec client -- \ curl -s -o /dev/null -w '%{http_code}\n' http://nodejs-app.istio-demo/ 200 000 command terminated with exit code 56 The pod inside the mesh gets 200. Its sidecar encrypted the request and presented its certificate. The pod outside the mesh has no sidecar and no certificate, so the connection is reset before it reaches the app. curl prints 000, and exit code 56 means the connection was reset. Both pods run the same image and the same command. The only difference is the sidecar.
Moving an existing app into the mesh? Start with
mode: PERMISSIVEso clients without a sidecar keep working. Switch toSTRICTonce every client has one.
2.6 Allow or block requests (06-authorization-policy.yaml)
What it does: mTLS proves who is calling. An AuthorizationPolicy decides what they're allowed to do. This policy allows two kinds of requests to nodejs-app:
- Any request that arrives through the ingress gateway, identified by the gateway's service account.
-
GETrequests from workloads in theistio-demonamespace.
Once an ALLOW policy applies to a workload, any request that doesn't match one of its rules is denied.
apiVersion: security.istio.io/v1 kind: AuthorizationPolicy metadata: name: nodejs-app-allow namespace: istio-demo spec: selector: matchLabels: { app: nodejs-app } action: ALLOW rules: - from: - source: principals: ["cluster.local/ns/istio-ingress/sa/istio-ingressgateway"] - from: - source: { namespaces: ["istio-demo"] } to: - operation: { methods: ["GET"] } Apply:
kubectl apply -f k8s-manifests/istio/06-authorization-policy.yaml Check: From the pod inside the mesh, send a GET and then a POST.
kubectl -n istio-demo exec client -c client -- \ curl -s -o /dev/null -w 'GET -> %{http_code}\n' http://nodejs-app/ kubectl -n istio-demo exec client -c client -- \ curl -s -w ' -> %{http_code}\n' -X POST http://nodejs-app/ GET -> 200 RBAC: access denied -> 403 The sidecar blocked the POST with 403 before it reached the app. Run the same POST before applying this file and you get the app's own response instead. Istio knows the caller is in istio-demo because it reads that from the caller's mTLS certificate. An IP address can be faked. The certificate can't.
Requests through the gateway still work, because rule 1 allows the gateway:
curl -s -o /dev/null -w '%{http_code}\n' "http://$GW/" # 200 The full request path
curl http://$GW/ │ ▼ AWS load balancer ▼ Ingress gateway (Envoy) │ Gateway: accept HTTP on port 80 │ VirtualService: header x-version=v2? -> v2, else 80% v1 / 20% v2 │ DestinationRule: pick a pod in the chosen subset, connect over mTLS ▼ App pod sidecar (Envoy) │ PeerAuthentication: reject anything that isn't mTLS │ AuthorizationPolicy: is this caller allowed to do this? ▼ App container Step 3 (optional): See the mesh in Kiali
Kiali draws the mesh as a live graph that shows the traffic split, mTLS padlocks, and request rates. It needs Prometheus for metrics.
REL=release-1.32 kubectl apply -f https://raw.githubusercontent.com/istio/istio/$REL/samples/addons/prometheus.yaml kubectl apply -f https://raw.githubusercontent.com/istio/istio/$REL/samples/addons/kiali.yaml kubectl -n istio-system rollout status deployment/kiali kubectl -n istio-system port-forward svc/kiali 20001:20001 Leave the port-forward running and open http://localhost:20001. The sample Kiali addon has no login, so it opens straight to the overview.
Send steady traffic
Kiali only draws traffic that happened during the selected time range. In a second terminal, keep requests flowing:
while true; do curl -s -o /dev/null "http://$GW/"; sleep 0.2; done Set up the graph
- In the left menu, click Traffic Graph.
- In the namespace selector, pick istio-demo and istio-ingress.
- Change the graph type from "App graph" to Versioned app graph, so v1 and v2 appear as separate nodes.
- In the Display menu, turn on Traffic Distribution and Security.
- In the top right, set the time range to Last 1m and refresh to Every 10s.
Wait about a minute for Prometheus to collect metrics.
What to look for in Kiali
1. The request path. You'll see istio-ingressgateway → the nodejs-app service (a triangle) → a box containing two circles, v1 and v2. This is the architecture diagram from the start of the post, drawn from live traffic.
2. The 80/20 split. With Traffic Distribution on, the edges into v1 and v2 show roughly 80% and 20%. Change the weights in 04-gateway-virtualservice.yaml to 50/50 and re-apply. After a minute or two the percentages move toward 50/50.
3. mTLS padlocks. With Security on, each edge between sidecars shows a small padlock. Every padlock is a connection that is encrypted and authenticated with mTLS, which 05-peer-authentication.yaml requires.
4. Edge colors and response codes. Green edges mean healthy traffic. Run the POST from step 2.6 a few times, then click the edge from client to nodejs-app. The side panel breaks down responses by HTTP code, and the 403s from 06-authorization-policy.yaml appear there. If enough requests fail, the edge turns orange or red.
5. Which pods have a sidecar. Go to Workloads and select all namespaces. The nodejs-app workloads and the istio-demo client show as part of the mesh. The client in no-mesh has a Missing sidecar warning. This is the 2/2 vs 1/1 difference from step 2.2.
6. Config validation. Go to Istio Config. All five resources from the YAML files are listed (Gateway, VirtualService, DestinationRule, PeerAuthentication, AuthorizationPolicy), each with a green check or a warning. Kiali catches mistakes here. For example, if a VirtualService points to a subset that no DestinationRule defines, it shows an error. Without it, that mistake would only show up as a 503.
If the graph is empty
- Check that the curl loop is still running and that the time range covers the last minute.
- Check that Prometheus is running:
kubectl -n istio-system get pods -l app.kubernetes.io/name=prometheus - Wait another 30 to 60 seconds. Prometheus collects metrics on an interval, so requests from the last few seconds may not show up yet.
Cleanup
Delete the Kubernetes resources before you run terraform destroy. The gateway created an AWS load balancer. If it still exists, Terraform can't delete the VPC and destroy hangs.
# 1. Test pods and the demo app kubectl delete namespace no-mesh kubectl delete -f k8s-manifests/istio/ # 2. Kiali and Prometheus, if you installed them REL=release-1.32 kubectl delete -f https://raw.githubusercontent.com/istio/istio/$REL/samples/addons/kiali.yaml kubectl delete -f https://raw.githubusercontent.com/istio/istio/$REL/samples/addons/prometheus.yaml # 3. Check that the gateway's load balancer is gone kubectl get svc -n istio-ingress # 4. Istio, EKS, and the VPC cd infrastructure terraform destroy If terraform destroy hangs on the VPC or subnets, open the EC2 console and look under Load Balancers for one tagged with your cluster name. Delete it, and the destroy will continue.
Conclusion
We never changed the application. Both versions ran their original images, and with six YAML files we:
- Added a sidecar proxy to every pod with one namespace label.
- Split traffic 80/20, sent testers to v2 with a header, and moved to 50/50 without restarting a pod.
- Added timeouts, retries, and circuit breaking.
- Encrypted traffic between services and blocked a client that had no sidecar.
- Allowed reads and blocked writes based on the caller's verified identity.
Each file adds one capability:
- Namespace label: puts a proxy next to every pod.
- DestinationRule: defines the versions and how to connect to them.
- Gateway and VirtualService: decide where each request goes.
- PeerAuthentication: requires mTLS.
- AuthorizationPolicy: decides who can do what.
Possible next steps:
- Automate canary releases with Flagger or Argo Rollouts, which change the weights for you based on error rates.
- Try fault injection to add delays or errors and see how your services handle them.
- Look at Istio ambient mode, which provides the mesh without a sidecar in every pod.

