sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
apt-cache policy kubectl
apt-get install bash-completion
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash >/etc/bash_completion.d/kubect
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc
alias kg='kubectl get'
alias klo='kubectl logs -f'
It's an interactive Unix filter for command-line that can be used with any list; files, command history, processes, hostnames, bookmarks, git commits, etc.
sudo apt-get install fzf
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &&
tar zxvf krew.tar.gz &&
KREW=./krew-"${OS}_${ARCH}" &&
"$KREW" install krew
)
kubectl krew install ctx
kubectl krew install ns
# OR
sudo apt install kubectx
# kubectx
alias kx=kubectx
complete -F _complete_alias kx
alias kctx="kubectl ctx"
alias kubectx="kubectl ctx"
# kubens
alias kn=kubens
complete -F _complete_alias kn
alias kns="kubectl ns"
alias kubens="kubectl ns"
A script that lets you add the current Kubernetes context and namespace configured on kubectl to your Bash/Zsh prompt strings (i.e. the $PS1).
wget https://raw.githubusercontent.com/jonmosco/kube-ps1/master/kube-ps1.sh -o ~/.oh-my-zsh/plugins/kube-ps1/kube-ps1.plugin.zsh
vim ~/.zshrc
source ~/.oh-my-zsh/plugins/kube-ps1/kube-ps1.plugin.zsh
PROMPT=$PROMPT'$(kube_ps1) '
source ~/.oh-my-zsh/plugins/kubectl/kubectl.plugin.zsh
RPROMPT='%{$fg[blue]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}'
kubectl krew install deprecations
# Usage
kubectl deprecations --help
Under the hood kube-shell still calls kubectl. Kube-shell aims to provide ease-of-use of kubectl and increasing productivity.
The kube-shell requires python and pip to install. You can install the kube-shell using pip:
pip install kube-shell
After installing kube-shell through pip, just run kube-shell to bring up shell.
At the kube-shell command prompt you can run exit or press F10 to exit the shell. You can clear the screen by running clear command.
By default drop-down suggestion list also displays in-line documentation, you can turn on/off inline documnetation by pressing F4 button.
You can run any shell command by prefixing command with "!". For e.g. !ls would list from the current directory.
Kubernetes tail. Streams logs from all containers of all matched pods. Match pods by service, replicaset, deployment, and others. Adjusts to a changing cluster - pods are added and removed from logging as they fall in or out of the selection.
Kail binaries for Linux and OSX can be found on the latest release page. Download and install into your $GOPATH/bin with:
bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$GOPATH/bin"
A kubectl plugin to explore ownership relationships between Kubernetes objects through ownersReferences on the objects.
The kubectl lineage plugin is very similar to kubectl tree, but it understands logical relationships between some API objects without needing ownerReferences.
Use krew plugin manager to install:
kubectl krew install tree
kubectl tree --help
- kubectl-df-pv: A kubectl plugin to see df for persistent volumes.
- kubectl-images: Show container images used in the cluster