7

kubectl, tmux, Kubernetes.

  Kubernetes   tmux  kubectl

Kubernetes - , , , . , kubectl. Kubectl , , Kubernetes.


Kubernetes

, Kubernetes , - , . , Kubernetes - ( ).

, . , , - - , - .

, System, :

kubectl --namespace=kube-system exec -i -t <your-pod-name>

. , dotfiles (.bashrc .zshrc):

alias ksysex='kubectl --namespace=kube-system exec -i -t'

Kubernetes, kubectl. - , , .


kubectl

, , . ; Kubernetes. .

10 20 50 100, . ?

  • -, , .
  • -, .
  • , .

, , , .

, , kubectl. , , Kubernetes.

, kubectl- < - > , $PATH chmod+x.

, . , kubectl-krwl kubectl-kmux:

$ kubectl plugin list
The following compatible plugins are available:

/usr/local/bin/kubectl-krawl
/usr/local/bin/kubectl-kmux

$ kubectl kmux

, Kubernetes tmux.

tmux

Tmux - , , - . , .

kubectl, tmux, . , ( , ):

#NAMESPACE is namespace to monitor.
#POD is pod name
#Containers is container names

# initialize a counter n to count the number of loop counts, later be used by tmux to split panes.
n=0;

# start a loop on a list of pod and containers
while IFS=' ' read -r POD CONTAINERS
do

           # tmux create the new window for each pod
            tmux neww $COMMAND -n $POD 2>/dev/null

           # start a loop for all containers inside a running pod
        for CONTAINER in ${CONTAINERS//,/ }
        do

        if [ x$POD = x -o x$CONTAINER = x ]; then
        # if any of the values is null, exit.
        warn "Looks like there is a problem getting pods data."
        break
        fi
           
            # set the command to execute
        COMMAND=kubectl logs -f $POD -c $CONTAINER -n $NAMESPACE
        # check tmux session
        if tmux has-session -t <session name> 2>/dev/null;
        then
        <set session exists>
        else
        <create session>
        fi

           # split planes in the current window for each containers
        tmux selectp -t $n \; \
        splitw $COMMAND \; \
        select-layout tiled \;

           # end loop for containers
        done

           # rename the window to identify by pod name
        tmux renamew $POD 2>/dev/null
       
            # increment the counter
        ((n+=1))

# end loop for pods
done< <(<fetch list of pod and containers from kubernetes cluster>)

# finally select the window and attach session
 tmux selectw -t <session name>:1 \; \
  attach-session -t <session name>\;

, . , ( ) . tmux ; , (. ).


Kubernetes. , kubectl . , kubectl, . , , kubectl.


50% Merion Academy