惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Luca Cavallin

AI Engineering for Developers | Blog AI Engineering for Developers Platform Engineering End-to-End | Blog Google Cloud Networking 101: The Comprehensive TLDR | Blog Google Cloud Networking 101: The Comprehensive TLDR Containers Are Not Automatically Secure | Blog Containers Are Not Automatically Secure Watery Stone Beacon | Photography Blue Iceman Suture | Photography Hidden Emerald Pool | Photography Autumn Chapel Pinnacles | Photography A Tour of eBPF in the Linux Kernel: Observability, Security and Networking | Blog A Tour of eBPF in the Linux Kernel: Observability, Security and Networking Shared Violet Pulse | Photography Kubernetes Networking from Packets to Pods | Blog An Overview of Network Protocols | Blog An Overview of Network Protocols A Quick Journey Into the Linux Kernel | Blog A Quick Journey Into the Linux Kernel OpenTelemetry: A Guide to Observability with Go | Blog I'm on the Cillers Podcast Talking About Tech and Hackathons | Blog Yet Another List of Random Opinions on Writing Readable Code and Other Rants | Blog My post about Istio is now on the Istio blog too! | Blog Tropical Jungle Escape | Photography The Istio Service Mesh for People Who Have Stuff to Do | Blog Dreamy Cartoonscape Windmill | Photography Twilight Windmill Reflections | Photography Notes I took while reading "Applied Machine Learning and AI for Engineers" and "Introducing MLOps" | Blog Things I've Learned About Terraform That I Keep Telling People About | Blog Analyzing Unsplash Photo Performance with Python | Blog Analyzing Unsplash Photo Performance with Python I am a Top Mentor on MentorCruise! 🎉 | Blog CI/CD Observability on GitHub Actions and the Role of OpenTelemetry | Blog CI/CD Observability on GitHub Actions and the Role of OpenTelemetry Silent Water Sentinel | Photography Three Early Crosses | Photography Fiery Twilight Trails | Photography Forested Folds Flowing | Photography Majestic Snowbound Spire | Photography Shrouded Winter Peaks | Photography Space Cat Pillar | Photography I am a CNCF (Cloud Native Computing Foundation) Ambassador! | Blog Curved Valley Mist | Photography Highly Independent Tree | Photography Misty Morning Plateau | Photography Sick Shadows Fading | Photography Half Moon Blossom | Photography Serene Pedestal Swinging | Photography Sunset Clouds Reeling | Photography Aerial Nose Parking | Photography How to Structure C Projects: These Best Practices Worked for Me | Blog How to Structure C Projects: These Best Practices Worked for Me I'm on the KubeFM Podcast Talking About "Linux Containers From Scratch" | Blog I am (again) a Google Developers Expert! | Blog How to Configure OIDC with Terraform for GitHub Enterprise Server | Blog How to Configure OIDC with Terraform for GitHub Enterprise Server | Blog Modern Frontend Development: A Tooling Overview for Engineers Revisiting the Field | Blog Meet verto.sh: Your Gateway to Open-Source Collaboration. | Blog Crafting a Clean, Maintainable, and Understandable Makefile for a C Project. | Blog Crafting a Clean, Maintainable, and Understandable Makefile for a C Project. | Blog barco: Linux Containers From Scratch in C. | Blog barco: Linux Containers From Scratch in C. | Blog How to Create a Release With Multiple Artifacts From a GitHub Actions Workflow Using the Matrix Strategy | Blog How to Create a Release With Multiple Artifacts From a GitHub Actions Workflow Using the Matrix Strategy | Blog How Databases Store and Retrieve Data with B-Trees | Blog How Databases Store and Retrieve Data with B-Trees | Blog Concurrency in Go: Goroutines, Channels, Mutexes, and More | Blog Concurrency in Go: Goroutines, Channels, Mutexes, and More | Blog Club Cloud 2021: Cloud Engineering Panel Discussion | Blog Club Cloud 2021: Cloud Engineering Panel Discussion | Blog How to Prepare for the Google Cloud Engineer Associate Certification Exam | Blog How to Prepare for the Google Cloud Engineer Associate Certification Exam | Blog What is Google Cloud Deploy? | Blog What is GitOps? | Blog Club Cloud Stories #2 - News from Around the Cloud | Blog Club Cloud Stories #2 - News from Around the Cloud | Blog Club Cloud Stories #1 - The First Episode with Antoni Tzavelas & Mark van Holsteijn | Blog Club Cloud Stories #1 - The First Episode with Antoni Tzavelas & Mark van Holsteijn | Blog Quiet Oak Shining | Photography How to Read Firestore Events with Cloud Functions and Golang | Blog How to Read Firestore Events with Cloud Functions and Golang | Blog Google Cloud Pub/Sub vs NATS: An Easy-to-Understand Comparison | Blog Google Cloud Pub/Sub vs NATS: An Easy-to-Understand Comparison | Blog How to Deploy a Multi-cluster Service Mesh on GKE with Anthos | Blog How to Deploy a Multi-cluster Service Mesh on GKE with Anthos | Blog How to Safely Store Secrets in Terraform Using Cloud KMS | Blog How to Safely Store Secrets in Terraform Using Cloud KMS | Blog Designing Serverless Applications on AWS - Jacco Kulman and Luca Cavallin @ End2End LIVE | Blog Designing Serverless Applications on AWS - Jacco Kulman and Luca Cavallin @ End2End LIVE | Blog How to Use Terraform Workspaces to Manage Environment-based Configuration | Blog Puffy Steel Spreading | Photography How to Deploy ElasticSearch on GKE using Terraform and Helm | Blog How to Deploy ElasticSearch on GKE using Terraform and Helm | Blog Summer Windmills Spinning | Photography How to Optimize PHP Performance on Google Cloud Run | Blog How to Optimize PHP Performance on Google Cloud Run | Blog Foggy Boats Rusting | Photography How I Prepared for the Google Cloud Associate Cloud Engineer Exam | Blog How I Prepared for the Google Cloud Associate Cloud Engineer Exam | Blog Winter Kids Chasing | Photography
The Istio Service Mesh for People Who Have Stuff to Do
Luca Cavallin · 2024-09-21 · via Luca Cavallin

I recently made a small contribution to Istio, an open-source service mesh project. My contribution involved adding a few tests for one of the Istio CLI commands. If you want to check out the details, you can find the pull request here. It wasn't a huge change, but it was a great learning experience. Working on Istio helped me understand service meshes at a deeper level. I'm excited to contribute more. In this post, I'll explain what Istio is, why it's useful, and how it works.

What is Istio?

At its core, Istio is a service mesh. A service mesh manages communication between microservices, taking care of things like routing traffic, securing communication, and providing observability. As your microservices grow in number, managing these interactions can get complicated. Istio automates many of these tasks, so you can focus on building your application instead of managing service-to-service communication.

Why Use Istio?

As your architecture becomes more complex, you'll face new challenges. Services need to communicate in a reliable, secure, and efficient way. Istio helps you do this in three key areas:

  1. Managing Traffic: Istio gives you control over how traffic flows between services. You can split traffic between different versions of a service, reroute requests during deployments, or set up retry and timeout policies.

  2. Securing Communication: Istio makes it easy to enable mutual TLS (mTLS). This ensures that all communication between services is encrypted and authenticated, keeping unauthorized services out.

  3. Observability: Istio automatically collects metrics, logs, and traces, giving you real-time visibility into your services. This helps with monitoring, troubleshooting, and performance tuning.

These three areas—traffic management, security, and observability—are key to running a healthy microservices architecture, and Istio handles them with ease.

Managing Traffic with Istio

One of Istio's main features is managing traffic between services. In a microservices setup, you might have multiple versions of a service running at the same time. For example, you might be testing a new version of your payment service and want to send most of the traffic to version 1, but route some traffic to version 2.

Here's an example of how you can use Istio to split traffic between two versions of a service:

yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: payments
spec:
  hosts:
  - payments.myapp.com
  http:
  - route:
    - destination:
        host: payments
        subset: v1
      weight: 90
    - destination:
        host: payments
        subset: v2
      weight: 10

In this example:

  • 90% of traffic is sent to version 1 of the payments service, and 10% is sent to version 2.
  • The hosts field specifies the domain for which the virtual service is applicable—in this case, payments.myapp.com.
  • The route block defines how traffic is split between two subsets of the service: v1 (for version 1) and v2 (for version 2). The weight field controls the traffic distribution.

This is useful for canary deployments, where you test new features with a small percentage of users before rolling them out fully.

Envoy Proxy and Sidecar Containers

Istio's data plane relies on the Envoy proxy, a layer 7 proxy that manages all traffic between services. Every service in your mesh has its own sidecar proxy, which sits next to the service and manages all its inbound and outbound traffic.

Envoy allows you to apply traffic policies like retries, timeouts, and circuit breaking, all without changing your application code. It also collects detailed metrics about traffic flow, helping with monitoring and debugging.

Because Envoy runs as a sidecar container, it can enforce these rules and collect data without interfering with your application's logic. In short, Envoy acts as the "traffic cop" for all communication in your service mesh.

Observability: Seeing What's Happening in Your System

Running a system with many microservices can make it hard to see what's going on. Istio's built-in observability features help you track metrics, logs, and traces for all communication between services. This is vital for monitoring the health of your system, spotting performance issues, and fixing bugs.

Istio's observability tools give you a clear picture of how your system is working. You can detect problems early and make your services run more smoothly.

Security: Enabling mTLS and Access Control

Security is a big concern when managing microservices. Istio makes it easy to implement mutual TLS (mTLS), which encrypts all communication between services and ensures that services authenticate each other before exchanging data.

Istio also lets you set up access control policies to specify which services are allowed to communicate. This helps limit which services can interact, reducing your system's attack surface.

Here's an example of an Istio policy that allows only the billing service to communicate with the payments service:

yaml

apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: payments-to-billing
spec:
  selector:
    matchLabels:
      app: payments
  rules:
  - from:
    - source:
        principals: ["billing.myapp.com"]

In this policy:

  • The selector specifies that this rule applies to the payments service, using the label app: payments.
  • The rules block allows only the billing service, identified by the principal "billing.myapp.com", to communicate with payments. No other service is permitted to send traffic to payments.

This policy restricts all services except billing from accessing payments, tightening the security of your microservices.

What is SPIFFE?

Istio uses SPIFFE (Secure Production Identity Framework for Everyone) to manage service identities. SPIFFE provides a way to assign secure, verifiable identities to services. Each service in the mesh gets a SPIFFE Verifiable Identity Document (SVID), which is used along with mTLS to ensure secure communication. This identity system is the foundation of Istio's security model.

Networking in Istio

Networking in microservices can be difficult, especially when it comes to controlling traffic inside and outside the mesh. Istio provides several tools for managing network traffic:

  1. Service Entry: Allows external services to communicate with services inside the mesh and the other way around.
  2. Virtual Service: Defines how traffic is routed inside the mesh.
  3. Destination Rule: Applies traffic policies, such as load balancing or mTLS, to the services.
  4. Gateways: Manages traffic coming into and going out of the mesh.

Example Configuration: Gateway, Service Entry, Virtual Service, and Destination Rule

Let's say you have an API server inside your mesh that receives traffic from the internet via a load balancer. Here's how you can configure a Gateway, Service Entry, Virtual Service, and Destination Rule to handle this traffic.

Gateway Configuration

yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: api-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "api.myapp.com"

What is happening here? The Gateway listens on port 80 for HTTP traffic coming to the domain api.myapp.com. The selector field connects this Gateway to the Istio ingress gateway, which handles inbound traffic to the mesh.

Service Entry Configuration

Let's say your API server needs to call an external authentication service. Here's how you would configure a Service Entry:

yaml

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: auth-service-entry
spec:
  hosts:
  - "auth.external-service.com"
  location: MESH_EXTERNAL
  ports:
  - number: 443
    name: https
    protocol: HTTPS
  resolution: DNS
  endpoints:
  - address: 203.0.113.1

What is happening here? The Service Entry tells Istio how to route traffic to an external service (auth.external-service.com), which runs on port 443 (HTTPS). The location: MESH_EXTERNAL indicates that this service exists outside the Istio service mesh. The endpoints field includes the external service's IP address, allowing the API server inside the mesh to send requests.

Virtual Service Configuration

Here's how you can route traffic within the mesh:

yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: api-virtualservice
spec:
  hosts:
  - "api.myapp.com"
  gateways:
  - api-gateway
  http:
  - match:
    - uri:
        prefix: "/v1"
    route:
    - destination:
        host: api-service
        subset: stable

What is happening here? The Virtual Service defines the traffic routing rules. In this case, traffic arriving at api.myapp.com/v1 through the api-gateway is routed to the api-service in the mesh. The subset: stable refers to a specific version of the api-service (you can have multiple versions of the same service).

Destination Rule Configuration

Lastly, here's a Destination Rule to apply load balancing and mTLS:

yaml

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: api-destination-rule
spec:
  host: api-service
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
    tls:
      mode: ISTIO_MUTUAL

What is happening here? The Destination Rule applies policies to the traffic routed to the api-service. It uses round-robin load balancing to distribute requests evenly across instances. mTLS is enabled with tls.mode: ISTIO_MUTUAL, ensuring encrypted communication between services.

Resiliency: Handling Failures with Retries, Timeouts, and Circuit Breakers

In distributed systems, failures happen. Services might go down, networks might get slow, or users might experience delays. Istio helps you handle these problems with retries, timeouts, and circuit breakers.

  • Retries: Automatically retries failed requests to handle temporary failures without disrupting the user experience.
  • Timeouts: Defines how long a service should wait for a response before giving up and moving on.
  • Circuit breakers: If a service is failing, Istio can stop sending traffic to it, preventing cascading failures that might bring down other parts of the system.

Here's an example of how to configure retries and timeouts in Istio:

yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-service
spec:
  hosts:
  - my-service
  http:
  - route:
    - destination:
        host: my-service
    retries:
      attempts: 3
      perTryTimeout: 2s
    timeout: 5s

What is happening here? If a request to my-service fails, Istio will retry the request up to 3 times. Each retry attempt has a 2-second limit. The total time allowed for a request is 5 seconds. After this, Istio will stop waiting for a response.

For circuit breaking, you can use a Destination Rule like this:

yaml

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: my-service
spec:
  host: my-service
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 100
      http:
        http1MaxPendingRequests: 50
    outlierDetection:
      consecutive5xxErrors: 2
      interval: 10s
      baseEjectionTime: 30s
      maxEjectionPercent: 50

What is happening here? If my-service returns two consecutive 5xx errors within 10 seconds, Istio will stop sending traffic to it. The service will be ejected from the load balancing pool for 30 seconds before being reconsidered.

Summary

Istio is a powerful tool that simplifies traffic management, security, and observability for microservices. Contributing to Istio gave me insight into how it helps solve some of the complex challenges that come with running distributed systems.

If you're running a microservices architecture or planning to scale, Istio can help you make your system more resilient and easier to manage. If you have any questions or want to learn more about Istio, feel free to reach out—I'd be happy to share what I've learned.