K8s Pod exec via sockJS, webSocket disconnects after I enter any character, what should I do?

Viewed 65

K8s Pod exec via sockJS, webSocket disconnects after I enter any character? I tried to use xtrem combined with sockjs to connect to kubernetes to execute the command, I got an error 1: "Process exited", it was sent immediately after I entered the command

    const term = new Terminal({
      rendererType: 'canvas',
      cursorBlink: true,
      cursorStyle: "underline",
      convertEol: true,
      allowTransparency: true,
      fontFamily: 'operator mono,SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace',
      fontSize: 15,
      disableStdin: false,
      scrollback: 10000,
      tabStopWidth: 8,
      bellStyle: "sound",
      rightClickSelectsWord: true,
      row: 42,
      cols: 188,
      rows: 42,

      theme: {
        foreground: "white",
        background: "#060101",
        cursor: "help",
      }
    })
    const webLinksPlugin = new WebLinksAddon();
    const SearchPlugin = new SearchAddon();
    const fitAddon = new FitAddon();
    term.loadAddon(fitAddon)
    term.loadAddon(webLinksPlugin);
    term.loadAddon(SearchPlugin);


    const webssh = (sessionId) => {
      const ws = new SockJS(`http://localhost:88/api/v1/ws/podssh/podssh?${sessionId}`);
      const attachAddon = new AttachAddon(ws);
      term.loadAddon(attachAddon);
      term.open(document.getElementById('terminal'));

      ws.onopen = function (e) {
        term.writeln("connection...");
        setTimeout(() => ws.send(JSON.stringify({Op: 'bind', SessionID: sessionId})), 500)
      }
      term.onData(function (str) {
        ws.send(JSON.stringify({'Op': 'stdin', 'Data': str, SessionID: sessionId}));
        term.write(str)
      });

      ws.onmessage = function (e) {
        let msg = JSON.parse(e.data);
        switch (msg['Op']) {
          case 'stdout':
            console.log("stdout----", msg['Data'])
            term.write(msg['Data']);
            break;
          case 'toast':
            // message.info(msg['Data']);
            console.log(msg['Data'])
            break;
          default:
            term.writeln('Unexpected message type:', msg);
        }

      };
      ws.onclose = function (e) {
        console.log("web_console on close: ", e)
      }

    }

I'm not sure where is the problem, please help me? enter image description here

E0105 15:24:44.459965   20696 v2.go:105] invalid character 'w' looking for beginning of value
0 Answers
Related