Skip to content

Commit

Permalink
修改readme
Browse files Browse the repository at this point in the history
  • Loading branch information
richie committed Apr 3, 2019
1 parent d0e6581 commit 8ccd5e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
# kubectl apply -f k8s-webshell-deployment.yaml
# kubectl apply -f k8s-webshell-svc.yaml
```
修改`doc/demo/client/index.html` 中的以下内容的ip修改为容器的nodePort ip:
修改`doc/demo/client/index.html` 中的以下内容的ip修改为容器的为域名(ssl证书为xx.com):
```javascript
ws = new WebSocket("ws://10.10.152.39:30001/api/ws?" + "podNs=" + podNs + "&podName=" + podName + "&containerName=" + containerName );
ws = new WebSocket("wss://xx.com:30001/api/ws?" + "token=" + wsToken);
```
然后打开index.html 就可以测试了

Expand All @@ -50,3 +50,30 @@ ws = new WebSocket("ws://10.10.152.39:30001/api/ws?" + "podNs=" + podNs + "&podN
```bash
docker-compose -f docker-compose.yaml up k8s-webshell -d
```

### 接口使用
调用`/auth`(POST方法)先获取token,参数如下:
```json
{
"secretKey":"ERkyNK2Q",
"paasUser":"zhuruiqing",
"podNs":"richie",
"podName":"my-nginx-f9995bdb6-jtr5k",
"containerName":"my-nginx"
}
```
参数说明:
```python
secretKey api认证secretKey
paasUser paas平台用户
podNs pod命名空间
podName pod名称
containerName 容器名称
```

### web页面调用k8s-webshell websocket接口
调用接口`/api/ws`其中token为 请求auth后获得的token:
`ws = new WebSocket("wss://xx.com:30001/api/ws?" + "token=" + wsToken);`

12 changes: 8 additions & 4 deletions doc/demo/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
</head>
<body>
<form>
<!--
namespace:<input type="text" id="podNs">
podName:<input type="text" id="podName">
containerName:<input type="text" id="containerName">
-->
wsToken:<input type="text" id="wsToken">
<input id="ssh" type="button" value="ssh">
</form>
<div id="terminal"></div>
Expand All @@ -34,12 +37,13 @@
// 取得输入焦点
term.focus();
// 获取要连接的容器信息
var podNs = document.getElementById("podNs").value
var podName = document.getElementById("podName").value
var containerName = document.getElementById("containerName").value
// var podNs = document.getElementById("podNs").value
// var podName = document.getElementById("podName").value
// var containerName = document.getElementById("containerName").value
var wsToken = document.getElementById("wsToken").value
// 连接websocket
// ws = new WebSocket("wss://k8s-webshell.finupgroup.com:7777/api/ws?" + "podNs=" + podNs + "&podName=" + podName + "&containerName=" + containerName + "&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiUGFzc3dvcmQiOiIxMjMiLCJleHAiOjE1NTQxMTgxMjUsImlzcyI6Ims4cy13ZWJzaGVsbCJ9.Dss1g9ZMflB_x0vkaK9GhRHYSZf2xek9VpfUeZaThL");
ws = new WebSocket("wss://k8s-webshell.finupgroup.com:30001/api/ws?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZWNyZXRrZXkiOiJFUmt5TksyUSIsIlBhYXNVc2VyIjoiemh1cnVpcWluZyIsInBvZE5zIjoicmljaGllIiwicG9kTmFtZSI6Im15LW5naW54LWY5OTk1YmRiNi1qdHI1ayIsImNvbnRhaW5lck5hbWUiOiJteS1uZ2lueCIsImV4cCI6MTU1NDMwNTIxNCwiaXNzIjoiazhzLXdlYnNoZWxsIn0.O2XkjFo_8aYeIOrXMgrYVw3zA-s4k7zbP3cvJC5MU54");
ws = new WebSocket("wss://k8s-webshell.finupgroup.com:30001/api/ws?" + "token=" + wsToken);
ws.onopen = function(event) {
// ws.send(JSON.stringify({'podNs':podNs, 'podName':podName, 'containerName':containerName, 'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiUGFzc3dvcmQiOiIxMjMiLCJleHAiOjE1NTQxMjI2MjQsImlzcyI6Ims4cy13ZWJzaGVsbCJ9.93CNsR7QeifmnV-MmPOYqp9n1jNaceLfyWujDSSFdMM'}))
console.log("onopen")
Expand Down

0 comments on commit 8ccd5e1

Please sign in to comment.