Configure the Ingress log center
Updated at:
Enable the Ingress Log Center to collect and visualize Ingress access logs in real time in Simple Log Service.
Prerequisites
The Logtail component must be installed. For more information, see Install the Logtail component.By default, the Logtail component is automatically installed when you create a Kubernetes cluster.
Step 1: Deploy Ingress collection
Simple Log Service uses a Custom Resource Definition (CRD) to extend Kubernetes for log collection. When you define an AliyunLogConfig CRD, the alibaba-log-controller component automatically creates the corresponding collection configurations and report resources in Simple Log Service.
- In your Kubernetes cluster, define the AliyunLogConfig CRD configuration.
Note
- Ensure that the version of the alibaba-log-controller component is 0.2.0.0-76648ee-aliyun or later.
If you update the component after you apply the CRD configuration, you must delete and reapply the configuration.
- This CRD configuration works only for the default access log format of the Ingress Controller in Container Service for Kubernetes (ACK). If you modified the access log format, you must update the
processor_regexsection of this CRD configuration with the corresponding regular expression. For details about the required modifications, see the CRD configuration in Use a CRD to collect container logs in DaemonSet mode. - If no other systems depend on the access log, we recommend that you change the access log format to the one recommended by Simple Log Service. To do this, run the
kubectl edit configmap -n kube-system nginx-configurationcommand to modify the configmap and update thelog-format-upstreamfield with the following content: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: # The name of your configuration. The name must be unique in the Kubernetes cluster. name: k8s-nginx-ingress spec: # The name of the Logstore to which logs are sent. logstore: nginx-ingress # The product code. Set the value to k8s-nginx-ingress for Kubernetes NGINX Ingress. productCode: k8s-nginx-ingress # The details of the Logtail configuration. logtailConfig: inputType: plugin # The name of the Logtail configuration. It must be the same as the value of 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: content - Ensure that the version of the alibaba-log-controller component is 0.2.0.0-76648ee-aliyun or later.
- Deploy the Ingress collection configuration.
You can use one of the following methods:
- Method 1: Run a
kubectlcommand. - Method 2: Save the AliyunLogConfig CRD configuration from Step 1 as a file named
nginx-ingress.yaml, and then run thekubectl apply -n kube-system -f nginx-ingress.yamlcommand. - Method 3: Use an orchestration template.
- 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 the template. For more information, see Create a stateless application by using a Deployment.
For the Namespace parameter, select the default namespace of your cluster.
- Method 1: Run a
Step 2: Add a log center
Log on to the Simple Log Service console.
- In the Log Application section, click Ingress Log Center.
- On the Inspection Management tab, click Add.
- In the Add Log Center panel, configure the following parameters and click OK.
Parameter Description Log center name Enter a name for the log center. Project Select the project that you created. Logstore Select the Logstore that you created. This Logstore must be the same as the one specified in the collection configuration in Step 1.
Next steps
After you complete the configuration, you can view reports in the Ingress Log Center. You can also query, analyze, download, ship, and process logs, and configure alerts. For more information, see Common operations on logs of Alibaba Cloud services. You can also query, analyze, and configure alerts for metric data. For more information, see Query and analyze metric data.Is this page helpful?