In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to use Tmux and kubectl to solve Kubernetes failure, the content is very detailed, interested friends can refer to, hope to be helpful to you.
A kubectl plug-in that uses tmux can make Kubernetes troubleshooting easier.
Kubernetes is an active open source container management platform that provides extensibility, high availability, robustness, and resilient application management. One of its many features is support for running custom scripts or executables through its main binary client, kubectl, which is powerful and allows users to do a lot of things directly on the Kubernetes cluster.
Troubleshooting Kubernetes using aliases
Anyone who uses Kubernetes for container choreography knows that its functional complexity is caused by design reasons. For example, there is an urgent need to simplify troubleshooting in Kubernetes (except for special cases) at a faster speed and with little manual intervention.
In terms of troubleshooting capabilities, there are many scenarios to consider. In one scenario, you know what you need to run, but the syntax of the command (even if run as a separate command) is too complex, or requires one or two interactions to work.
For example, if you need to frequently enter a container that runs in a system namespace, you may find yourself typing repeatedly:
Kubectl-namespace=kube-system exec-I-t
To simplify troubleshooting, you can use the command line aliases for these instructions. For example, you can add the following command to your hidden configuration file (.bashrc or .zshrc):
Alias ksysex='kubectl-- namespace=kube-system exec-I-t'
This is an example from the Kubernetes common alias repository that shows a way to simplify functionality in kubectl. In a simple situation like this, it is useful to use aliases.
Switch to the kubectl plug-in
More complex troubleshooting scenarios require a lot of commands to be executed one by one, investigate the environment, and finally come to a conclusion. Using aliases alone won't solve this situation; you need to know the logic and correlation between the Kubernetes you deploy, and what you really need is automation to output what you want in less time.
Consider that your cluster has 10-20 or 50-100 namespaces to provide different microservices. In general, what is helpful to you when troubleshooting?
You need something that can quickly tell which Pod of which namespace threw the error.
You need something to monitor all Pod logs in a namespace.
You may also need to monitor the log of an Pod with errors in a particular namespace.
Solutions that cover these points are of great help in locating problems in the production environment, as well as in development and testing.
You can use the kubectl plugin to create something more powerful than a simple alias. Plug-ins are similar to other stand-alone scripts written in any language, but are designed to extend the main commands of Kubernetes administrators.
To create a plug-in, you must use the correct syntax of kubectl- to copy the script to one of the export directories in $PATH and give it executable permissions (chmod + x).
After creating the plug-in, move it to the path, and you can run it immediately. For example, I have a kubectl-krawl and kubectl-kmux under my path:
$kubectl plugin listThe following compatible plugins are available: / usr/local/bin/kubectl-krawl/usr/local/bin/kubectl-kmux $kubectl kmux
Now let's see how powerful Kubernetes with tmux can be.
Harness the powerful tmux
Tmux is a very powerful tool that many administrators and operations teams rely on to solve ease-of-operation-related problems: monitoring logs by dividing the window into panes to run parallel debugging on multiple computers. Its main advantage is that it can be used on the command line or in automated scripts.
I created a kubectl plug-in that uses tmux to make troubleshooting easier. I will parse the logic behind the plug-in through comments (the complete code of the plug-in will be left for you to implement):
# NAMESPACE is the namespace to monitor # POD is the Pod name # Containers is the container name # initialize a counter n to calculate the number of loop counts, and then tmux uses it to split the pane. Start while IFS=' 'read-r POD CONTAINERSdo # tmux on the Pod and container list create a new window for each Pod tmux neww $COMMAND-n $POD 2 > / dev/null # launch the loop for CONTAINER in ${CONTAINERS//,/} do if [x$POD = x-o x$CONTAINER = x] for all containers in the running Pod; then # exit if any value is null. 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-T2 > / dev/null; then else fi # split panes for each container in the current window tmux selectp-t $n\ \ splitw $COMMAND\;\ select-layout tiled\; # terminate the container loop done # rename the window with the Pod name to identify the tmux renamew $POD 2 > / dev/null # add counters ((nasty counter 1)) # terminate the Pod loop done
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.