Giter Club home page Giter Club logo

kubecui's Introduction

kubecui

kubeui makes kubectl more user friendly. This is still kubectl but enhanced with fzf.


I believe, anybody who is new to kubernetes, must use kubectl. Because kubectl is the basics.


However, kubectl slows you down - requires heavy keyboard typing. In order to alleviate interaction with kubernetes API and describe the fields associated with each supported API resource directly in the Terminal, kubectl was complemented by fzf.

Dependencies

Three modes

BASIC

In the basic mode you use only the k alias in your terminal window. You type commands like k get pod -A, k logs and others, do what you need to do, like search for pods, deployments, view the logs and so on. Every time you need to type a new command. This mode is what kubecui was made for. This mode makes work with kubectl a little easier.

NORMAL

Usually we work with more than one cluster. Every time in order to switch a context we type k config use-context command. It is a tedious and error prone process (you might deploy or delete something in the wrong context). In the NORMAL mode, we work with a simple interface which has 3 windows - dev,stg,prod. To switch between windows the Ctrl+b w shortcut is used. We still need to type commands, like being in BASIC mode, but we switch the context by switching the windows. k start activates the mode. The mode is avaliable if we install optional tmux and tmuxp packages The init.sh script creates a .tmuxp folder and copies the default.yaml file there. After that, you have to edit the file( ~/.tmuxp/default.yaml) and make sure that you use actual values instead of < ...abc... > When everything is ready execute k start

k start Pay attention to the red rectangle. These are your clusters. * next to cluster points to the active window/cluster.Key combinations you may find helpful:

  • Ctrl+b 1,2,3,n OR Ctrl+b w - switch between windows/clusters
    • windows
  • Ctrl+b d - exit multi-widow session
  • Ctrl+b [ - edit mode. You can move cursor, scroll up/down, select and copy text.
  • Ctrl+r - if you followed the installation instructions for fzf, most probably you use fzf to browse shell history. If you didn't, you should try, cause it is fun and makes your experience with kubecui more plesant.

DARK_SIDE

The most efficient and the most interactive mode. Requires minimum typing. Unfortunately this mode goes against the main concept of kubecui. You don't type commands, rather switch between windows and sessions. You enter this mode by executing k start. After k start initializes the environment you will be able to switch between sessions. Each session corresponds to a single context (dev,stage or prod). The shortcut for switching between sessions - Ctrl+b s. Each session has 10 windows(for pods, deployments, logs, ingresses, configmaps, secrets, services, PV, PVC and one empty window for any commands). Why are there 10 windows? To make it easier to switch between them. Quick switching - Ctrl+b number from 0-9. Or Ctrl+b w.

  • windows It pops up interface with windows list, use arrow keys to choose the window.

Docker

How to build and run kubecui (the darkside mode) using docker.

  1. kubectl must be installed on your laptop. Because kubecui must use the same version of it, inside a docker container.
  2. There are lines in the Dockerfile:
  RUN cp /root/kubecui/tmux-profiles/dev.yaml.init ~/.tmuxp/dev.yaml && sed -i 's/<KUBECONFIG_PATH>/"~\/\.kube\/dev\.yml"/g' ~/.tmuxp/dev.yaml
  RUN cp /root/kubecui/tmux-profiles/stg.yaml.init ~/.tmuxp/stg.yaml&& sed -i 's/<KUBECONFIG_PATH>/"~\/\.kube\/stg\.yml"/g' ~/.tmuxp/stg.yaml
  RUN cp /root/kubecui/tmux-profiles/prod.yaml.init ~/.tmuxp/prod.yaml&& sed -i 's/<KUBECONFIG_PATH>/"~\/\.kube\/prod\.yml"/g' ~/.tmuxp/prod.yaml

They add kubeconfig files path and name (~/.kube/dev.yml, ~/.kube/stg.yml, ~/.kube/prod.yml) to the kubecui config file (kubecui will search these particular file names). Later, you will mount kubeconfig directory from your laptop to a docker container -v <HOME_DIR_PATH>/.kube:/root/.kube, which means your's laptop /.kube/ directory must contain dev.yml, stg.yml, prod.yml. If you want to use different file names, instead of default ones, you must change them the Dockerfile sed -i 's/<KUBECONFIG_PATH>/"~\/\.kube\/BLA_BLA_SOME_NAME\.yml"/g'

  1. Build the image: docker build -t kubecui:latest .
  2. Run kubecui: docker run -it --rm --name kubecui -v <PATH>/kubectl:/usr/local/bin/kubectl -v <HOME_DIR_PATH>/.kube:/root/.kube kubecui:latest

IMPORTANT: For AWS EKS clusters you will additionally need -v <HOME_DIR_PATH>/.aws:/root/.aws

Installation

Dependencies

There is no script which leads you through the process of installation. This is done intentionally because usually tools like apt, snap, yum and so on, require root privileges, and we want the process to be transparent, at least at the earlier stage.

Clone the repo

kubecui

  • chmod +x kubecui.sh kui_start.sh

kubecui init

  • init.sh
  • source ~/.bashrc

If for some reason init.sh failed

BASIC mode

make sure that ~/.bashrc contains this line:

  • source /<PATH>/kubecui.sh

NORMAL mode

In addition to the line for BASIC mode, make sure that ~/.bashrc contains this line too:

  • export KUI_PATH="<the path to the directory where kui_start.sh is>

Also the ~/.tmuxp directory must exist and contain the default.yaml file. Remmember to update the file and replace < ...abc... > with actual values. Finally, check the kui_start.sh file and make sure that tmuxp load default line is uncommented and tmuxp load dev stg prod remains commented out

DARK-SIDE mode

All the same as for NORMAL mode but instead of default.yaml the directory ~/.tmuxp must contain three files instead:

  • dev.yaml
  • stg.yaml
  • prod.yaml

kui_start.sh. tmuxp load default is commented out. tmuxp load dev stg prod is uncommented

kui_start.sh

Every time you run k start it executes kui_start.sh. The script initializes the sessions. For example, if you work with AWS EKS and MFA is a part of the authentication process you can put an awsume command in the very beginning of the kui_start.sh.

SORRY.

I know that not all of you use bash. I really hope that you know how to do the same for other shells. At this moment I am not able to test kubecui for all the most popular shells like zsh.

From fzf README file:

Search syntax

Unless otherwise specified, fzf starts in "extended-search mode" where you can type in multiple search terms delimited by spaces. e.g. ^music .mp3$ sbtrkt !fire

Token Match type Description
sbtrkt fuzzy-match Items that matchsbtrkt
'wild exact-match (quoted) Items that includewild
^music prefix-exact-match Items that start withmusic
.mp3$ suffix-exact-match Items that end with.mp3
!fire inverse-exact-match Items that do not includefire
!^music inverse-prefix-exact-match Items that do not start withmusic
!.mp3$ inverse-suffix-exact-match Items that do not end with.mp3

Commands

Most probabaly you are falimiar with or already use k alias for kubectl. If so, you will be happy to hear, that kubecui is k alias in essence.

  • k get <OBJECT> k get pod
  • k logs k logs
  • k expain k expain
  • k explain <OBJECT> k explain pod k explain pod
  • k get events --all-namespaces
    • Get all events. sort by first and last seen
  • k config use-context
    • Singale panel. Switch between kubeconfig contexts
  • k config set ns
    • Singale panel. Set default namespace.
  • k start
    • starts cluster per window session
  • k stop
    • stop and clear session. Without stop next time you run k start it will suggest you to return to previous session

Additional materials

kubecui's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kalyann567

kubecui's Issues

k logs change view (Ctrl-/) results in "invalid memory address or nil pointer dereference"

Thanks for putting together a useful kubectl tool using fzf. I ran into an issue when I used k logs and tried to change the view using Ctrl-/. After two presses, when it tries to go 'full-screen' I get an error.

Steps to reproduce

  1. Set KUI_PATH to the directory with kubecui.sh
  2. Load kubecui.sh using source kubecui.sh
  3. Run k logs
  4. Press Ctrl-/ twice

Error message below, I had to clean it up because it was intermingled with the shell output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x68 pc=0x5772b4]                                                                                                                                                                                                                                                              
goroutine 24 [running]:                                                                                                                                                                                                                                       
github.com/junegunn/fzf/src.(*Terminal).Loop.func9.2(0x0?)
github.com/junegunn/fzf/src/terminal.go:3055 +0x714
github.com/junegunn/fzf/src/util.(*EventBox).Wait(0xc000012738, 0xc0000c9fa0)
github.com/junegunn/fzf/src/util/eventbox.go:34 +0x62
github.com/junegunn/fzf/src.(*Terminal).Loop.func9()l
github.com/junegunn/fzf/src/terminal.go:2978 +0xee
created by github.com/junegunn/fzf/src.(*Terminal).Loop in goroutine 8
github.com/junegunn/fzf/src/terminal.go:2962 +0x593

Lastly, I am using bash on Debian testing (trixie) version GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)

[F1]Explain results in error due to known option for yq/jq

Steps to reproduce:

  1. k get pods
  2. select a pod and press F1

Visible error message:

jq: Unknown option -o
                     Use jq --help for help with command-line options,
                                                                      or see the jq manpage, or online docs  at https://jqlang.github.io/jq

I also believe I see a "Broken pipe" error but it does not persist on screen.

My install of jq and yq on a Debian linux system are versions:

jq 1.7.1-3
yq 3.2.3.-1

Neither has option -o available.

I thought fx/libs/explain.sh, line 4 may be the culprit

EXPLAIN=$(kubectl explain ${RS_TYPE} --recursive | sed -r 's/FIELDS:/---/' | sed -n '\|---|,$p' | sed -r 's/(\w+)\t.*/\1:/g' | yq -o props -P . | sed -r 's/ =//g')

I tried removing the -o and -P options, so the line reads as follows:

EXPLAIN=$(kubectl explain ${RS_TYPE} --recursive | sed -r 's/FIELDS:/---/' | sed -n '\|---|,$p' | sed -r 's/(\w+)\t.*/\1:/g' | yq . | sed -r 's/ =//g')

Update: I forgot to source the kubecui.sh file after my change. After changing the EXPLAIN line 4, and removing the -o and -P, the F1 button for Explain "works". Although the results may not have been what you originally intended. Without knowing what these two options were suppose to do, I can't really figure out what the change in behavior is.

Let me know if there is anything else I can test to help determine the root cause of the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.