Integrating a registered cluster with Simple Log Service provides a unified way to manage Kubernetes clusters that are distributed across different environments. This topic describes how to integrate Simple Log Service with a registered cluster by using an application in Container Service for Kubernetes (ACK).
Prerequisites
Step 1: Configure RAM permissions
Use onectl
-
Install and configure onectl on your local machine. For more information, see Manage registered clusters using onectl.
Run the following command to configure RAM permissions for the Simple Log Service component:
onectl ram-user grant --addon logtail-dsExpected output:
Ram policy ack-one-registered-cluster-policy-logtail-ds granted to ram user ack-one-user-ce313528c3 successfully.
Use the console
Before you install components in a registered cluster, you must create an AccessKey pair to grant the cluster permissions to access cloud services. This requires creating a RAM user and granting it the necessary permissions.
Create a custom policy. Use the following policy content.
-
Create an AccessKey for the RAM user.
WarningFor enhanced security, configure a network access control policy for the AccessKey to restrict access to trusted network environments and improve security. For more information, see AccessKey-based network access restriction policies.
Use the AccessKey pair to create a Secret named
alibaba-addon-secretin the registered cluster.Run the following command to create the Secret used by the Logtail component.
kubectl -n kube-system create secret generic alibaba-addon-secret --from-literal='access-key-id=<your AccessKey ID>' --from-literal='access-key-secret=<your AccessKey Secret>'NoteReplace
<your AccessKey ID>and<your AccessKey Secret>with your AccessKey pair.
Step 2: Install the logtail-ds component
Use onectl
Run the following command to install the logtail-ds component:
onectl addon install logtail-dsExpected output:
Addon logtail-ds, version **** installed.Use the console
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the target cluster. In the left-side navigation pane, click Add-ons.
On the Add-ons page, click the Logs and Monitoring tab. Find the logtail-ds component and click Install in the lower-right corner of the card.
In the Note dialog box, click OK.
(Optional) Step 3: Configure log collection from pods
Text logs
To collect text logs from pods, connect to the registered cluster by using kubectl and apply the following AliyunLogConfig configuration.
apiVersion: log.alibabacloud.com/v1alpha1
kind: AliyunLogConfig
metadata:
name: test-file # The name of the resource. The name must be unique in the Kubernetes cluster.
spec:
project: k8s-log-c326bc86**** # Optional. The name of the project. You can customize the name. We recommend that you name the project in the k8s-log-<cluster-id> format.
logstore: test-file # Required. The name of the Logstore. If the specified Logstore does not exist, Simple Log Service automatically creates it.
logtailConfig: # The Logtail configuration.
inputType: file # The type of the data source. Set the value to file for text logs or plugin for stdout.
configName: test-file # The name of the Logtail configuration. The name must be the same as the resource name specified by metadata.name.
inputDetail: # The details of the Logtail configuration.
logType: common_reg_log # Collects text logs in simple mode.
logPath: /log/ # The path where the log files are stored.
filePattern: "*.log" # The name of the log file. You can use asterisks (*) and question marks (?) as wildcards. Example: log_*.log.
dockerFile: true # Specifies whether to collect logs from files in containers. Set the value to true.
advanced: # Specifies the conditions to filter containers.
k8s:
K8sNamespaceRegex: ^(default)$
K8sPodRegex: '^(nginx-log-demo.*)$'
K8sContainerRegex: ^(nginx-log-demo-0)$
IncludeK8sLabel:
job-name: "^(nginx-log-demo.*)$"For more information about the parameters, see Logtail configurations (Legacy).
Stdout
To collect stdout from pods, connect to the registered cluster by using kubectl and apply the following AliyunLogConfig configuration. Applying this configuration automatically creates a Logstore named stdout-logstore and collects logs into it.
apiVersion: log.alibabacloud.com/v1alpha1
kind: AliyunLogConfig
metadata:
# The name of your configuration. The name must be unique in your Kubernetes cluster.
name: stdout-collector
spec:
# The name of the Logstore to which logs are uploaded.
logstore: stdout-logstore
# The details of the Logtail configuration.
logtailConfig:
# The input type for Docker stdout. Must be 'plugin'.
inputType: plugin
# The name of the Logtail configuration. Must match metadata.name.
configName: stdout-collector
inputDetail:
plugin:
inputs:
-
type: service_docker_stdout
detail:
# Collects stdout and stderr.
Stdout: true
Stderr: true
# Collects the stdout of all containers except for those with the COLLECT_STDOUT_FLAG:false environment variable.Step 4: Configure Simple Log Service
For more information, see Configure Simple Log Service when you create an application.
For more information about how to collect Ingress logs, see Collect and analyze access logs of NGINX Ingress controllers.