来自kubectl的“找不到资源”获取远程集群

时间:2019-03-18 21:54:58

标签: kubernetes kubectl minikube

我已经为kubectl配置了一个多集群设置,该设置涉及Docker Mac随附的本地Kubernetes和使用Minikube的远程集群。当我将上下文切换到远程集群时,kubectl无法找到任何资源,例如pod或服务。我在哪里可以查看日志以了解更多信息?如果在实际的远程计算机上运行kubectl,我确实会看到资源。

当我执行kubectl version时,我得到了:

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"clean", BuildDate:"2019-02-01T20:00:57Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}

kubectl get componentstatus返回:

NAME                 STATUS    MESSAGE              ERROR
scheduler            Healthy   ok                   
controller-manager   Healthy   ok                   
etcd-0               Healthy   {"health": "true"}

kubectl cluster-info返回:

Kubernetes master is running at https://remote-cluster-ip:8443
KubeDNS is running at https://remote-cluster-ip:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

执行kubectl cluster-info dump会产生大量输出。

我按照以下步骤使Minikube工作并成功部署了示例应用程序。 https://kubernetes.io/docs/setup/minikube/

我按照以下步骤进行了多集群配置: https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

我将所有的crt和密钥文件从.minikube复制到了本地计算机上,以便在配置中使用。这是我编辑过的配置:

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://localhost:6443
  name: docker-for-desktop-cluster
- cluster:
    insecure-skip-tls-verify: true
    server: https://remote-cluster-ip:8443
  name: remote-cluster
contexts:
- context:
    cluster: docker-for-desktop-cluster
    user: docker-for-desktop
  name: docker-for-desktop
- context:
    cluster: remote-cluster
    namespace: remote-cluster
    user: minikube
  name: remote-cluster
current-context: remote-cluster
kind: Config
preferences: {}
users:
- name: docker-for-desktop
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
- name: minikube
  user:
    client-certificate: /path/to/local/client.crt
    client-key: /path/to/local/client.key

1 个答案:

答案 0 :(得分:0)

运行kubectl get pods --all-namespaces来检查是否可以看到所有命名空间中的pod。 如果您看到Pod正在运行,则必须为当前上下文设置默认名称空间,即

kubectl config set-context <remote-context-name> --namespace=default