terminal

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

Kuberntes web terminal

more imformations of terminal

Create a terminal

clent                     terminal                        terminal-pod
  | {"User", "Token"}        |                                |
  |------------------------->|create a service and deployment |
  |                          |                                |
  |                          |------------------------------->| pod ENVS: kubernetes APIserver IP
  |                          |                                |           User token
  |                          |                                |           Namespace
  |                          |                                |           User name
  | { terminalID,            |                                |           Terminelid
  | EndPoint:"ip:port"}      |      terminal IP:port          | pod Label: LastHeartbeat, time.Now - LastKeepalived > 10, kill it          
  |<-------------------------|<-------------------------------|           

How to stop a terminal container

clent                     terminal                        terminal-pod
  | heartbeat (5min)         |                                |
  |------------------------->|update deployment LastHeartbeat |
  |                          |                                |
  |                          |------------------------------->| 
  |                          |                                | 
  |                          |                                | 
  |                          | loop check LastHeartbeat       | 
  |                          |------------------------------->| 
  |                          | if timeout delete deployment   |          
  |                          | and service                    |           

Quick start

Using the http server

Install

terminal is sub module of fist, if you already install fist, needn't install this again.

cd terminal/deploy
kubectl create ns sealyun
kubectl create -f rbac.yaml
kubectl create -f deploy.yaml

env of deploy

name type defaults Description
MY_NAMESPACE string "sealyun" the deployment of k8s namespace
MY_SA_NAME string "admin" the service account name of terminal

get fist terminal cluster ip

[root@iZj6cegflzze2l7fpcqoerZ deploy]# kubectl get svc -n sealyun
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
fist-terminal   NodePort    10.99.162.142   <none>        8080:31857/TCP   17m
Create a terminal

Create a terminal from POST, it will return the webterminal NodePort

  • Use user token access webterminal
    curl -H "Content-Type:application/json" -d '{"User":"fanux", "UserToken":"eyJhbGciOiJSUzI1NiIsImtpZCI6IkNnYzRPVEV5TlRVM0VnWm5hWFJvZFdJIn0.eyJpc3MiOiJodHRwczovL2Zpc3Quc2VhbHl1bi5zdmMuY2x1c3Rlci5sb2NhbDo4MDgwIiwic3ViIjoiQ2djNE9URXlOVFUzRWdabmFYUm9kV0kiLCJhdWQiOiJzZWFseXVuLWZpc3QiLCJleHAiOjE1NTE3MTgzMTgsImlhdCI6MTU1MTM1ODMxOCwiZW1haWwiOiJmaHRqb2JAaG90bWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZ3JvdXBzIjpbImRldiIsInRlc3QiXSwibmFtZSI6ImZhbnV4In0.N8YjE5CqhpPHbtpmNxWIuyIii-VD4vYf8i_JfWpwvJ68SB5JbUM1PN-nXH8xU_biyAB5P1ehNKer2ciMfVA45hyDedzkb6E4A-6B0ezMhU-OL9pCdleq2cJma2R3g64i0YybtQuoOS56kS0isbbmx2NDcL_fluMRdZRPS0Zbx5Pu8CBb60ChXj8r7-zkYuzPFkO1UBi99a3QHR9jBpXz2vBQMjqTPcGddaeUpKP6r80Ib4K9whF3U4rH5gNEOGwgMTe_V4PnEdQ3JbIIiqNJPqIisgxT_HBUqIzHtY3Vsxkjzr2Sj5v0ZWV-gYnZr1ib1bM1uXGK4VOebA5DLbCYaw", "Namespace":"default"}' \
    http://10.99.162.142:8080/terminal
    
  • User admin token access webterminal
    curl -H "Content-Type:application/json" -d '{"WithoutToken": true}' http://10.99.162.142:8080/terminal
    

OR you can get terminal endpoint in sealyun-tty namespace:

[root@iZj6cegflzze2l7fpcqoerZ deploy]# kubectl get svc -n sealyun-tty
NAME                               TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
bc5aaf70741d41c0b4011ebfe7a70f52   NodePort   10.98.60.90   <none>        8080:32219/TCP   16m

Using http://IP:32219

classpath of terminal
name type defaults Description
User string "" user name of k8s cluster , when WithoutToken is false
UserToken string "" user token of k8s cluster , when WithoutToken is false
Apiserver string "https://kubernetes.default.svc.cluster.local:443" web-termianl controll k8s cluster,k8s apiserver address
Namespace string "default" default controller k8s cluster namespace
WithoutToken bool false without user token access k8s
TTYKubeImage string "fanux/fist-tty-tools:v1.0.0" default of tty images

Using bare docker image

imageList:

  • fanux/kube-ttyd:latest : only has kubectl and tty
  • fanux/fist-tty-tools:v1.0.0 : include golang dev environment, full vim plugins, and vim kubernetes plugins
docker run -d --net=host -e APISERVER="https://172.31.12.61:6443" -e USER_TOKEN="XX" -e NAMESPACE="default" -e USER_NAME=fanux -e TERMINAL_ID="uuid" fanux/kube-ttyd:latest

Access to :

http://yourip:8080

OR if you want mount the kubeconfig file instead to use user token:

docker run -d --net=host -v /root/.kube/config:/root/.kube/config fanux/kube-ttyd:latest ttyd -p 8080 bash

How to using the terminal

  • Ctrl g complete k8s yaml file
  • zm fold or unfold code
  • Ctrl n open code dir
  • ,t open function or structs list
  • Ctrl h swith window (Ctrl h Ctrl J Ctrl K Ctrl L)
  • ,dt go to defination

Documentation

Index

Constants

View Source
const (
	DefaultTTYnameapace = "sealyun-tty"
	DefaultApiserver    = "https://kubernetes.default.svc.cluster.local:443" //or https://10.96.0.1:443
	DefaultKubeTTYimage = "fanux/fist-tty-tools:v1.0.0"
	DefaultPrefix       = "tid-"
	ClassPathNamespace  = "MY_NAMESPACE"
	ServiceAccountName  = "MY_SA_NAME"

	DefaultNamespace      = "sealyun"
	DefaultServiceAccount = "admin"
)

consts

Variables

View Source
var (
	DefaultTTYDeployReplicas = int32(1)
)

vars

View Source
var (
	//TerminalPort is cmd port param
	TerminalPort uint16
)

Functions

func CreateTTYcontainer

func CreateTTYcontainer(t *Terminal) error

CreateTTYcontainer is

func CreateTTYdeploy

func CreateTTYdeploy(t *Terminal) error

CreateTTYdeploy create deployment

func CreateTTYservice

func CreateTTYservice(t *Terminal) error

CreateTTYservice tty service

func LoadTerminalID

func LoadTerminalID() error

LoadTerminalID is

func Register

func Register(container *restful.Container)

Register is

func Serve

func Serve()

Serve start a terminal server

Types

type Heartbeater

type Heartbeater interface {
	//terminal deployment is in sealyun-tty namespace
	UpdateTimestamp() error
	//need delete deployment and service in sealyun-tty if it timeout
	CleanTerminalJob() error
}

Heartbeater is

func NewHeartbeater

func NewHeartbeater(tid string, namespace string) Heartbeater

NewHeartbeater is

type Terminal

type Terminal struct {
	//input field
	User         string `json:"user,omitempty"`
	UserToken    string `json:"userToken,omitempty"`
	Apiserver    string `json:"apiServer,omitempty"`    // just using default apiserver
	Namespace    string `json:"namespace,omitempty"`    // the kubeconfig default context namespace
	WithoutToken bool   `json:"withoutToken,omitempty"` // if true, mount the kubeconfig file, using ttyd instead the start-terminal.sh
	TTYKubeImage string `json:"ttyKubeImage,omitempty"` //default is  "fanux/fist-tty-tools:v1.0.0"

	//output append field
	TerminalID string `json:"terminalID,omitempty"`
	EndPoint   string `json:"endPoint,omitempty"`
}

Terminal is

func (*Terminal) Create

func (t *Terminal) Create() error

Create a terminal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL