In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you practice on how to query and analyze Kubernetes logs. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
Introduction: the following will introduce how to realize the collection, query and analysis of Kubernetes (hereinafter referred to as K8s) logs based on log service. in addition, it also gives a brief introduction to Ingress and Audit schemes. In order to facilitate your understanding through operation, detailed operation steps and corresponding screenshots and configuration codes are provided.
Preparatory work
In order to complete the following operations, we need to prepare a K8s cluster. The steps are as follows:
Log in to the Container Services console.
Create a standard managed cluster (Hangzhou area) and check * * [use EIP to expose API Server] and [use Log Service] * * in the wizard.
After the cluster is created, go back to the cluster list page and click * more-> manage clusters through CloudShell] * *.
Enter kubectl get ds-n kube-system in CloudShell, and the logtail-ds shown in the result is the log service component installed for data acquisition.
Open the log service console and see that the project corresponding to the K8s cluster ID has also been created.
The screenshot of the operation is as follows:
Figure: create a managed cluster (step 2)
Figure: open CloudShell (step 3)
Figure: view the log service components in CloudShell (step 4)
Figure: open the Log Service console and view project (step 5)
1. data acquisition
In K8s environment, container log data can be divided into two categories: standard output of container and text file in container. The former is a unique form of log existence of container, while the latter is similar to traditional text file log, except that the files are stored inside each container and isolated from each other. Below we will describe how to collect these two types of logs.
1.1. Mock data
We will use the following two YAML files to generate mock data in standard output and in-container files, respectively.
Container standard output
# create two pod to generate mock data apiVersion: batch/v1kind: Jobmetadata: name: nginx-stdout-log-demo-1 namespace: nginx-stdoutspec: template: metadata: name: nginx-stdout-log-demo-1 spec: containers:-name: nginx-stdout-log-demo-1 image: registry.cn-hangzhou.aliyuncs.com/log-service/docker-log-test:latest command: ["/ bin/ Mock_log "] args: ["-- stderr=false " "- stdout=true", "- log-type=nginx", "- total-count=100000000" "--logs-per-sec=5"] restartPolicy: Never---apiVersion: batch/v1kind: Jobmetadata: name: nginx-stdout-log-demo-2 namespace: nginx-stdoutspec: template: metadata: name: nginx-stdout-log-demo-2 spec: containers:-name: nginx-stdout-log-demo-2 image: registry.cn-hangzhou.aliyuncs.com/log-service/docker-log-test:latest command : ["/ bin/mock_log"] args: ["--stderr=false" "- stdout=true", "- log-type=nginx", "- total-count=100000000", "- logs-per-sec=5"] restartPolicy: Never
Text file in container (/ var/log/access.log)
ApiVersion: batch/v1kind: Jobmetadata: name: nginx-file-log-demo namespace: nginx-filespec: template: metadata: name: nginx-file-log-demo spec: restartPolicy: Never containers:-name: registry.cn-hangzhou.aliyuncs.com/log-service/docker-log-test:latest command: ["/ bin/mock_log"] args: ["--log-type=nginx" "- stdout=false", "- stderr=false", "- path=/var/log/access.log", "- total-count=100000000", "- logs-per-sec=5"]
Procedure:
Open CloudShell and refer to step 3 in preparation.
Apply the two YAML (Github) mentioned above to the cluster.
Execute kubectl get pods to view several Pod responsible for generating logs.
View the log generated by the two Pod (replace the pod name in the command according to the actual situation)
Standard output: execute kubectl logs-n nginx-stdout--tail=10 nginx-stdout-log-demo-1-7kvwx.
Container files: execute kubectl exec-n nginx-file nginx-file-log-demo-7frsp-- bash-c "tail / var/log/access.log".
$kubectl create namespace nginx-stdout$ kubectl create-f https://raw.githubusercontent.com/goclis/kubernetes-mock-log/master/pod_nginx_stdout.yaml$ kubectl create namespace nginx-file$ kubectl create-f https://raw.githubusercontent.com/goclis/kubernetes-mock-log/master/pod_nginx_file.yaml
Command: generate mock data (step 2)
$kubectl get pods-ANAMESPACE NAME READY STATUS RESTARTS AGEnginx-file nginx-file-log-demo-7frsp 1 7kvwx 1 Running 0 2m9snginx-stdout nginx-stdout-log-demo-1-7kvwx 1 Running 0 2m12snginx-stdout nginx-stdout -log-demo-2-4x7vw 1 4x7vw 1 Running 0 2m12s
Command: view log service components (step 3)
The above is the editor for you to share how to carry out Kubernetes log query analysis practice, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.