Skip to content

ildar-shaimordanov/kubecli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Content

NAME

kubecli - extended control over Kubernetes

SYNOPSIS

kubecli [OPTIONS]
kubectl [OPTIONS]

DESCRIPTION

The kubecli project implements the extended management on Kubernetes.

Requirements

  • kubectl
  • sh
  • grep
  • awk

Installation

Download the .kubecli file from this repository and put it in the home directory. After that source it in .bashrc or in shell scripts where you'd like to add its functionality.

. ~/.kubecli

kubectl

It's wrapper function around the kubectl executable itself and possibly other launchers like minikube kubectl, k3s kubectl and rancher kubectl.

Other forms have been taken into account also because they are mentioned in the official documentations of each distribution.

kubecli

It's the real workhorse. It does everything what kubectl is able to do and also does a bit more. The following section describes extended commands supplied by kubecli.

A command is passed as the first argument. If the argument is recognized as the kubecli extended command, it is processed internally. Otherwise everything is passed to kubectl.

COMMANDS

help

Print brief usage.

kubecli help

man

Print full usage.

kubecli man

Note: this command is fully supported in BASH only.

names

List the entity names only: any of namespaces, pods, etc.

kubecli names NAME [OPTIONS]
kubectl get NAME [OPTIONS] -o name

Two examples above show two options how to achieve the same result with the new function and in the classical way.

labels

Collect the entities and reorder them against the labels they associated.

kubecli labels NAME [OPTIONS]
kubectl get NAME [OPTIONS] \
    --no-headers \
    -o custom-columns=NAMES:.metadata.name,LABELS:.metadata.labels

This command can be useful to recognize labels for selectors when needs come to define the pods for logging.

Besides that this command reorders the collected list putting the labels in the front of the associated list of pods and other entities.

tail

Display logs for selected entities.

kubecli tail [SELECTOR] [OPTIONS]
kubectl logs SELECTOR [OPTIONS]

It's definitely something useful: keep a namespace and pod selectors in KUBECLI_NS and KUBECLI_SEL, the environment variables and call this command to monitor pods' log messages.

grep

Print log lines matching GREP-OPTIONS.

kubecli grep [SELECTOR] [OPTIONS] -- GREP-OPTIONS
kubecli tail [SELECTOR] [OPTIONS] | grep GREP-OPTIONS
kubectl logs SELECTOR [OPTIONS] | grep GREP-OPTIONS

Take logs of pods specified by the selector and filter particular lines. If the KUBECLI_SEL variable is set and not empty, it is used implicitly.

It's syntactic sugar combining kubecli tail and grep. For more complex cases use kubecli tail with alternative grep-like tools or specify the KUBECLI_GREP variable.

Note: the -- parameter in the first command is mandatory because it separates arguments for kubectl and grep, respectively.

Note: this command is fully supported in BASH only.

ctx

Display, use or modify the context.

Display all contexts.

kubecli ctx -a [OPTIONS]
kubectl config get-contexts [OPTIONS]

Display the current context.

kubecli ctx [.]
kubectl config current-context

Use the context.

kubecli ctx NAME
kubectl config use-context NAME

Use the previous context (similar to cd - in shells).

kubecli ctx -
kubectl config use-context "$KUBECLI_OLDCTX"

Modify the context.

kubecli ctx .|NAME OPTIONS
kubectl config set-context --current OPTIONS
kubectl config set-context NAME OPTIONS

ENVIRONMENT

These variables are used by kubecli and kubectl. If one of them is declared and is not empty, it is used according to the explanations below.

KUBECLI_GREP

Enables an alternative command for filtering log lines. If not specified, grep is used.

KUBECLI_NS

Declares a namespace for invocation as kubectl -n "$KUBECLI_NS".

KUBECLI_SEL

Declares a selector for invocation as kubectl logs -l "$KUBECLI_SEL".

KUBECLI_SUDO

If required, declares the sudo command and optionally its parameters used to elevate privileges for kubectl. It can be useful when the command is executed under regular users. No needs to declare it for root.

At least one of the following examples is applicable for you (just specify the right path to the configuration file):

KUBECLI_SUDO=sudo
KUBECLI_SUDO='sudo -i'
KUBECLI_SUDO='sudo -E'
KUBECLI_SUDO='sudo -E bash -l'
KUBECLI_SUDO='sudo --preserve-env=KUBECONFIG'
KUBECLI_SUDO='sudo KUBECONFIG=/etc/kubernetes/admin.conf'

KUBECLI_OLDCTX

It is used to store the previously working context.

ASSOCIATIONS AND CULTURAL REFERENCES

Initially, when I started developing this project, one allusion has stuck in my mind - "Kin-dza-dza!", the famous movie and masterpiece by the Soviet producer Georgy Danelia. It is funny sci-fi, a bit humoristic, a bit satirical.

Events take place partially on our Earth and mostly on Plyuk, the alien planet. The Plyukanian language has the word koo /ku/ meaning any other word. It sounds like the first sillable of the kubectl word. And nothing more.

Later I realized that kubecli is good name for the project because it is CLI tool for kube (the short form of kubectl). In the other hand, kubecli /kubekli/ sounds almost like күбәләк /kʏbæ'læk/, the Tatar word meaning butterfly.

When development became closer to finish and was almost ready for publishing I re-read some facts about "Kin-dza-dza!". It recalled me another Plyukanian word, pepelats, meaning a spaceship. It's originated from the Georgian word პეპელა /'pepela/ that is translated as a butterfly.

So, the circle has closed! Koo!

REFERENCES

Kubectl commands

kubectl Cheat Sheet

Custom columns

JSONPath Support

SEE ALSO

Here is collection of links to other projects similar to this one or implementing more interesting features.

LICENSE

Copyright 2022, 2023 Ildar Shaimordanov

MIT License

Releases

No releases published

Packages

No packages published

Languages