← 中文资源

简体中文版本

kubectl: 无法连接到服务器

修复 kubectl 的 unable to connect to the server:检查 kubeconfig 上下文、API 服务器可达性与凭据过期。

阅读英文原文

症状

kubectl 报 The connection to the server ... was refused 或拨号超时。它在另一台机器上往往正常,指向本地配置或网络。

诊断

检查上下文与可达性:

kubectl config current-context
kubectl config view --minify
nc -vz api.cluster.internal 6443

服务器地址错误或客户端证书过期都会在此显现。

修复

选择正确上下文并刷新凭据:

kubectl config use-context prod
kubectl cluster-info

续期客户端证书或令牌,并检查 kubeconfig 权限。

验证

kubectl get nodes 返回节点列表;API 服务器可达且认证成功,确认上下文、网络与凭据均已对齐。