cnrancher / kube-explorer

A portable explorer for Kubernetes, without any dependency.
Apache License 2.0
215 stars 26 forks source link

pod 的web shell 打开后提示无法连接,kubectl可以打开 #6

Closed eager-yu closed 2 years ago

eager-yu commented 3 years ago

现像:

  1. log Find All: [cluster] pod socket.js:81 Socket connecting (id=3, url=ws://xxxx:9898/api/v1/namespaces/default/pods/centos-test-d9b5b57b7-29r4t/log...) socket.js:86 WebSocket connection to 'ws://xxxx:9898/api/v1/namespaces/default/pods/centos-test-d9b5b57b7-29r4t/log?previous=false&follow=true&timestamps=true&pretty=true&container=centos-x&sinceSeconds=1800&sockId=3' failed: value @ socket.js:86 (anonymous) @ ContainerLogs.vue:315 d @ runtime.js:45 (anonymous) @ runtime.js:274 O.forEach.t. @ runtime.js:97 r @ asyncToGenerator.js:3 l @ asyncToGenerator.js:25 (anonymous) @ asyncToGenerator.js:32 (anonymous) @ asyncToGenerator.js:21 connect @ ContainerLogs.vue:222 (anonymous) @ ContainerLogs.vue:214 d @ runtime.js:45 (anonymous) @ runtime.js:274 O.forEach.t. @ runtime.js:97 r @ asyncToGenerator.js:3 l @ asyncToGenerator.js:25 (anonymous) @ asyncToGenerator.js:32 (anonymous) @ asyncToGenerator.js:21 mounted @ ContainerLogs.vue:213 Qt @ vue.runtime.esm.js:1854 cn @ vue.runtime.esm.js:4219 insert @ vue.runtime.esm.js:3139 $ @ vue.runtime.esm.js:6346 (anonymous) @ vue.runtime.esm.js:6565 t._update @ vue.runtime.esm.js:3948 r @ vue.runtime.esm.js:4066 _n.get @ vue.runtime.esm.js:4479 _n.run @ vue.runtime.esm.js:4554 gn @ vue.runtime.esm.js:4310 (anonymous) @ vue.runtime.esm.js:1980 ie @ vue.runtime.esm.js:1906 socket.js:309 Socket error (state=connecting, id=3) socket.js:252 Socket 3 closed ContainerLogs.vue:286 Connect Error r {isTrusted: false}
  1. shell socket.js:86 WebSocket connection to 'ws://xxxxx:9898/api/v1/namespaces/default/pods/centos-test-d9b5b57b7-29r4t/exec?container=centos-x&stdout=1&stdin=1&stderr=1&tty=1&command=%2Fbin%2Fsh&command=-c&command=TERM%3Dxterm-256color%3B%20export%20TERM%3B%20%5B%20-x%20%2Fbin%2Fbash%20%5D%20%26%26%20(%5B%20-x%20%2Fusr%2Fbin%2Fscript%20%5D%20%26%26%20%2Fusr%2Fbin%2Fscript%20-q%20-c%20%22%2Fbin%2Fbash%22%20%2Fdev%2Fnull%20%7C%7C%20exec%20%2Fbin%2Fbash)%20%7C%7C%20exec%20%2Fbin%2Fsh&sockId=3' failed: value @ socket.js:86 (anonymous) @ ContainerShell.vue:232 d @ runtime.js:45 (anonymous) @ runtime.js:274 O.forEach.t. @ runtime.js:97 r @ asyncToGenerator.js:3 l @ asyncToGenerator.js:25 (anonymous) @ asyncToGenerator.js:32 (anonymous) @ asyncToGenerator.js:21 connect @ ContainerShell.vue:183 (anonymous) @ ContainerShell.vue:98 d @ runtime.js:45 (anonymous) @ runtime.js:274 O.forEach.t. @ runtime.js:97 r @ asyncToGenerator.js:3 l @ asyncToGenerator.js:25 socket.js:309 Socket error (state=connecting, id=3) socket.js:252 Socket 3 closed ContainerShell.vue:206 Connect Error r {isTrusted: false}

服务端日志: INFO[0002] Watching metadata for /v1, Kind=ResourceQuota INFO[0002] Watching metadata for apps/v1, Kind=ReplicaSet INFO[0002] Watching metadata for certificates.k8s.io/v1beta1, Kind=CertificateSigningRequest INFO[0002] Watching metadata for /v1, Kind=PersistentVolumeClaim INFO[0002] Watching metadata for /v1, Kind=Secret
INFO[0002] Watching metadata for /v1, Kind=PersistentVolume INFO[0002] Watching metadata for rbac.authorization.k8s.io/v1, Kind=ClusterRoleBinding ERRO[0011] Error during subscribe websocket: close sent ERRO[0011] Error during subscribe websocket: close sent ERRO[0366] Error during subscribe websocket: close sent ERRO[0366] Error during subscribe websocket: close sent ERRO[0483] Error during subscribe websocket: close sent ERRO[0483] Error during subscribe websocket: close sent

Linux 下操作: 命令行操作查看log, 执行shell 没问题

niusmallnan commented 3 years ago

你使用什么浏览器?

eager-yu commented 3 years ago

chrome

K8S 使用的是AWS的EKS

niusmallnan commented 3 years ago

@eager-yu 我不知道EKS有什么安全限制,但是我将kube-explorer作为Pod安装到EKS中,这些功能都可以使用。

git clone https://github.com/cnrancher/kube-explorer
cd kube-explorer/deploy/kubectl
kubectl create -f .
# edit svc type to NodePort
kubectl edit svc kube-explorer -n kube-system
# deployment使用的是latest镜像,如有必要你可以进行修改

确保安全组允许NodePort的端口访问,访问EKS对应节点的NodeIP+NodePort即可使用,对应的UI shell和logs功能可以使用。