Kubernetes v1.12 Kubectl exec问题

时间:2018-11-19 10:29:32

标签: kubernetes exec kubectl

我一直在使用Kelsey Hightower出色的kubernetes-the-hard-way-guide学习Kubernetes。

使用本指南,我已在GCE上安装了v1.12。除了kubectl exec之外,其他所有功能都可以正常运行:

$ kubectl exec -it shell-demo – /bin/bash --kubeconfig=/root/certsconfigs/admin.kubeconfig
error: unable to upgrade connection: Forbidden (user=kubernetes, verb=create, resource=nodes, subresource=proxy)

请注意,我已设置KUBECONFIG=/root/certsconfigs/admin.kubeconfig

除了exec以外,所有其他kubectl函数均可与此admin.kubeconfig文件一起正常工作,因此,我推断出该文件对我的集群有效。

我敢肯定,我在某个地方犯了一个初学者的错误,但是如果有人可以建议我离开的地方,我应该非常感激。

TIA

肖恩

我已经仔细检查了主控制器上任何地方都不存在.kube/config文件:

root@controller-1:/root/deployment/kubernetes# kubectl get pods
NAME READY STATUS
shell-demo 1/1 Running 0 23m

以下是-v8的输出:

root@controller-1:/root/deployment/kubernetes# kubectl -v8 exec -it shell-demo – /bin/bash
I1118 15:18:16.898428 11117 loader.go:359] Config loaded from file /root/certsconfigs/admin.kubeconfig
I1118 15:18:16.899531 11117 loader.go:359] Config loaded from file /root/certsconfigs/admin.kubeconfig
I1118 15:18:16.900611 11117 loader.go:359] Config loaded from file /root/certsconfigs/admin.kubeconfig
I1118 15:18:16.902851 11117 round_trippers.go:383] GET ://127.0.0.1:6443/api/v1/namespaces/default/pods/shell-demo
I1118 15:18:16.902946 11117 round_trippers.go:390] Request Headers:
I1118 15:18:16.903016 11117 round_trippers.go:393] Accept: application/json, /
I1118 15:18:16.903091 11117 round_trippers.go:393] User-Agent: kubectl/v1.12.0 (linux/amd64) kubernetes/0ed3388
I1118 15:18:16.918699 11117 round_trippers.go:408] Response Status: 200 OK in 15 milliseconds
I1118 15:18:16.918833 11117 round_trippers.go:411] Response Headers:
I1118 15:18:16.918905 11117 round_trippers.go:414] Content-Type: application/json
I1118 15:18:16.918974 11117 round_trippers.go:414] Content-Length: 2176
I1118 15:18:16.919053 11117 round_trippers.go:414] Date: Sun, 18 Nov 2018 15:18:16 GMT
I1118 15:18:16.919218 11117 request.go:942] Response Body: {“kind”:“Pod”,“apiVersion”:“v1”,“metadata”:{“name”:“shell-demo”,“namespace”:“default”,“selfLink”:"/api/v1/namespaces/default/pods/shell-demo",“uid”:“99f320f8-eb42-11e8-a053-42010af0000b”,“resourceVersion”:“13213”,“creationTimestamp”:“2018-11-18T14:59:51Z”},“spec”:{“volumes”:[{“name”:“shared-data”,“emptyDir”:{}},{“name”:“default-token-djprb”,“secret”:{“secretName”:“default-token-djprb”,“defaultMode”:420}}],“containers”:[{“name”:“nginx”,“image”:“nginx”,“resources”:{},“volumeMounts”:[{“name”:“shared-data”,“mountPath”:"/usr/share/nginx/html"},{“name”:“default-token-djprb”,“readOnly”:true,“mountPath”:"/var/run/secrets/kubernetes.io/serviceaccount"}],“terminationMessagePath”:"/dev/termination-log",“terminationMessagePolicy”:“File”,“imagePullPolicy”:“Always”}],“restartPolicy”:“Always”,“terminationGracePeriodSeconds”:30,“dnsPolicy”:“ClusterFirst”,“serviceAccountName”:“default”,“serviceAccount”:“default”,“nodeName”:“worker-1”,“securityContext”:{},“schedulerName”:“default-scheduler”,“tolerations”:[{“key”:"node.kubernet [truncated 1152 chars]
I1118 15:18:16.925240 11117 round_trippers.go:383] POST …
error: unable to upgrade connection: Forbidden (user=kubernetes, verb=create, resource=nodes, subresource=proxy)

1 个答案:

答案 0 :(得分:1)

根据您的日志,kubectl和apiserver之间的连接很好,并且正在正确验证。

为满足exec请求,apiserver与运行pod的kubelet联系,并且该连接被禁止。

您的kubelet已配置为对请求进行身份验证/授权,并且没有授权apiserver凭据针对kubelet的API发出exec请求。

基于禁止的消息,您的apiserver正在作为kubelet的“ kubernetes”用户进行身份验证。

您可以使用以下命令向该用户授予对kubelet API的完全权限:

kubectl create clusterrolebinding apiserver-kubelet-admin --user=kubernetes --clusterrole=system:kubelet-api-admin

有关更多信息,请参见以下文档

  

https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet-authentication-authorization/#overview

     

https://kubernetes.io/docs/reference/access-authn-authz/rbac/#other-component-roles