This topic explains how to enable the Ingress Log Center and collect Ingress logs in real time.
Prerequisite
The Logtail components are installed. For more information, see Install Logtail components in an ACK cluster.
By default, the Logtail components are automatically installed during the Kubernetes cluster creation.
Step 1: Deploy Ingress collection configuration
ACK defines a type of CustomResourceDefinition (CRD) named AliyunLogConfig. You can create an AliyunLogConfig to configure log collection. The alibaba-log-controller automatically generates configurations for Simple Log Service to collect log data and update data in relevant dashboards.
Define the AliyunLogConfig CRD configuration in the Kubernetes cluster.
NoteVerify that the version of the alibaba-log-controller component is 0.2.0.0-76648ee-aliyun or later.
If you want to update the component version after applying the CRD configuration, delete the CRD configuration and reapply it after updating the component version.
The CRD configuration only takes effect on the access log format of the default Ingress Controller in Container Service for Kubernetes (ACK). If you have modified the access log format of the Ingress Controller, update the processor_regex part in the CRD configuration accordingly. For more information, see the CRD configuration in Collect text logs from Kubernetes containers in DaemonSet mode.
If you currently do not have other systems relying on access logs, consider adopting the Simple Log Service's recommended access log format. To do this, run the command kubectl edit configmap -n kube-system nginx-configuration to modify the configmap and update the log-format-upstream field as follows:
log-format-upstream: $the_real_ip - [$the_real_ip] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id $host
apiVersion: log.alibabacloud.com/v1alpha1 kind: AliyunLogConfig metadata: # your config name, must be unique in you k8s cluster name: k8s-nginx-ingress spec: # logstore name to upload log logstore: nginx-ingress # product code, only for k8s nginx ingress productCode: k8s-nginx-ingress # logtail config detail logtailConfig: inputType: plugin # logtail config name, should be same with [metadata.name] configName: k8s-nginx-ingress inputDetail: plugin: inputs: - type: service_docker_stdout detail: IncludeLabel: io.kubernetes.container.name: nginx-ingress-controller Stderr: false Stdout: true processors: - type: processor_regex detail: KeepSource: false Keys: - client_ip - x_forward_for - remote_user - time - method - url - version - status - body_bytes_sent - http_referer - http_user_agent - request_length - request_time - proxy_upstream_name - upstream_addr - upstream_response_length - upstream_response_time - upstream_status - req_id - host - proxy_alternative_upstream_name NoKeyError: true NoMatchError: true Regex: ^(\S+)\s-\s\[([^]]+)]\s-\s(\S+)\s\[(\S+)\s\S+\s"(\w+)\s(\S+)\s([^"]+)"\s(\d+)\s(\d+)\s"([^"]*)"\s"([^"]*)"\s(\S+)\s(\S+)+\s\[([^]]*)]\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s*(\S*)\s*\[*([^]]*)\]*.* SourceKey: contentDeploy the Ingress collection configuration.
Select one of the following deployment methods:
Method 1: Run the kubectl command for deployment.
Method 2: Save the AliyunLogConfig CRD configuration from Step 1 as the nginx-ingress.yaml file, and run the kubectl apply -n kube-system -f command for deployment.
Method 3: Use the orchestration template for deployment.
Log on to the ACK Console.
Save the AliyunLogConfig CRD configuration from Step 1 as an orchestration template. For more information, see Manage orchestration templates.
Create an application from your template. For more information, see Create a Linux application by using an orchestration template. During this step, select the default namespace of your cluster.
Step 2: Add a log center
Log on to the Simple Log Service console.
In the Log Application section, click the Intelligent O&M tab and click Ingress Log Center.
Click Add.
In the Add Log Center panel, set the following parameters and click OK.
Parameter
Description
Log Center Name
Enter the name of the log center.
Project
Select a project.
Logstore
Select a logstore. Ensure that it matches the logstore specified in Step 1: Deploy Ingress collection configuration.
What to do next
After completing the configuration, you can view related reports in the Ingress Log Center and perform tasks such as log query analysis, downloading, shipping, transformation, and alerting. For more information, see Common operations on logs of Alibaba Cloud services. You can also manage query analysis and alerting for monitoring data. For more information, see Query and analyze metric data.