Turn Your CLI into a Web App with GoTTY: Quick Start and Kubernetes Deployment
This guide introduces GoTTY, a tool that converts command-line programs into web applications, covering installation, basic usage, and advanced deployment inside Kubernetes using Docker images and service exposure.
GoTTY is a simple command-line tool that turns your CLI into a web application.
Quick Start
1. Install GoTTY
# Mac version
brew install yudai/gotty/gottyIf you have a Go environment, you can also install via:
go get github.com/yudai/gotty2. GoTTY Usage
Usage: gotty [options] <command> [<arguments...>]options
--address value, -a value IP address to listen (default "0.0.0.0")
--port value, -p value Port number to listen (default "8080")
--permit-write, -w Permit clients to write to the TTY (BE CAREFUL)
--credential value, -c value Credential for Basic Authentication (e.g., user:pass)
--random-url, -r Add a random string to the URL
--random-url-length value Random URL length (default 8)
--tls, -t Enable TLS/SSL
--tls-crt value TLS/SSL certificate file path (default "~/.gotty.crt")
--tls-key value TLS/SSL key file path (default "~/.gotty.key")
--tls-ca-crt value TLS/SSL CA certificate file (default "~/.gotty.ca.crt")
--index value Custom index.html file
--title-format value Title format of browser window (default "{{ .command }}@{{ .hostname }}")
--reconnect Enable reconnection
--reconnect-time value Time to reconnect (default 10)
--max-connection value Maximum connections (default 0)
--once Accept only one client and exit on disconnect
--timeout value Timeout seconds for waiting a client (0 to disable)
--permit-arguments Permit clients to send command line arguments in URL
--width value Static width of the screen (0 means dynamic)
--height value Static height of the screen (0 means dynamic)
--ws-origin value Regular expression that matches origin URLs for WebSocket
--term value Terminal name to use on the browser (default "xterm")
--close-signal value Signal sent to the command process when GoTTY closes (default SIGHUP)
--close-timeout value Time in seconds to force kill process after client disconnects (default -1)
--config value Config file path (default "~/.gotty")
--version, -v Print the version3. Example
# Example
gotty -w python3Visit http://127.0.0.1:8080 to experience an online Python3 environment.
Advanced: Using GoTTY in Kubernetes
In the container era, troubleshooting inside containers via CLI can be inefficient; exposing containers as web‑accessible applications simplifies the process.
This section shows how to connect GoTTY to any container in a k8s cluster.
1. Build GoTTY Docker Image
Pre‑built image:
registry.cn-beijing.aliyuncs.com/tlab/k8s-gotty:latest gotty: executable to run; see the Releases page for the appropriate version. kubernetes.repo: repository file for downloading 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: used to build the image.
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"]2. Deploy GoTTY in the k8s Cluster
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: <service-account-with-permissions>
containers:
- name: gotty
image: registry.cn-beijing.aliyuncs.com/tlab/k8s-gotty
ports:
- containerPort: 8080
protocol: TCP3. Expose GoTTY Service
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: NodePort4. Access the Container
To exec into a container via kubectl: kubectl exec -it -n <Namespace> <PodName> Using GoTTY, access it through:
http://<ip>:38080/?arg=<Namespace>&arg=<PodName>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
