我有在Kubernetes中定义的服务,我想从与我的k8s群集相同的networking上的Google Compute VM访问。
我从这个链接可以看出,可以问k8s API服务器如何访问一个服务; 麻烦的是我无法连接到API服务器:
vm2:~$ kubectl proxy & [2] 1230 vm2:~$ curl http://localhost:8001/api/v1/namespaces/default/services/proxy/proxy I1102 09:53:25.861513 1104 logs.go:41] http: proxy error: dial tcp [::1]:8080: getsockopt: connection refused
我看到它似乎有错误的API服务器地址:
vm2:~$ kubectl cluster-info Kubernetes master is running at http://localhost:8080 To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
我的API服务器地址实际上是109.xxx 。 手动指定API服务器让我得到正确的服务器,但它声称没有资源:
vm2:~$ kubectl -s 109.xxx describe pods the server doesn't have a resource type "pods"
我得到了每个资源types/命令。 如果我从我的笔记本电脑运行相同的东西(通过身份validation),我会看到有关集群正在运行的Pod,部署和服务的更多信息。
如何使用我的虚拟机的服务帐户从我的虚拟机访问工作?
编辑:忘了提及,我已经validation,我的gcloud服务帐户正在通过正确的虚拟机:
vm2:~$ gcloud auth list Credentialed Accounts ACTIVE ACCOUNT * [email protected] To set the active account, run: $ gcloud config set account `ACCOUNT`
find了。 正如我认为与authentication有关。
我需要这样做:
gcloud container clusters get-credentials <cluster name> --zone <zone> --project <gcp project>
在那之后, kubectl config view有更多的输出,包括正确的API服务器地址和访问令牌,现在kubectl按预期工作。