有人能分享一下kubectl exec是如何工作的吗,比如技术概述。还有什么方法来排除故障。
例如,我有以下问题:当试图连接到吊舱时:
kubectl.exe:I0502 04:25:18.562064 7288 loader.go:357]从文件C:\user\u615648/.kube/Config加载的配置在行:1 char:1+.\kubectl.exe exec dataarchives-service-264802370-mjwcl date-n FDM 18....48/.kube/Config:string)[],RemoteException+FullyQualifiedErrorId:NativeCommandError
I0502 04:25:18.636776 7288 round_trippers.go:414]获取https://fdmmgmt.uksouth.cloudapp.azure.com/api/v1/namespaces/fdm-development/pods/dataarchives-service-264802370-MJWCL I0502 04:25:18.636776 7288 round_trippers.go:421]请求头:I0502 04:25:18.636776 7288 round_trippers.go:424]接受:application/json,/I0502.Go:424]用户-代理:KubectL.exe/V1.9.3(Windows/AMD64)Kubernetes/D283541 I0502 04:25:18.716758 7288 Round_Trippers.Go:439]响应状态:200 79毫秒内确定I0502 04:25:18.716758 7288 Round_Trippers.Go:442]响应头:I0502 04:25:18.716758 7288 Round_Trippers.Go:445]内容-类型:Application/JSON I0502 04:25:18.716758 7288 Round_Trippers.Go:445]内容-长度:18.716758 7288 round_trippers.go:445]日期:2018年05月02日04:25:18 GMT I0502 04:25:18.717872 7288 Request.go:873]响应正文:{“kind”:“pod”,“apiversion”:“v1”,“metadata”:{“name”:“dataarchives-service-264802370-MJWCL”,“generatename”:“da“taarchives-service-264802370-”,“namespace”:“FDM-开发”,“无私”:“/api/v1/namespaces/fdm-development/pods/dataarchives-service-264802370-MJWCL”,“uid”:“eeb7d14f-49 5e-11e8-9d96-002248014205”,“resourceversion”:“15681866”,“creationtimestamp”:“2018-04-26t14:34:31z”,“labels”:{“app”:“dataadogistics”,“kubernetes.io/created-by”:“{\”kind\“:\”serializedreference\“,\”apiversion\“:\”v1\“,\”reference\“:{\”kind\“:\”replicaset\“,\”namespace\“:\”fdm-development\“,\”n ame\“:\”dataarchives-service-264802370\“,\”uid\“:\”eeaf949c-495e-11e8-9d96-002248014205\“,\”apiversions\“:\”ownerrefe rences“:[{”apiversion“:”extensions/v1beta1“,”kind“:”replicaset“,”name“:”dataarchives-service-264802370“,”uid“:”eeaf949c-495e-11e8-9d96-002248014205“,”controller“:true,”b lockownerdeletion“:true}]},”spec“:{”volumes“:[{”name“:”uploadsfileshare[truncated2143 chars]I0502https://fdmmgmt.uksouth.cloudapp.azure.com/api/v1/namespaces/fdm-development/pods/dataarchives-service-26480237 0-Mjwcl/exec?command=date&command=cmd&container=dataarchives&container=dataarchives&container=dataarchives&stderr=true&stdout=true I0502 04:25:18.908749 7288 round_trippers.go:421]请求头:I0502 0502 04:25:18.908749
7288 round_trippers.go:424]X-stream-protocol-version:v3.channel.k8s.io I0502 04:25:18.908749 7288 round_trippers.go:424]X-stream-protocol-version:channel.k8s.io I0502 04:25:18.908749 7288 round_trippers.go:424]
用户代理:kubectL.exe/v1.9.3(windows/amd64)kubernetes/d283541 I0502 04:25:19.086745 7288 round_trippers.go:439]响应状态:401未经授权177毫秒I0502 04:25:19.086745 7288 round_trippers.go:442]响应头:I0502 04:25:19.086745 7288_trippers.go:445]日期:2018年05月2日04:25:19 GMT I0502 04:25:19.086745 7288 Round_Trippers.go:445]内容-长度:12 I0502 04:25:19.086745 7288 Round_Trippers.go:445]内容-类型:文本/普通;charset=UTF-8 F0502 04:25:19.086745 7288 helpers.go:119]错误:无法升级连接:未经授权
感谢帮助。
在内部,kubectl命令通过HTTP/SPDY与Kubernetes API服务器交互。Kubernetes的API服务器是一个常规的REST API。Kubernetes目前正在使用SPDY,但维护者计划在docker允许时立即切换到HTTP/2:https://github.com/Kubernetes/Kubernetes/issues/7452
您可以在这里查看kubectl命令如何调用kubernetes go-client来与REST API交互:https://github.com/kubernetes/kubernetes/blob/e6272b887b81a62e6f06b7fac4b3b61d1c8bf657/pkg/kubectl/cmd/exec/exec.go#l310
关于您的具体堆栈跟踪:“错误:无法升级连接:未授权”看起来您没有被授权。您是否能够使用kubectl运行其他命令,例如“kubectl get po--all-namespaces”?