简体   繁体   English

无法kubectl连接我的kubernetes集群

[英]Unable to kubectl connect my kubernetes cluster

With a Kubernetes cluster up and running and the ability to go to the master over ssh with ssh-keys and run kubectl commands there; 随着Kubernetes集群的建立和运行,并能够使用ssh-keys通过ssh转到主服务器并在其中运行kubectl命令; I want to run kubectl commands on my local machine. 我想在本地计算机上运行kubectl命令。 So I try to setup the configuration, following the kubectl config : 所以我尝试按照kubectl config来设置配置

kubectl config set-cluster mykube --server=https://<master-ip>:6443
kubectl config set-context mykube --cluster=mykube --user=mykube-adm
kubectl config set-credentials mykube-adm --client-key=path/to/private/keyfile 

Activate the context: 激活上下文:

kubectl config use-context mykube

When I run a kubectl command: 当我运行kubectl命令时:

kubectl get nodes

It returns: 它返回:

The connection to the server localhost:8080 was refused - did you specify the right host or port? 与服务器localhost:8080的连接被拒绝-您是否指定了正确的主机或端口?

The output of kubectl config view kubectl config view的输出

apiVersion: v1
clusters:
- cluster:
    server: https://<master-ip>:6443
  name: mykubecontexts:
- context:
    cluster: mykube
    user: mykube-adm
  name: mykube
current-context: mykube
kind: Config
preferences: {}
users:
- name: mykube-adm
  user:
    client-key: path/to/private/keyfile

Unfortunately, above kubectl config file is incorrect. 不幸的是,上面的kubectl配置文件不正确。 It seems an error appeared due to manual formatting or something else. 由于手动格式化或其他原因,似乎出现了错误。

New line is missing in this part ( name: mykubecontexts: ): 这部分缺少新行( name: mykubecontexts:

clusters:
- cluster:
    server: https://<master-ip>:6443
  name: mykubecontexts:
- context:
    cluster: mykube
    user: mykube-adm
  name: mykube

Correct one is: 正确的一个是:

clusters:
- cluster:
    server: https://<master-ip>:6443
  name: mykube
contexts:
- context:
    cluster: mykube
    user: mykube-adm
  name: mykube

That's why cluster's name is mykubecontexts: : 这就是群集的名称为mykubecontexts:的原因:

clusters:
- cluster:
    server: https://<master-ip>:6443
  name: mykubecontexts:

and that's why there is no context in it, because contexts: is not defined. 这就是为什么其中没有上下文的原因,因为contexts:没有定义。

kubectl cannot find context mykube and switches to default one where server=localhost:8080 is by default. kubectl找不到上下文mykube并切换到默认值,其中默认情况下server=localhost:8080

kubectl config is located in ${HOME}/.kube/config file by default if --kubeconfig flag or $KUBECONFIG environment variable are not set. 如果未设置--kubeconfig标志或$KUBECONFIG环境变量,则默认情况下, kubectl config位于${HOME}/.kube/config文件中。

Please correct it to the following one: 请更正以下内容:

apiVersion: v1
clusters:
- cluster:
    server: https://<master-ip>:6443
  name: mykube
contexts:
- context:
    cluster: mykube
    user: mykube-adm
  name: mykube
current-context: mykube
kind: Config
preferences: {}
users:
- name: mykube-adm
  user:
    client-key: path/to/private/keyfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 kubernetes 集群 IP 地址已更改,现在 kubectl 将不再连接 - My kubernetes cluster IP address changed and now kubectl will no longer connect 无法将 Kubectl 上下文更改为我的 Google Kubernetes 集群 - Unable to Change Kubectl Context to my Google Kubernetes Cluster 无法使用 kubectl 连接到 GKE 集群 - Unable to connect with kubectl to a GKE cluster 配置 Kubectl 以连接到 local.network Kube.netes 集群 - Configure Kubectl to connect to a local network Kubernetes cluster Kubernetes / kubectl:无法连接到服务器来处理“ pods” - Kubernetes/kubectl: unable to connect to a server to handle “pods” 无法使用 kubectl 连接到我的私有集群(无法连接到服务器:dial tcp) - Can't connect to my private cluster using kubectl (Unable to connect to the server: dial tcp ) 无法连接到远程 Kube.netes 集群 - Unable to connect to remote Kubernetes cluster 如何配置本地 kubectl 连接到 kubernetes EKS 集群 - How to configure local kubectl to connect to kubernetes EKS cluster 使用 kubectl 从本地机器连接到 kube.netes 集群 - connect to kubernetes cluster from local machine using kubectl 无法从部署在同一集群中的我的 golang 应用程序连接到 kubernetes 上的 redis 集群 - Unable to connect to redis cluster on kubernetes from my golang application deployed within the same cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM