Back to articles
DevOps & Systems

Configure Envoy Proxy as API Gateway for GRPC and HTTP3 Traffic Routing in Microservices

Detailed guide on configuring Envoy Proxy as an API Gateway to route GRPC and HTTP3 traffic in microservices systems, including setup, configuration, testing, and performance...

DPTCloud Engineering6 min read
Configure Envoy Proxy as API Gateway for GRPC and HTTP3 Traffic Routing in Microservices

Image credit: edwebster · Pixabay Content License

Introduction

Envoy Proxy is a high-performance network gateway designed to function as an API Gateway in microservices architectures. With support for GRPC and HTTP3, Envoy enables traffic routing, load balancing, monitoring, and security. This guide provides a detailed walkthrough of configuring Envoy Proxy to route GRPC and HTTP3 traffic in a microservices system.

Prerequisites

  • Three Linux-based VPS servers (Ubuntu 20.04+) or Docker containers
  • Docker and Docker Compose installed
  • Basics of GRPC and HTTP3 protocols
  • SSH access to all servers

Configure Envoy Proxy as API Gateway

First, create an envoy.yaml file to define the Envoy Proxy configuration:

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address:
          address: 0.0.0.0
          port_value: 10000
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: backend
                      domains: ["*"]
                      routes:
                        - match:
                            prefix: "/grpc"
                          route:
                            cluster: grpc_service
                        - match:
                            prefix: "/http3"
                          route:
                            cluster: http3_service
                http_filters:
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
    - name: grpc_service
      connect_timeout: 0.25s
      type: logical_dns
      lb_policy: round_robin
      load_assignment:
        cluster_name: grpc_service
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: grpc-service
                      port_value: 50051
    - name: http3_service
      connect_timeout: 0.25s
      type: logical_dns
      lb_policy: round_robin
      load_assignment:
        cluster_name: http3_service
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: http3-service
                      port_value: 8080

Run Envoy Proxy

Deploy Envoy Proxy using Docker Compose:

version: '3.8'
services:
  envoy:
    image: envoyproxy/envoy:v1.27-latest
    ports:
      - "10000:10000"
    volumes:
      - ./envoy.yaml:/etc/envoy/envoy.yaml
    command: ["/usr/local/bin/envoy", "-c", "/etc/envoy/envoy.yaml", "--disable-hot-restart"]

Test and Validate

Run GRPC and HTTP3 services to validate routing:

curl -X POST http://localhost:10000/grpc -d '{"message": "Hello GRPC"}'
curl -X GET http://localhost:10000/http3

Troubleshooting Common Issues

  • Connection failed: Check port 10000 is open and not blocked by firewall. Use netstat -tuln | grep 10000.
  • No response: Check Envoy logs with docker logs envoy.
  • Incorrect routing: Verify route definitions in envoy.yaml.
  • Low performance: Adjust load balancing and connection pool settings.

Performance Analysis and Optimization

Envoy provides detailed metrics such as latency, request rate, error rate, and connection count. Configure Prometheus and Grafana to collect and visualize these metrics for early detection of performance issues. Use the envoy_admin endpoint (default port 9901) to access real-time status, including listeners, clusters, routes, and health checks. Test metrics after load testing to confirm proper routing.

Security Configuration

Secure the system by enabling TLS for GRPC and HTTP3. Use Let's Encrypt to issue free SSL certificates for HTTP3 services. In envoy.yaml, add envoy.filters.network.tls_inspector and envoy.filters.network.sni filters to handle TLS. Configure mTLS (Mutual TLS) between microservices to ensure authentication and encryption. Use envoy.filters.http.tls_inspector to inspect TLS connections and block invalid ones.

Conditional Traffic Routing

Envoy supports routing based on headers, query parameters, and paths. For example, route GRPC traffic based on the user-type header to separate clusters for VIP users. In envoy.yaml, use route_match with conditions like headers, query_parameters, and prefix. This improves performance and security by directing traffic to appropriate services.

Advanced Docker Compose Deployment

For easier management, create a docker-compose.yml with multiple services. Add GRPC and HTTP3 services to the same Docker network. Configure services to connect to Envoy via the same network. Use depends_on to ensure Envoy starts after dependent services. This prevents startup errors due to unready services.

Preparation for Testing

Before deployment, conduct comprehensive testing. Create test scenarios for GRPC and HTTP3. Use grpcurl for GRPC testing and curl with HTTP3 for HTTP3 validation. Test error cases such as connection refusal, timeout, and unexpected responses. Record results for analysis and optimization.

Performance Optimization

Optimize performance by configuring parameters like max_requests, max_connections, and max_pending_requests in the cluster. Use envoy.filters.http.fault to simulate errors and test system resilience. Configure envoy.filters.http.cors to control cross-origin access. Use envoy.filters.http.router to optimize request routing.

Monitoring and Alerts

Set up automated alerts for failures. Use Prometheus to collect metrics and Grafana to visualize them. Configure alert rules in Prometheus to trigger notifications for errors or performance degradation. For example, alert when 5xx errors exceed 1% or average latency exceeds 100ms. This enables rapid detection and resolution of issues.

Related infrastructure & engineering guides: NVMe Cloud VPS for Docker, Nginx & Databases · Reduce VPS Costs by 70% with Spot Instance and Preemptible VPS: Cloud Optimization Strategy for Businesses

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478