Kubernetes cluster management tool K9s

Time:2022-1-3

Kubernetes cluster management tool K9s

Generally, after deploying k8s clusters, we either use kubectl command for cluster management or use bashroad’s UI management interface to manage clusters. Recently, we found a terminal based and easy-to-use project that allows us to quickly view, navigate, observe and solve some problems in our daily use of kubernetes. This is the K9s project (some related introductions in the previous article:7 tools to easily manage kubernetes clusters)。

Kubernetes cluster management tool K9s

Tool introduction

You who use the terminal everyday can be described as a sharp weapon!

K9s is a full screen terminal UI management tool based on curves. It can interact with kubernetes cluster, observe system resources, switch between various resources, check lists, logs, monitor events and execute pod, so as to ensure that the desktop space will not be occupied by a large number of terminal panes.

K9s monitors kubernetes resources at specific time intervals, which is 2 seconds by default, and allows you to view the content in your own cluster. It provides a visual view of running pods, logs, and deployments at a glance, as well as quick access to the shell. The following are the main features of the tool:

  • Information is within reach
  • Tracks the real-time activity of resources running in the kubernetes cluster
  • Handle kubernetes standard resources and custom resource definitions
  • Cluster index
  • Track real-time metrics associated with resources such as pod, container and node
  • Advanced features
  • Provide standard cluster management commands, such as logging, expansion, port forwarding, and restart
  • Define your own command shortcuts to quickly navigate through command aliases and hotkeys
  • The plug-in extension K9s is supported to create its own cluster operation management commands
  • Powerful filtering mode that allows users to drill down and view workload related resources
  • The appearance can be customized
  • Define your appearance through K9s skin
  • Customize / schedule columns to display by resource

Pulses – top level dashboard for cluster transaction status

Kubernetes cluster management tool K9s

Xray mining cluster resources and viewing their dependencies

Kubernetes cluster management tool K9s

Pods – lists your pods status and resource consumption

Kubernetes cluster management tool K9s

Logs – view and interact with container logs

Kubernetes cluster management tool K9s

RBAC – view the authorized users, methods, etc. on your cluster

Kubernetes cluster management tool K9s

install

The installation is relatively simple, but awesome.

K9s is developed in go language and can run on Linux, MacOS and windows platforms. K9s installation is very simple. The official has provided us with binary installation packages for various platforms. Just download the corresponding version.

MacOS

# Homebrew
$ brew install derailed/k9s/k9s

Linux

# LinuxBrew
$ brew install derailed/k9s/k9s
# PacMan
$ pacman -S k9s

Build

# Clone the repo
$ git clone https://github.com/derailed/k9s.git
# Build and run the executable
$ make build && ./execs/k9s

Docker

#Specify k8s the path to the configuration file
$ docker run --rm -it -v $KUBECONFIG:/root/.kube/config derailed/k9s
#Default path for k8s configuration file
$ docker run --rm -it -v ~/.kube/config:/root/.kube/config derailed/k9s

Mode of use

K9s and dashboard can be understood as the relationship between vim and idea!

K9s comes with some parameters, which can be used to start the tool with different configurations. For example, you need to see pod related information.

Command line startup parameters

#Lists all available cli options
$ k9s help
#Get information about the K9s runtime
$ k9s info
$ k9s info logs
$ k9s info configs
#Run in the given namespace
$ k9s -n mycoolns
#Run K9s to start in the pod view
$ k9s -c pod
#Start K9s in read-only mode; This mode disables all modification commands
$ k9s --readonly

Operation shortcut keyKubernetes cluster management tool K9sKubernetes cluster management tool K9s

Simple use

Mainly demonstrates the effect of some common command parameters!

After startup, a text-based user interface will pop up K9s. If no namespace flag is specified, it will show you the pod in the default namespace. With shortcut keys to navigate K9s, you can use the arrow keys and enter keys to select the listed items at any time. You may notice that K9s is set to use VIM command keys, including J and K keys to move up and down, etc.

  • k9s
0: # show all # pods in all namespaces
d: # describe the selected pod
l: # displays the log of the selected # pod #
y: # view yaml file
e: # edit yaml file
d: # view key mapping description
: SVC: # jump to service view
: deploy: # jump to deployment view
: namespace: # jump to namespace view
: CJ: # jump to the cronjob view to see which jobs are scheduled in the cluster
: RB: # jump to role binding view for role-based access control (RBAC) management

Kubernetes cluster management tool K9s

  • k9s info

Running this command will tell us where the application is looking for its configuration file.

$ k9s info
 ____  __.________
|    |/ _/   __   ______
|      < ____    /  ___/
|    |     /    /___ 
|____|__  /____//____  >
        /            /
Configuration:   /Users/jess/.k9s/config.yml
Logs:            /var/folders/5l/xxx/T/k9s-jess.log
Screen Dumps:    /var/folders/5l/xxx/T/k9s-screens-jess
#View K9s's log
$ tail -f /var/folders/5l/xxx/T/k9s-jess.log
#Enter K9s the debugging mode
$ k9s -l debug
  • k9s -n namespace

By specifying the namespace, we can focus on a given namespace.

Kubernetes cluster management tool K9s

configuration file

The above default methods are mainly defined in the configuration file

K9s saves its configuration in the home directory $home / In K9s K9s directory. The main configuration file name is config YML and store various K9s special positions. K9s updates this file to store the current view and namespace information.

# config.yml
k9s:
  # Represents ui poll intervals. Default 2secs
  refreshRate: 2
  # Set to true to hide K9s header. Default false
  headless: false
  # Indicates whether modification commands like delete/kill/edit are disabled. Default is false
  readOnly: false
  # Toggles icons display as not all terminal support these chars.
  noIcons: false
  # Logs configuration
  logger:
    # Defines the number of lines to return. Default 100
    tail: 200
    # Defines the total number of log lines to allow in the view. Default 1000
    buffer: 500
    # Represents how far to go back in the log timeline in seconds. Default is 5min
    sinceSeconds: 300
    # Go full screen while displaying logs. Default false
    fullScreenLogs: false
    # Toggles log line wrap. Default false
    textWrap: false
    # Toggles log line timestamp info. Default false
    showTime: false
  # Indicates the current kube context. Defaults to current context
  currentContext: minikube
  # Indicates the current kube cluster. Defaults to current context cluster
  currentCluster: minikube
  # Persists per cluster preferences for favorite namespaces and view.
  clusters:
    cooln:
      namespace:
        active: coolio
        favorites:
          - cassandra
          - default
      view:
        active: po
      featureGates:
        # Toggles nodeshell support. Allow K9s to shell into nodes if needed. Default false.
        nodeShell: false
      # Provide shell pod customization of feature gate is enabled
      shellPod:
        # The shell pod image to use.
        image: killerAdmin
        # The namespace to launch to shell pod into.
        namespace: fred
        # The resource limit to set on the shell pod.
        limits:
          cpu: 100m
          memory: 100Mi
      # The IP Address to use when launching a port-forward.
      portForwardAddress: 1.2.3.4
    minikube:
      namespace:
        active: all
        favorites:
          - all
          - kube-system
          - default
      view:
        active: dp

Summary description

It is very helpful for the operation and maintenance personnel who often need to operate k8s in daily life!

In addition to the above functions, K9s there are other practical functions, such as supporting self built command aliases, user-defined hotkey methods, user-defined plug-ins, user-defined terminal interface display, and resource display sequence and combination. In the official website, some simple examples and configuration methods are given, which can be basically done. After reading them, you can DIY by yourself.

It is important to understand your tools and master the “hard truth” of doing things. It is also important to remember that in terms of management, it is important to work smarter, not harder. Using K9s is the way I practice this goal.

Author: Escape
Link:https://www.escapelife.site/p…

Kubernetes cluster management tool K9s

Recommended Today

Vue2 technology finishing 3 – Advanced chapter – update completed

3. Advanced chapter preface Links to basic chapters:https://www.cnblogs.com/xiegongzi/p/15782921.html Link to component development:https://www.cnblogs.com/xiegongzi/p/15823605.html 3.1. Custom events of components 3.1.1. Binding custom events There are two implementation methods here: one is to use v-on with vuecomponent$ Emit implementation [PS: this method is a little similar to passing from child to parent]; The other is to use ref […]