Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the tips for troubleshooting applications on Kubernetes

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the troubleshooting skills for applications on Kubernetes". The explanation in this article is simple and clear and easy to learn and understand. please follow the editor's ideas to study and learn "what are the troubleshooting skills for applications on Kubernetes?"

1.kubectl get deployment/pods

The reason why this command is so important is that it does not need to display a lot of content to display useful information.

If you want to use deployment for workloads, you have two options:

Kubectl get deploy kubectl get deploy-n namespace kubectl get deploy-all-namespaces [or "- A"]

Ideally, what you want to see is 1 prime 1 or the equivalent of 2 prime 2, and so on. This indicates that your deployment has been accepted and that it has been attempted.

Next, you may need to check the kubectl get pod to see if the deployed backup Pod starts correctly.

2. Kubectl get events

I was surprised that I often had to explain this trick to people who had problems with Kubernetes. This command prints out events in a given namespace and is ideal for finding critical issues, such as crashed pod or unable to pull container images.

The logs in Kubernetes are "unsorted", so you will need to add the following, which are taken from the OpenFaaS document.

$kubectl get events-sort-by=.metadata.creationTimestamp

Another close command for the kubectl get event is kubectl describe, which, like get deploy / pod, works with the name of the object:

Kubectl describe deploy/figlet-n openfaas

You will get very detailed information here. You can describe most things, including nodes, which will show that Pod cannot be started due to resource constraints or other problems.

3. Kubectl logs

This command must be used a lot, but many people use it in the wrong way.

If you deploy, such as cert-manager in the cert-manager namespace, many people think they must first find the long (unique) name of the Pod and use it as a parameter. Wrong.

Kubectl logs deploy/cert-manager-n cert-manager

To track the log, add-f

Kubectl logs deploy/cert-manager-n cert-manager-f

You can combine all three.

If your Deployment or Pod has any tags, you can use-l app = name or any other tag set to attach to one or more logs that match the Pod.

Kubectl logs-l app=nginx

There are tools, such as stern and kail, that can help you match patterns and save some typing, but I find them distracting you.

4.kubectl get-o yaml

When you start using YAML generated by another project or other tools such as Helm, you will soon need it. It is also useful to check the version of the image or the comments you set somewhere in production.

Kubectl run nginx-1-image=nginx-port=80-restart=Always

Output yaml

Kubectl get deploy/nginx-1-o yaml

Now we know. Also, we can add-export and save the YAML locally for editing and reapplying.

Another option for real-time editing YAML is kubectl edit. If you are confused about vim and don't know how to use it, add VISUAL = nano before the command and use this simplified editor.

5. Kubectl scale, have you turned it on and off?

Kubectl scale can be used to shrink Deployment and its Pod to zero copies, effectively killing all copies. When you scale it back to 1 / 1, a new Pod is created and your application is restarted.

The syntax is so simple that you can restart the code and test it again.

Kubectl scale deploy/nginx-1-replicas=0 kubectl scale deploy/nginx-1-replicas=16. Port forwarding

We need this trick, port forwarding through kubectl allows us to expose a service on a local or remote cluster on our own computers so that we can access it on any configured port without exposing it on Internet.

The following is an example of locally accessing a Nginx deployment:

Kubectl port-forward deploy/nginx-1 8080:80

Some people think that this only applies to deployment or Pod, which is wrong. Services are fair, usually the choice of forwarding, because they will simulate the configuration in the production cluster.

If you do want to expose the service on Internet, you will usually use the LoadBalancer service, or run kubectl exposure:

Kubectl expose deployment nginx-1-- port=80-- type=LoadBalancer Thank you for your reading, these are the contents of "what are the skills for troubleshooting applications on Kubernetes". After the study of this article, I believe you have a deeper understanding of the skills of troubleshooting applications on Kubernetes, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report