我无法连接到我们的Kubernetes集群。kubectl
命令似乎没有考虑到配置…
当我发出kubectl cluster-info
(或kubectl get pods
)时我得到以下错误消息:
与服务器localhost:8080的连接被拒绝-您是否指定了正确的主机或端口?
我怀疑~/.kube/config
指向我的minikube,但事实并非如此:
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS...==
server: https://10.95.xx.yy:6443
name: cluster.local
contexts:
- context:
cluster: cluster.local
namespace: xxx-cluster-xxx-xx-username
user: username
name: username-context
current-context: ""
kind: Config
preferences: {}
users:
- name: username
user:
client-certificate: .certs/username.crt
client-key: .certs/username.key
令人惊讶的是,$KUBECONFIG
环境变量被设置为正确的路径:
KUBECONFIG=/Users/username/.kube/config
和kubectl config view
工作正常(也就是说不是指向localhost
,而是指向https://10.95.xx.yy:6443
)
最后,我还尝试在调用kubectl
(kubectl get pods --kubeconfig=/Users/username/.kube/config
)时指定配置文件的路径,但错误仍然相同…
当前上下文未设置,如current-context: ""
所示;如果你要运行kubectl --context username-context get pods
,我希望它能做更多你想要的。如果是这种情况,可以运行kubectl config use-context username-context
来设置current-context
向前