解决kubectl exec terminal size问题

贵贵的博客 ( http://blog.linuxphp.org/ ) :

kubectl exec 进入容器,shell窗口很小,不方便,导致gotty窗口也很小,有时用打开开发者工具来解决,有的机器好像还解决不了。今天测试出另一个方案

https://stackoverflow.com/questions/30841921/kubernetes-kubectl-exec-bash-session-drop-and-line-width/30842198

在bash前添加 env COLUMNS=$COLUMNS LINES=$LINES

示例 kubectl exec -ti busybox -- env COLUMNS=$COLUMNS LINES=$LINES bash

 

由于我这里要通过非窗口程序创建,所以上面变量为空的,我手动指定为固定值

kubectl exec -ti busybox -- env COLUMNS=210 LINES=60 bash

 

指定行列后,窗口大小必须一致才正常显示,修改gotty程序将大小也固定,

git diff resources/index.html
diff --git a/resources/index.html b/resources/index.html
index 5212a47..f0b0632 100644
--- a/resources/index.html
+++ b/resources/index.html
@@ -2,7 +2,7 @@
 <html>
   <head>
     <title>GoTTY</title>
-    <style>body, #terminal {position: absolute; height: 100%; width: 100%; margin: 0px;}</style>
+    <style>body, #terminal {position: absolute; height: 720px; width: 1280px; margin: 0px;}</style>
     <link rel="icon" type="image/png" href="favicon.png">
   </head>
   <body>

重新对gotty进行打包,测试正常

 

另:https://coderwall.com/p/qtk07q/fix-terminal-rows-columns-and-type-when-using-old-versions-of-kubectl-exec

文章来源:

Author:linuxphp@qq.com(keminar)
link:http://blog.linuxphp.org/archives/1658/