Skip to content

ohmystack/kubetool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

kt (kubetool)

Short-cut for many kubectl operations.

    __         __         __              __
   / /____  __/ /_  ___  / /_____  ____  / /
  / //_/ / / / __ \/ _ \/ __/ __ \/ __ \/ /
 / ,< / /_/ / /_/ /  __/ /_/ /_/ / /_/ / /
/_/|_|\__,_/_.___/\___/\__/\____/\____/_/

kt (kubetool)

Usage:
kt [-n <namespace>] [--all] <action>

Actions:
  ps <kind> [keyword]   | List or search resources
  get <kind> [keyword]  | Search and get a resource by a keyword
  desc <kind> [keyword] | Search and describe a resource by a keyword
  logs [-f] <keyword>   | Search and fetch the Pod's logs
  ssh <keyword>         | Enter the bash/sh of a Pod's container

Other actions:
  self-upgrade          | Upgrade "kubetool" to the latest version

Installation

INSTALL_DIR='/usr/local/bin'
sudo curl -o ${INSTALL_DIR}/kubetool https://raw.githubusercontent.com/ohmystack/kubetool/master/kubetool
sudo chmod a+x ${INSTALL_DIR}/kubetool
sudo ln -sf ${INSTALL_DIR}/kubetool ${INSTALL_DIR}/kt

You can use command-line kt or kubetool.

Upgrade:

$ sudo kt self-upgrade

Usage

kt ps : List + Search

Example:

# List all the pods
$ kt ps pod
# Search pods with keyword: hello
$ kt ps pod hello
# List other k8s kinds
$ kt ps deployment hello

kt get : Search + Get YAML

It will do the following steps:

  • Search resources by a kind and a keyword.
  • Choose one from the search result.
  • Get the resource in YAML format.

Example:

 $ kt get pod kube
  0) pod/kube-apiserver-docker-for-desktop
  1) pod/kube-controller-manager-docker-for-desktop
  2) pod/kube-dns-86f4d74b45-mqx2j
  3) pod/kube-proxy-dmd8p
  4) pod/kube-scheduler-docker-for-desktop
  5) pod/kubernetes-dashboard-7b9c7bc8c9-4kqxl
Please choose one. Enter the index number: 0
apiVersion: v1
kind: Pod
metadata:
  annotations:
  ...

kt desc : Search + Describe

Similar with kt get, but it shows in a kubectl describe format.

Example:

 $ kt desc deployment kube

kt logs : Search + Logs

It will do the following steps:

  • Search pods by a keyword.
  • Choose the pod from the search result.
  • If there are multiple containers in that Pod, choose the container.
  • Fetch the logs.

Example:

$ kt logs kube
  0) pod/kube-apiserver-docker-for-desktop
  1) pod/kube-controller-manager-docker-for-desktop
  2) pod/kube-dns-86f4d74b45-mqx2j
  3) pod/kube-proxy-dmd8p
  4) pod/kube-scheduler-docker-for-desktop
  5) pod/kubernetes-dashboard-7b9c7bc8c9-4kqxl
Please choose one. Enter the index number: 2
  0) kubedns
  1) dnsmasq
  2) sidecar
Multiple containers in this Pod. Please choose one. Enter the index number: 0
I0219 06:50:04.383374       1 dns.go:48] version: 1.14.8
I0219 06:50:04.386396       1 server.go:71] Using configuration read from directory: /kube-dns-config with period 10s
I0219 06:50:04.387241       1 server.go:119] FLAG: --alsologtostderr="false"
I0219 06:50:04.387289       1 server.go:119] FLAG: --config-dir="/kube-dns-config"
...

kt ssh : Search + Enter into the Pod's container

It will do the following steps:

  • Search pods by a keyword.
  • Choose the pod from the search result.
  • If there are multiple containers in that Pod, choose the container.
  • Enter the container using kubectl exec -it <pod> -c <container> /bin/bash

Example:

$ kt ssh hello

Development

If you have any good ideas about kubetool, welcome to submit your PRs.

One simple rule: Keep this kubetool a single file bash program.

@ohmystack


About

Short-cut for many kubectl operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages