Files
Kubernetes/问题记录/Metrics-Server启动报错证书验证失败.md
offends 8a87b699ba
All checks were successful
continuous-integration/drone Build is passing
first commit
2025-12-13 18:06:23 +08:00

37 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> 本文作者:丁辉
# Metrics-Server启动报错证书验证失败
日志显示错误为 `x509: cannot validate certificate for 172.18.0.x because it doesn't contain any IP SANs`,这说明集群中 kubelet 的证书没有包含节点的 IP 地址172.18.0.x作为 SANSubject Alternative Name
这是一个在测试环境中非常常见的问题。
## 解决方案
1. 编辑 metrics-server 的 Deployment
```bash
kubectl edit deployment metrics-server -n kube-system
```
2. 在 containers.args 部分添加以下参数:
```yaml
spec:
containers:
- args:
- --cert-dir=/tmp
- --secure-port=4443
- --kubelet-insecure-tls # 添加这一行
# --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
```
## 生产环境建议
**重要提醒**`--kubelet-insecure-tls` 参数会跳过 TLS 验证,**只应在开发测试环境使用**。在生产环境中,应该:
1. 为 kubelet 配置正确的证书,包含 IP SAN
2. 或者使用证书轮转功能RotateKubeletServerCertificate
3. 或者使用 `--kubelet-certificate-authority` 指定正确的 CA
但对于测试环境,使用 `--kubelet-insecure-tls` 是完全安全和合适的。