当前位置:网站首页>Collect tke logs through daemonset CRD
Collect tke logs through daemonset CRD
2022-06-24 16:46:00 【tinkerli】
stay TKE in LogListener In order to DaemonSet mode , It can be done by CRD Method to create a collection configuration collection TKE Cluster log . How does this article describe CRD Method to create a collection configuration .
Prerequisite
You need to enable the log collection function , Please refer to Start log collection
Create a collection configuration
You just need to define LogConfig CRD You can create an acquisition configuration ,LogListener according to LogConfig CRD Changes to modify the corresponding logging service CLS Journal topics , And set the bound machine group .CRD The format is as follows :
apiVersion: cls.cloud.tencent.com/v1
kind: LogConfig ## The default value is
metadata:
name: test ## CRD Resource name , The only one in the cluster
spec:
clsDetail:
topicId: xxxxxx-xx-xx-xx-xxxxxxxx ## CLS Log subject ID, Log topics need to be in CLS Create in advance , And is not occupied by other acquisition configurations
logType: minimalist_log ## Log collection format ,json_log representative json Format ,delimiter_log Represents the separator format ,minimalist_log Represents single line full-text format ,multiline_log Represents multi line full-text format ,fullregex_log Stands for fully regular format
extractRule: ## extract 、 Filtering rules
...
inputDetail:
type: container_stdout ## Type of collection log , Include container_stdout( Container standard output )、container_file( Container file )、host_file( Host files )
containerStdout: ## Container standard output
namespace: default ## Of the collection container kubernetes Namespace , If you don't specify , Represents all namespaces
allContainers: false ## Whether to collect the standard output of all containers in the specified namespace
container: xxx ## Satisfy includeLabels Of Pod Container name in , Only in the designated includeLabels When using
includeLabels: ## The acquisition contains the specified label Of Pod
k8s-app: xxx ## Collect only pod Configuration in label "k8s-app=xxx" Of pod Generated log , And workloads、allContainers=true Cannot specify at the same time
workloads: ## Of the container to be collected Pod Of kubernetes workload
- namespace: prod ## workload The namespace of
name: sample-app ## workload Name
kind: deployment ## workload type , Support deployment、daemonset、statefulset、job、cronjob
container: xxx ## Name of the container to collect , If you don't specify , representative workload Pod All containers in
containerFile: ## Documents in the container
namespace: default ## Of the collection container kubernetes Namespace
container: xxx ## Collection container name
includeLabels: ## The acquisition contains the specified label Of Pod
k8s-app: xxx ## Collect only pod Configuration in label "k8s-app=xxx" Of pod Generated log , And workload Cannot specify at the same time
workload: ## Of the container to be collected Pod Of kubernetes workload
name: sample-app ## workload Name
kind: deployment ## workload type , Support deployment、daemonset、statefulset、job、cronjob
logPath: /opt/logs ## Log folder , Wildcard characters are not supported
filePattern: app_*.log ## Log file name , Support for wildcards * and ? ,* Indicates matching multiple arbitrary characters ,? Means to match a single arbitrary character
hostFile: ## Host files
logPath: /opt/logs ## Log folder , Support for wildcards
filePattern: app_*.log ## Log file name , Support for wildcards * and ? ,* Indicates matching multiple arbitrary characters ,? Means to match a single arbitrary character
customLablels
k1: v1View collection configuration
- View all collection configurations
[[email protected] ~]# kubectl get logconfigs NAME AGE cls-delimiter 48m stdout-lgs 4h21m www-nginx 75m
- View the details and status of the collection configuration
- among stdout-lgs Is the name of the configuration , It can be replaced according to the actual situation ;
- status The field values for Synced Indicates that the application configuration is successful , Otherwise, the application configuration fails .
[[email protected] ~]# kubectl get logconfigs stdout-lgs -o yaml apiVersion: cls.cloud.tencent.com/v1 kind: LogConfig metadata: creationTimestamp: "2021-04-07T09:33:42Z" generation: 2 managedFields: - apiVersion: cls.cloud.tencent.com/v1 ...... name: stdout-lgs spec: clsDetail: extractRule: beginningRegex: (\S+)\s-[^-]+(\S+)\s\[([^\]]+)\]\s"(\w+)\s(\S+)\s([^"]+)"\s(\d+)\s(\d+)\s(\S+)[^-]+([^"]+)"\s"([^"]+)[^-]+([^"]+)"\s"([^"]+).* keys: - client_ip - remote_user - request_time - request_method - request_url - http_protocol - status_code - body_bytes_sent - handle_time - http_referer - http_user_agent - real_ip - log_time logRegex: (\S+)\s-[^-]+(\S+)\s\[([^\]]+)\]\s"(\w+)\s(\S+)\s([^"]+)"\s(\d+)\s(\d+)\s(\S+)[^-]+([^"]+)"\s"([^"]+)[^-]+([^"]+)"\s"([^"]+).* logType: fullregex_log topicId: 4511efaa-2cad-4c3c-8c7c-d3bb5a58d903 inputDetail: containerStdout: includeLabels: k8s-app: tke-cls-nginx-std namespace: cls-wk type: container_stdout status: status: Synced
Sample collection
standard output
- Collect one namespace yes cls-wk, The label is tke-cls-nginx Configuration of standard output of all containers
apiVersion: cls.cloud.tencent.com/v1
kind: LogConfig
metadata:
# Configuration name , Cluster unique
name: test123
spec:
# Consumer configuration
clsDetail:
# The consumption of topic id
topicId: 4224b4f3-9ee8-46e3-822a-xxxxxxxxx
# Extraction mode
logType: minimalist_log
inputDetail:
# Collection type
type: container_stdout
containerStdout:
# Belongs to namespace
namespace: cls-wk
# Label corresponding to the container
includeLabels:
k8s-app: tke-cls-nginx- Regular expression extraction pattern
apiVersion: cls.cloud.tencent.com/v1
kind: LogConfig
metadata:
# Configuration name , Cluster unique
name: stdout-lgs
spec:
clsDetail:
extractRule:
beginningRegex: (\S+)\s-[^-]+(\S+)\s\[([^\]]+)\]\s"(\w+)\s(\S+)\s([^"]+)"\s(\d+)\s(\d+)\s(\S+)[^-]+([^"]+)"\s"([^"]+)[^-]+([^"]+)"\s"([^"]+).*
# Raised key value
keys:
- client_ip
- remote_user
- request_time
- request_method
- request_url
- http_protocol
- status_code
- body_bytes_sent
- handle_time
- http_referer
- http_user_agent
- real_ip
- log_time
# Regular expressions , Will be based on () The capture group extracts the corresponding value
logRegex: (\S+)\s-[^-]+(\S+)\s\[([^\]]+)\]\s"(\w+)\s(\S+)\s([^"]+)"\s(\d+)\s(\d+)\s(\S+)[^-]+([^"]+)"\s"([^"]+)[^-]+([^"]+)"\s"([^"]+).*
# Log collection format : Fully regular extraction pattern
logType: fullregex_log
topicId: 4511efaa-2cad-4c3c-8c7c-xxxxxxxxx
inputDetail:
containerStdout:
# pod label
includeLabels:
k8s-app: tke-cls-nginx-std
namespace: cls-wk
# Collection type
type: container_stdoutAfter applying the configuration , The data format of the log service is as follows :
Container file
- collection deployment by nginx-logfile, The container name is nginx-logfile Log file , The log file path is /data/log/nginx,*.log Final document .
apiVersion: cls.cloud.tencent.com/v1
kind: LogConfig
metadata:
# Configuration name , Cluster unique
name: www-nginx
spec:
clsDetail:
# Log collection format
logType: minimalist_log
topicId: 56a32d6f-77da-4c4a-a7d1-xxxxxxxxx
inputDetail:
containerFile:
container: nginx-logfile
# file name , Support for wildcards * and ?
filePattern: '*.log'
logPath: /data/log/nginx
namespace: cls-wk
workload:
kind: deployment
name: nginx-logfile
# The collection type is container file
type: container_file- Separator mode log file
apiVersion: cls.cloud.tencent.com/v1
kind: LogConfig
metadata:
# Configuration name , Cluster unique
name: cls-delimiter
spec:
clsDetail:
# Separator
delimiter: '::'
# Extracted key
keys:
- remote_addr
- remote_user
- time_local
- request
- status
- body_bytes_sent
- request_time
- http_referer
- http_user_agent
- http_x_forwarded_for
- msec
# The log time uses the field time in the log
timeFormat: '%d/%b/%Y %H:%M:%S'
timeKey: time_local
# The format of log collection is separator mode
logType: delimiter_log
topicId: e850733e-f32b-4a8e-a246-xxxxxxxx
inputDetail:
containerFile:
container: nginxdelimiter
filePattern: '*.log'
logPath: /data/log/nginx
namespace: cls-wk
workload:
kind: deployment
name: nginxdelimiter
# The collection type is container file
type: container_fileAfter applying the configuration , The data format of the log service is as follows :
more CLS and TKE Please refer to the following links for log collection :
Use CRD Configure log collection
A friendly reminder :
- adopt CRD Collection configuration TKE journal , The index needs to be opened and configured in the log console ;
- Recommended by TKE Console configuration , By default, full-text index and partial key value index are opened .
边栏推荐
- During JMeter pressure measurement, time_ The number of requests does not go up due to many waits. The problem is solved
- Abstract factory pattern
- [go] concurrent programming channel
- [tke] analysis of CLB loopback in Intranet under IPVS forwarding mode
- Finite element simulation in design
- Object store signature generation
- Join in ABAP CDs
- Kubernetes 1.20.5 setting up Sentinel
- How to use the national standard streaming media server to view the video stream of the surveillance camera? How to correctly use UDP and TCP protocols?
- Problems encountered in the work of product manager
猜你喜欢

Cognition and difference of service number, subscription number, applet and enterprise number (enterprise wechat)

A survey on model compression for natural language processing (NLP model compression overview)
![[leetcode108] convert an ordered array into a binary search tree (medium order traversal)](/img/e1/0fac59a531040d74fd7531e2840eb5.jpg)
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)

A survey of training on graphs: taxonomy, methods, and Applications

A survey on dynamic neural networks for natural language processing, University of California

Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)

Ui- first lesson

Ps\ai and other design software pondering notes
![[go] concurrent programming channel](/img/6a/d62678467bbc6dfb6a50ae42bacc96.jpg)
[go] concurrent programming channel

Applet wxss
随机推荐
Sigai intelligent container damage identification products are deployed in Rizhao Port and Yingkou Port
Ui- first lesson
Swift array map/flatmap/compactmap/filter/reduce/chaining Usage Summary
Edit distance (linear dp+ violence matching)
AI video structured intelligent security platform easycvr realizes intelligent security monitoring scheme for procuratorate building
[tke] nodelocaldnschache is used in IPVS forwarding mode
集体突破之后,中国公有云的下一步落在哪里?
Tencent blue whale container management platform was officially released!
Clickhouse high performance column storage core principle
Introduction of thread pool and sharing of practice cases
Introduction to koa (II) building the koa program
Video structured intelligent analysis platform easycvr video recording plan function optimization / regularly delete expired videos
实现TypeScript运行时类型检查
How to collect and define project requirements in the early stage of EDI project implementation?
中金证券靠谱吗?是否合法?开股票账户安全吗?
Cognition and difference of service number, subscription number, applet and enterprise number (enterprise wechat)
How does the easynvr/easygbs live video platform use Wireshark to capture and analyze data locally?
[golang] Introduction to golang (I) establishment of running environment
Istio FAQ: virtualservice route matching sequence
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)