From 8ccd5e13cac691faac8e793e4667a42fa61bd5b4 Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 3 Apr 2019 21:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 31 +++++++++++++++++++++++++++++-- doc/demo/client/index.html | 12 ++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0362bc1..d481c8d 100644 --- a/README.md +++ b/README.md @@ -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 就可以测试了 @@ -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);` + diff --git a/doc/demo/client/index.html b/doc/demo/client/index.html index 29e4e8e..64d0912 100644 --- a/doc/demo/client/index.html +++ b/doc/demo/client/index.html @@ -10,9 +10,12 @@
+ + wsToken:
@@ -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")