当前位置:网站首页>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 .
边栏推荐
- A memory leak caused by timeout scheduling of context and goroutine implementation
- Robot toolbox matlab robotics toolbox
- Problems encountered in the work of product manager
- What is a reptile
- 6 things all engineers should know before FEA
- Go path customized project path package dependency
- [tke] analysis of CLB loopback in Intranet under IPVS forwarding mode
- How to pop up an alarm through the national standard gb28181 protocol video platform easygbs for mobile detection / perimeter intrusion detection video recording
- [play with Tencent cloud] & lt; trtc-room> Applet component usage
- Factory mode
猜你喜欢

Problems encountered in the work of product manager

Ui- first lesson

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

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

A survey on model compression for natural language processing (NLP model compression overview)

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

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

Ps\ai and other design software pondering notes

Applet wxss

Applet - use of template
随机推荐
[play with Tencent cloud] my operation strategy from domain name application to website filing in Tencent cloud
05. Tencent cloud IOT device side learning -- mqtt protocol client implementation
Ui- first lesson
Greenplum role-based fine-grained permission control
Batch BOM Bapi test
proxy pattern
@There is a free copyright protection service for enterprises in Dawan District
[play with Tencent cloud] & lt; trtc-room> Applet component usage
Embedded Software Engineer written interview guide arm system and architecture
[playing with Tencent cloud] a solution to the impassability of cross-border access to foreign websites using Tencent cloud CVM
Annual contribution! Tencent cloud middleware product upgrade conference is in hot registration!
The million bonus competition is about to start, and Ti-One will be upgraded to help you win the championship!
Serial of H3CNE experiment column - spanning tree STP configuration experiment
TRTC web end imitation Tencent conference microphone mute detection
Video intelligent analysis platform easycvr derivative video management platform menu bar small screen adaptive optimization
Percona Toolkit series - Pt deadlock logger
Applet - use of template
Bypass kernel function pointer integrity check
NFT元宇宙源码搭建解析与介绍
Pagoda activities, team members can enjoy a lightweight server 1 core 2g5m 28 yuan for two years