I load a lot of custom commands and functions in bashrc in order to make life easier in the long run. Below is a short list of the items i use often.
################### Functions ######################################
function clus_init {
echo "################################### CLUSTER INFO ###############################################################"
kubectl cluster-info | head -n 1
echo ""
kubectl top no
echo ""
RUN=0 # How many total pods running
TER=1 # Pod terminating or crashlooping
PEN=0 # Pods Pending
IMG=0 # Pods with Image issues
CON=0 # Pods with configuration errors
STA=0 # Pods starting up
pods=$(kubectl get po -A)
mapfile -t table_array < <(awk '{split($0, row, " "); print row[4] }' <<< "$pods")
for row in "${table_array[@]}"; do
RUN=$(($RUN+1))
case $row in
Terminating | CrashLoopBackOff)
TER=$(($TER+1))
;;
ImagePullBackOff | ErrImagePull)
IMG=$(($IMG+1))
;;
CreateContainerConfigError | Error)
CON=$(($CON+1))
;;
Pending)
PEN=$(($PEN+1))
;;
ContainerCreating)
STA=$(($STA+1))
;;
esac
done
echo "Tot Pods: $RUN | Pods Starting: $STA | Config Errors: $CON | Term or Crash: $TER | Image Issues: $IMG | Pending: $PEN"
echo "################################### CLUSTER INFO ###############################################################"
}
#################### ALIASES #########################################
alias argo='argocd'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias tf='terraform'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -lachF'
alias ls='ls --color=auto'
alias v='velero'
alias watch='watch -n .2 -d'
alias k='kubectl'
alias kc='kubectl config set-cluster'
alias kn='kubectl config set-context --current --namespace'
##################### Kube Configs ######################################
alias <ClusterName>='export KUBECONFIG=~/.kube/<config-file> && clus_init'
The above profile sets up all my preferred aliases. Also, when I change clusters I get a nice status update of the cluster before I start working it. The output from switching clusters by using the alias name:
################################### CLUSTER INFO ###############################################################
Kubernetes control plane is running at https://<ULRToClusterEndpoint>
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
Node 01 1517m 18% 9288Mi 29%
Node 02 411m 10% 4168Mi 26%
Node 03 245m 3% 10208Mi 32%
Node 04 812m 20% 4731Mi 30%
Node 05 2412m 30% 8788Mi 28%
Node 06 329m 8% 3253Mi 20%
Node 07 4159m 51% 19658Mi 62%
Tot Pods: 173 | Pods Starting: 0 | Config Errors: 2 | Term or Crash: 1 | Image Issues: 17 | Pending: 0
################################### CLUSTER INFO ###############################################################
I may switch over to kubectl get no -o wide
versus kubectl top no
if I find this doesn’t help much, but at the time it works.