Envoy Proxyチートシート
Envoy Proxyチートシート
インストール
| プラットフォーム | コマンド |
|---|---|
| Ubuntu/Debian | `curl -sL ‘https://deb.dl.getenvoy.io/public/gpg.8115BA8E629CC074.key’ \ |
| macOS | brew install envoy |
| Docker | docker pull envoyproxy/envoy:v1.28-latest |
| Binary (Linux) | curl -L https://github.com/envoyproxy/envoy/releases/download/v1.28.0/envoy-1.28.0-linux-x86_64 -o envoy && chmod +x envoy && sudo mv envoy /usr/local/bin/ |
| RHEL/CentOS | `curl -sL ‘https://rpm.dl.getenvoy.io/public/gpg.CF716AF503183491.key’ \ |
| Kubernetes (Helm) | helm repo add bitnami https://charts.bitnami.com/bitnami && helm install my-envoy bitnami/envoy |
| Verify Installation | envoy --version |
基本コマンド
| コマンド | 説明 |
|---|---|
envoy -c envoy.yaml | 指定された設定ファイルで Envoy を起動する |
envoy --version | Envoyのバージョン情報を表示 |
envoy --help | 利用可能なコマンドラインオプションをすべて表示 |
envoy --mode validate -c envoy.yaml | 設定ファイルを起動せずに検証する |
envoy -c envoy.yaml --log-level info | 特定のログレベル(trace、debug、info、warn、error、critical)から開始する |
envoy -c envoy.yaml --component-log-level upstream:debug | 特定のコンポーネントのログレベルを設定 |
envoy -c envoy.yaml --service-cluster my-cluster | サービスクラスタ識別子から開始する |
envoy -c envoy.yaml --service-node node-1 | サービスノード識別子から開始する |
envoy -c envoy.yaml --base-id 0 | ホットリスタート機能のベースIDを設定 |
envoy -c envoy.yaml --restart-epoch 1 | エポック番号で hot restart を実行 |
envoy -c envoy.yaml --drain-time-s 60 | グレースフルシャットダウンのためのドレインタイムを設定(秒) |
envoy -c envoy.yaml --parent-shutdown-time-s 90 | 親の停止時間をホットリスタート中に設定する |
envoy -c envoy.yaml --concurrency 4 | ワーカースレッドの数を設定 |
envoy -c envoy.yaml --disable-hot-restart | ホットリスタート機能を無効にする |
envoy --help-hidden | 非表示/詳細なコマンドラインオプションを表示 |
管理インターフェースコマンド
| コマンド | 説明 |
|---|---|
curl http://localhost:9901/server_info | サーバー情報と現在の状態を取得 |
curl http://localhost:9901/stats | プレーンテキスト形式ですべての統計を取得 |
curl http://localhost:9901/stats/prometheus | Prometheusフォーマットでエクスポート統計 |
curl http://localhost:9901/stats?format=json | JSON形式で統計を取得 |
curl http://localhost:9901/stats?filter=cluster.outbound | プレフィックスで統計をフィルタリング |
curl http://localhost:9901/stats?usedonly | ゼロ以外の値を持つ統計のみを表示 |
curl http://localhost:9901/config_dump | 現在の設定を完全にダンプ |
curl http://localhost:9901/config_dump?resource=bootstrap | bootstrap 設定のみをダンプする |
curl http://localhost:9901/config_dump?resource=dynamic_listeners | 動的リスナー設定をダンプする |
curl http://localhost:9901/config_dump?resource=dynamic_clusters | 動的クラスタ設定をダンプ |
curl http://localhost:9901/clusters | クラスターの詳細情報と正常性ステータスを取得 |
curl http://localhost:9901/listeners | リスナーの詳細情報を取得 |
curl http://localhost:9901/ready | Envoyがトラフィックを提供する準備ができているかを確認する |
curl -X POST http://localhost:9901/healthcheck/fail | ヘルスチェックのためにサーバーを障害状態としてマーク |
curl -X POST http://localhost:9901/healthcheck/ok | ヘルスチェックのためにサーバーを正常とマーク |
curl -X POST http://localhost:9901/reset_counters | すべての統計カウンターをゼロにリセット |
curl -X POST http://localhost:9901/drain_listeners | グレースフルシャットダウンのためのリスナーをドレイン |
curl -X POST http://localhost:9901/logging?level=debug | 実行時にグローバルログレベルを変更 |
curl -X POST http://localhost:9901/logging?upstream=debug | コンポーネント固有のログレベルを変更 |
curl -X POST http://localhost:9901/runtime_modify?key=value | ランタイム構成値を変更 |
高度な使用法
| コマンド | 説明 |
|---|---|
| `curl http://localhost:9901/stats \ | grep circuit_breakers` |
| `curl http://localhost:9901/stats \ | grep outlier_detection` |
| `curl http://localhost:9901/stats \ | grep ratelimit` |
| `curl http://localhost:9901/stats \ | grep upstream_rq_retry` |
| `curl http://localhost:9901/stats \ | grep ssl` |
| `curl http://localhost:9901/stats \ | grep http.ingress.downstream_rq` |
| `curl http://localhost:9901/clusters \ | grep health_flags` |
| `curl http://localhost:9901/config_dump \ | jq ‘.configs[].bootstrap.tracing’` |
| `curl http://localhost:9901/config_dump \ | jq ‘.configs[].dynamic_active_clusters’` |
| `curl http://localhost:9901/stats?format=json \ | jq ‘.stats[] \ |
| `curl http://localhost:9901/listeners \ | grep -A 5 “address”` |
| `curl http://localhost:9901/stats/prometheus \ | grep envoy_cluster_upstream_rq_total` |
docker run -d -v $(pwd)/envoy.yaml:/etc/envoy/envoy.yaml -p 9901:9901 -p 10000:10000 envoyproxy/envoy:v1.28-latest | Dockerでマウントされた設定でEnvoyを実行 |
kubectl create configmap envoy-config --from-file=envoy.yaml | Envoy 設定用の Kubernetes ConfigMap を作成する |
kubectl logs -f deployment/envoy | Kubernetes における Envoy のログを追跡する |
envoy -c envoy.yaml --log-format '[%Y-%m-%d %T.%e][%t][%l] %v' | カスタムログ形式で開始 |
curl http://localhost:9901/certs | ロード済みのTLS証明書の情報を表示 |
curl http://localhost:9901/memory | メモリ割り当て統計を表示 |
curl http://localhost:9901/contention | ミューテックスの競合統計を表示(有効な場合) |
curl -X POST http://localhost:9901/cpuprofiler?enable=y | CPUプロファイリングを有効にする(プロファイリング付きでコンパイルされている場合) |
設定
基本設定構造
# envoy.yaml - Minimal 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: "/"
route:
cluster: service_backend
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: service_backend
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: service_backend
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: backend-service
port_value: 8080
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9901
動的設定 (xDS)
# envoy-dynamic.yaml - Control plane configuration
node:
cluster: my-cluster
id: node-1
dynamic_resources:
lds_config:
resource_api_version: V3
api_config_source:
api_type: GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
cds_config:
resource_api_version: V3
api_config_source:
api_type: GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
static_resources:
clusters:
- name: xds_cluster
connect_timeout: 1s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
http2_protocol_options: {}
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: control-plane
port_value: 18000
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9901
高度な機能設定
# Circuit breaker and outlier detection
clusters:
- name: backend_service
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
circuit_breakers:
thresholds:
- priority: DEFAULT
max_connections: 1024
max_pending_requests: 1024
max_requests: 1024
max_retries: 3
outlier_detection:
consecutive_5xx: 5
interval: 30s
base_ejection_time: 30s
max_ejection_percent: 50
enforcing_consecutive_5xx: 100
load_assignment:
cluster_name: backend_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: backend
port_value: 8080
health_check_config:
port_value: 8081
TLS設定
# TLS termination
listeners:
- name: https_listener
address:
socket_address:
address: 0.0.0.0
port_value: 443
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_https
route_config:
name: local_route
virtual_hosts:
- name: backend
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: backend_service
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
common_tls_context:
tls_certificates:
- certificate_chain:
filename: /etc/ssl/certs/server.crt
private_key:
filename: /etc/ssl/private/server.key
一般的なユースケース
ユースケース: 基本的なHTTPプロキシ
バックエンドサービスにトラフィックを転送する簡単なHTTPプロキシとしてEnvoyを設定します。
# Create configuration file
cat > envoy.yaml << EOF
static_resources:
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 8080
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: "/"
route:
cluster: backend_cluster
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: backend_cluster
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: backend_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: localhost
port_value: 3000
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9901
EOF
# Start Envoy
envoy -c envoy.yaml
# Test the proxy
curl http://localhost:8080
# Monitor statistics
curl http://localhost:9901/stats | grep http
ユースケース: 複数のバックエンドへのロードバランシング
ヘルスチェックを使用して、複数のバックエンドインスタンス間でロードバランシングするようEnvoyを設定します。
# Create load balancing configuration
cat > envoy-lb.yaml << EOF
static_resources:
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 8080
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: "/"
route:
cluster: backend_cluster
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: backend_cluster
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
health_checks:
- timeout: 1s
interval: 10s
unhealthy_threshold: 2
healthy_threshold: 2
http_health_check:
path: /health
load_assignment:
cluster_name: backend_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: backend1.example.com
port_value: 8080
- endpoint:
address:
socket_address:
address: backend2.example.com
port_value: 8080
- endpoint:
address:
socket_address:
address: backend3.example.com
port_value: 8080
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9901
EOF
# Start Envoy with load balancing
envoy -c envoy-lb.yaml
# Check cluster health status
curl http://localhost:9901/clusters
# Monitor load distribution
watch -n 1 'curl -s http://localhost:9901/stats | grep backend_cluster.upstream_rq_total'
ユースケース: TLSターミネーションと再暗号化
クライアントからのTLSを終端し、バックエンドに再暗号化するようEnvoyを設定します。
# Generate self-signed certificates for testing
openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.crt -days 365 -nodes -subj "/CN=localhost"
# Create TLS configuration
cat > envoy-tls.yaml << EOF
static_resources:
listeners:
- name: https_listener
address:
socket_address:
address: 0.0.0.0
port_value: 443
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_https
route_config:
name: local_route
virtual_hosts:
- name: backend
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: secure_backend
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
common_tls_context:
tls_certificates:
- certificate_chain:
filename: server.crt
private_key:
filename: server.key
clusters:
- name: secure_backend
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
load_assignment:
cluster_name: secure_backend
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: backend.example.com
port_value: 443
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9901
EOF
# Start Envoy with TLS
envoy -c envoy-tls.yaml
# Test TLS connection
curl -k https://localhost
# Check TLS statistics
curl http://localhost:9901/stats | grep ssl
ユースケース: レートリミットとサーキットブレーキング
回復力のあるサービス通信のためのレートリミットとサーキットブレーキングを実装します。
# Create resilience configuration
cat > envoy-resilience.yaml << EOF
static_resources:
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 8080
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: "/"
route:
cluster: protected_backend
retry_policy:
retry_on: "5xx"
num_retries: 3
per_try_timeout: 1s
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: protected_backend
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
circuit_breakers:
thresholds:
- priority: DEFAULT
max_connections: 100
max_pending_requests: 100
max_requests: 100
max_retries: 3
outlier_detection:
consecutive_5xx: 5
interval: 10s
base_ejection_time: 30s
max_ejection_percent: 50
load_assignment:
cluster_name: protected_backend
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: backend.example.com
port_value: 8080
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9901
EOF
# Start Envoy with resilience features
envoy -c envoy-resilience.yaml
# Monitor circuit breaker status
curl http://localhost:9901/stats | grep circuit_breakers
# Check outlier detection events
curl http://localhost:9901/stats | grep outlier_detection
# View retry statistics
curl http://localhost:9901/stats | grep retry
ユースケース: 分散トレーシングによる可観測性
マイクロサービスの可観測性のために、分散トレーシングでEnvoyを設定します。
# トレーシング設定を作成
cat > envoy-tracing.yaml << EOF
static_resources:
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 8080
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
Note: For sections 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, and the incomplete code block 14, no specific text was provided to translate. I've maintained the structure and formatting as requested.