# gRPC错误：UNAVAILABLE。服务DNS解析失败：my-service.example.com:443

- **ID:** `api/grpc-unavailable-dns-resolution`
- **领域:** api
- **类别:** network_error
- **错误码:** `UNAVAILABLE`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

gRPC客户端无法解析目标服务主机名，由于DNS配置问题或网络连接问题。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.56.0 | active | — | — |
| Envoy proxy 1.27 | active | — | — |
| Kubernetes 1.28 | active | — | — |

## 解决方案

1. ```
   Verify DNS resolution manually: run 'dig my-service.example.com' or 'nslookup my-service.example.com'. If it fails, check /etc/resolv.conf for valid nameservers (e.g., 8.8.8.8).
   ```
2. ```
   Increase gRPC DNS resolver timeout: set GRPC_DNS_RESOLVER_TIMEOUT_MS=5000 environment variable before starting the client.
   ```
3. ```
   If using Kubernetes, ensure the service DNS name matches the gRPC target (e.g., my-service.namespace.svc.cluster.local). Use 'kubectl run -it --rm debug --image=busybox -- nslookup my-service' to test.
   ```

## 无效尝试

- **** — Restarting the gRPC client without fixing DNS configuration (e.g., missing /etc/resolv.conf entries) will reproduce the same error. (75% 失败率)
- **** — Changing the target endpoint to an IP address bypasses DNS but may fail if the service uses virtual hosting or TLS SNI requires the hostname. (60% 失败率)
