[英]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.