您好,登录后才能下订单哦!
本篇文章为大家展示了Web应用中GoTTY终端工具的安装以及用法,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
GoTTY 是一个简单的命令行工具,可将您的 CLI 工具变成 Web 应用。
# Mac 版 brew install yudai/gotty/gotty
如果你有 GO 的环境,也可以通过如下方式安装:
go get github.com/yudai/gotty
Usage: gotty [options] <command> [<arguments...>]
options
--address value, -a value IP address to listen (default: "0.0.0.0") [$GOTTY_ADDRESS] --port value, -p value Port number to liten (default: "8080") [$GOTTY_PORT] --permit-write, -w Permit clients to write to the TTY (BE CAREFUL) [$GOTTY_PERMIT_WRITE] --credential value, -c value Credential for Basic Authentication (ex: user:pass, default disabled) [$GOTTY_CREDENTIAL] --random-url, -r Add a random string to the URL [$GOTTY_RANDOM_URL] --random-url-length value Random URL length (default: 8) [$GOTTY_RANDOM_URL_LENGTH] --tls, -t Enable TLS/SSL [$GOTTY_TLS] --tls-crt value TLS/SSL certificate file path (default: "~/.gotty.crt") [$GOTTY_TLS_CRT] --tls-key value TLS/SSL key file path (default: "~/.gotty.key") [$GOTTY_TLS_KEY] --tls-ca-crt value TLS/SSL CA certificate file for client certifications (default: "~/.gotty.ca.crt") [$GOTTY_TLS_CA_CRT] --index value Custom index.html file [$GOTTY_INDEX] --title-format value Title format of browser window (default: "{{ .command }}@{{ .hostname }}") [$GOTTY_TITLE_FORMAT] --reconnect Enable reconnection [$GOTTY_RECONNECT] --reconnect-time value Time to reconnect (default: 10) [$GOTTY_RECONNECT_TIME] --max-connection value Maximum connection to gotty (default: 0) [$GOTTY_MAX_CONNECTION] --once Accept only one client and exit on disconnection [$GOTTY_ONCE] --timeout value Timeout seconds for waiting a client(0 to disable) (default: 0) [$GOTTY_TIMEOUT] --permit-arguments Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB) [$GOTTY_PERMIT_ARGUMENTS] --width value Static width of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_WIDTH] --height value Static height of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_HEIGHT] --ws-origin value A regular expression that matches origin URLs to be accepted by WebSocket. No cross origin requests are acceptable by default [$GOTTY_WS_ORIGIN] --term value Terminal name to use on the browser, one of xterm or hterm. (default: "xterm") [$GOTTY_TERM] --close-signal value Signal sent to the command process when gotty close it (default: SIGHUP) (default: 1) [$GOTTY_CLOSE_SIGNAL] --close-timeout value Time in seconds to force kill process after client is disconnected (default: -1) (default: -1) [$GOTTY_CLOSE_TIMEOUT] --config value Config file path (default: "~/.gotty") [$GOTTY_CONFIG] --version, -v print the version
3、实践
# 示例 gotty -w python3
访问 http://127.0.0.1:8080 即可在线体验 Python3 环境。
容器化时代,遇到一些问题的时候,会进入容器内部排查问题,依靠命令行确实可以解决,但是效率较低,如果将容器作为 Web 可访问的应用,那么处理问题就会便捷很多。
下面将介绍如何使用 GoTTY 连接 k8s 集群中的任意容器。
已构建好的镜像:registry.cn-beijing.aliyuncs.com/tlab/k8s-gotty:latest
gotty:可运行的 gotty 程序,查看 [Releases]列表,选择合适的
kubernetes.repo:用于下载 kubectl
[kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
Dockerfile:用于构建镜像
FROM centos:latest RUN yum install -y epel-release kde-l10n-Chinese glibc-common wget RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 ENV LC_ALL zh_CN.utf8 ADD gotty /root/ ADD kubernetes.repo /etc/yum.repos.d/ RUN yum -y install kubectl WORKDIR /root EXPOSE 8080 CMD ["./gotty", "-w", "--permit-arguments", "kubectl", "exec", "-it", "-n"]
kind: Deployment apiVersion: apps/v1 metadata: name: gotty namespace: default spec: replicas: 1 selector: matchLabels: k8s-app: gotty template: metadata: labels: k8s-app: gotty spec: serviceAccountName: <此处填具有合适权限的k8s用户名> containers: - name: gotty image: registry.cn-beijing.aliyuncs.com/tlab/k8s-gotty ports: - containerPort: 8080 protocol: TCP
kind: Service apiVersion: v1 metadata: labels: k8s-app: gotty name: gotty-service namespace: default spec: ports: - port: 80 targetPort: 8080 nodePort: 38080 selector: k8s-app: gotty type: NodePort
在终端里,进入容器的命令是:
kubectl exec -it -n <Namespace> <PodName>
那么,利用 GoTTY 访问则是 http://<ip>:38080/?arg=<Namespace>&arg=<PodName>
上述内容就是Web应用中GoTTY终端工具的安装以及用法,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。