- NAME
- SYNOPSIS
- DESCRIPTION
- COMMANDS
- ENVIRONMENT
- ASSOCIATIONS AND CULTURAL REFERENCES
- REFERENCES
- SEE ALSO
- LICENSE
kubecli
- extended control over Kubernetes
kubecli [OPTIONS]
kubectl [OPTIONS]
The kubecli
project implements the extended management on Kubernetes.
- kubectl
- sh
- grep
- awk
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
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.
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
.
Print brief usage.
kubecli help
Print full usage.
kubecli man
Note: this command is fully supported in BASH only.
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.
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.
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.
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.
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
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.
Enables an alternative command for filtering log lines. If not
specified, grep
is used.
Declares a namespace for invocation as kubectl -n "$KUBECLI_NS"
.
Declares a selector for invocation as kubectl logs -l "$KUBECLI_SEL"
.
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'
It is used to store the previously working context.
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!
Kubectl commands
- https://kubernetes.io/docs/reference/kubectl/kubectl/
- https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
kubectl Cheat Sheet
Custom columns
JSONPath Support
Here is collection of links to other projects similar to this one or implementing more interesting features.
- https://github.com/deniskrumko/kube-cli
- https://github.com/ahmetb/kubectx
- https://github.com/collabnix/kubetools
Copyright 2022, 2023 Ildar Shaimordanov
MIT License