解决 Linkerd 报错 protocol detection timeout MySQL/Redis 流量误识别修复
排查 客户端通过 Linkerd 访问 MySQL / Redis 等服务器首先发送握手报文的非 HTTP 协议时连接卡死或报 10s 超时,分析 协议嗅探与 opaque-ports 声明。
问题现象
将应用注入 Linkerd 边车后,连接内网 MySQL 报 10 秒超时中断:
ERR! connection error: protocol detection timed out after 10s
Proxy log: linkerd-proxy: Server-first protocol detected as HTTP, waiting for client preamble
触发根因
- Linkerd 边车代理默认通过“客户端先发数据”(Client-speaks-first)模式嗅探应用层协议以提供 HTTP 路由和指标;
- MySQL、Redis、PostgreSQL、SMTP 等属于“服务端先发问候报文”(Server-speaks-first)协议;
- 代理在等待客户端数据时陷入 10 秒的静默死锁,直至超时强行断开。
解决步骤
在服务定义或 Pod 注解中将数据库端口标记为 opaque-ports
告知 Linkerd 代理跳过协议嗅探,直接以纯 TCP 模式透明透传:
metadata:
annotations:
config.linkerd.io/opaque-ports: "3306,6379,5432"
或者在 Service 层面声明:
metadata:
annotations:
config.linkerd.io/opaque-ports: "3306"
更新部署并触发 Pod 滚动刷新
应用配置:
kubectl rollout restart deploy/my-app
验证确认
重新执行数据库连接测试:
MySQL 握手包瞬间穿透代理交付客户端,10 秒探测超时彻底解决。


