<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          GoTTY - 終端工具變?yōu)?Web 應(yīng)用

          共 8917字,需瀏覽 18分鐘

           ·

          2021-05-09 20:12

          GoTTY 是一個簡單的命令行工具,可將您的 CLI 工具變成 Web 應(yīng)用。

          快速入門

          1、安裝 GoTTY

          # Mac 版
          brew install yudai/gotty/gotty

          如果你有 GO 的環(huán)境,也可以通過如下方式安裝:

          go get github.com/yudai/gotty

          2、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 環(huán)境。

          進(jìn)階篇

          容器化時代,遇到一些問題的時候,會進(jìn)入容器內(nèi)部排查問題,依靠命令行確實可以解決,但是效率較低,如果將容器作為 Web 可訪問的應(yīng)用,那么處理問題就會便捷很多。

          下面將介紹如何使用 GoTTY 連接 k8s 集群中的任意容器。

          1、構(gòu)建 GoTTY Docker 鏡像

          已構(gòu)建好的鏡像: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:用于構(gòu)建鏡像
          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、在 k8s 集群中運行 GoTTY

          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: <此處填具有合適權(quán)限的k8s用戶名>
                containers:
                  - name: gotty
                    image: registry.cn-beijing.aliyuncs.com/tlab/k8s-gotty

                    ports:
                      - containerPort: 8080
                        protocol: TCP

          3、暴露 GoTTY 服務(wù)

          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

          4、訪問容器

          在終端里,進(jìn)入容器的命令是:

          kubectl exec -it -n <Namespace> <PodName>

          那么,利用 GoTTY 訪問則是 http://<ip>:38080/?arg=<Namespace>&arg=<PodName>

          原文轉(zhuǎn)載:https://www.jianshu.com/p/dbeb35ff437d

          (版權(quán)歸原作者所有,侵刪) 


          點擊下方“閱讀原文”查看更多

          瀏覽 145
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  黄色三级片免费网站 | 肏屄视频在线播放 | 男人的天堂在线 | 日本a片一道免费观看 | 日韩毛片在线 |