Kubernetes provides multiple metrics. You can collect the metrics from Kubernetes clusters to the Full-stack Monitoring application. This way, you can monitor data in a visualized manner.

Prerequisites

  • An instance is created. For more information, see Create an instance.
  • Logtail components are installed in a Kubernetes cluster. For more information, see Install Logtail components.
    Note Make sure that you select the same project when you install Logtail components and when you create a Full-stack Monitoring instance.

Install a monitoring component

  1. Log on to your Kubernetes cluster.
  2. Download the installation script sls-monitoring.sh.
  3. Run the following command to install the monitoring component:
    bash sls-monitoring.sh --project ${project} --aliuid ${aliuid} --instance-id ${instance-id} --cluster-id ${cluster-id} --action install --config-params ${config-params} --kube-state-metrics-image-name ${kube-state-metrics-image} --logtail-image-name ${logtail-image}

    Configuration example:

    bash sls-monitoring.sh --project k8s-log-c0ae5df1 --aliuid 165****50  --instance-id my-monitor --cluster-id my-k8s --action install --config-params cn-beijing --kube-state-metrics-image-name registry.cn-beijing.aliyuncs.com/log-service/kube-state-metrics --logtail-image-name registry.cn-beijing.aliyuncs.com/log-service/logtail

    The following table describes the parameters that are included in the command. You can configure the parameters based on your business requirements.

    Parameter Required Description
    ${project} Yes The name of the Log Service project. You must enter the name of the project that you select when you create the Full-stack Monitoring instance. For more information, see Create an instance.
    ${aliuid} Yes The ID of your Alibaba Cloud account. For more information, see Obtain the ID of an Alibaba Cloud account.
    ${instance-id} Yes The ID of the Full-stack Monitoring instance.
    ${cluster-id} Yes The ID of your Kubernetes cluster. The ID must meet the following requirements:
    • The ID can contain lowercase letters, digits, hyphens (-), and underscores (_).
    • The ID can be up to 24 characters in length.
    ${config-params} Yes Specify a value based on the region where your Log Service project resides and the type of the network for your project. For more information about regions, see Table 1.
    • If data is collected to your project over the Internet, specify the value in the region-internet format. For example, if your project resides in the China (Hangzhou) region, specify cn-hangzhou-Internet.
    • If data is collected to your project over an internal network of Alibaba Cloud, specify the value in the region format. For example, if your project resides in the China (Hangzhou) region, specify cn-hangzhou.
    ${kube-state-metrics-image} Yes The endpoint of the image for kube-state-metrics. Default value: registry.cn-beijing.aliyuncs.com/log-service/kube-state-metrics.
    Notice The default value is a public endpoint. If your cluster cannot access the Internet, you can enter an internal endpoint based on the region of the image. Example: registry-vpc.cn-hangzhou.aliyuncs.com/log-service/kube-state-metrics.
    ${logtail-image} Yes The endpoint of the image for Logtail. Default value: registry.cn-beijing.aliyuncs.com/log-service/logtail.
    Notice The default value is a public endpoint. If your cluster cannot access the Internet, you can enter an internal endpoint based on the region of the image. Example: registry-vpc.cn-hangzhou.aliyuncs.com/log-service/logtail.
    kube-state-metrics-image-tag No The label of the image for kube-state-metrics. Example: v1.6.0-f4ec1f70-aliyun.
    Note The default value varies based on the version of the release. You can view the default value in the sls-monitoring.sh script.
    logtail-image-tag No The label of the image for Logtail. Example: v1.0.27.0-7052198-aliyun.
    Note The default value varies based on the version of the release. You can view the default value in the sls-monitoring.sh script.
    logtail-cluster-limit-cpu No The CPU limit of the Logtail cluster. Example: 4000 m.
    logtail-cluster-limit-mem No The memory limit of the Logtail cluster. Example: 4096 Mi.
    logtail-nodeds-limit-cpu No The CPU limit of a Logtail node. Example: 200 m.
    logtail-nodeds-limit-mem No The memory limit of a Logtail node. Example: 384 Mi.
    kube-state-metrics-limit-cpu No The CPU limit of kube-state-metrics. Example: 1000 m.
    kube-state-metrics-limit-mem No The memory limit of kube-state-metrics. Example: 1024 Mi.

    After the sls-monitoring.sh script is run, Log Service automatically creates assets such as Metricstores. For more information, see Assets.

  4. Confirm the created Logtail configurations.
    1. Log on to the Log Service console.
    2. In the Projects list, click the project that you specify in Step 3.
    3. View Logtail configurations in the Logstores and Metricstores that are used.

      After the sls-monitoring.sh script is run, Log Service automatically creates four Logtail configurations. You can modify the configurations in the AliyunLogConfig Custom Resource Definitions (CRDs) in the sls-monitoring namespace. You can run the kubectl get aliyunlogconfig -n sls-monitoring command to query the CRDs.

      Logstore and Metricstore Logtail configuration
      {instance}-metas Logstore
      • {instance}__node-metas__{cluster}: used to collect configuration data from Kubernetes nodes.
      • {instance}__k8s-metas__{cluster}: used to collect configuration data from Kubernetes clusters.
      {instance}-node-metrics Metricstore {instance}__node-metrics__{cluster}: used to collect metric data from Kubernetes nodes.
      {instance}-k8s-metrics Metricstore {instance}__k8s-metrics__{cluster}: used to collect metric data from Kubernetes clusters.
  5. Log on to your Kubernetes cluster and confirm that the pods in the sls-monitoring namespace are all in the Running state.

Resources for the monitoring component

The Kubernetes resources that are used to collect Kubernetes monitoring data are all created in the sls-monitoring namespace. The resources include two Deployments, one DaemonSet, and four AliyunLogConfig CRDs.

Resource type Resource name Description
Deployment kube-state-metrics Used to listen to Kubernetes API operations to obtain the metric data of Kubernetes clusters.
logtail-kubernetes-metrics Used to collect metric data from the kube-state-metrics container to Log Service.
DaemonSet logtail-node-monitoring-ds Used to deploy the Logtail container in automatic mode. By default, Logtail runs on each node and collects the configuration data and metric data of the nodes.
AliyunLogConfig {instance-id}-k8s-metas Used to collect the configuration data of Kubernetes clusters. The data includes the name, namespace, label, image, and limit of each Deployment, pod, Ingress, and Service. By default, the collected data is stored in a Logstore named {instance}-metas.
{instance-id}-k8s-metrics Used to collect the metric data of Kubernetes clusters. The data includes the CPU, memory, and network data of pods and containers. By default, the collected data is stored in a Metricstore named {instance}-k8s-metrics.
{instance-id}-node-metas Used to collect the configuration data of Kubernetes nodes. The data includes CPU models and memory sizes. By default, the collected data is stored in a Logstore named {instance}-metas.
{instance-id}-node-metrics Used to collect the metric data of Kubernetes nodes. The data includes CPU utilization and memory usage. By default, the collected data is stored in a Metricstore named {instance}-node-metrics.

What to do next

After Kubernetes monitoring data is collected to Log Service, the Full-stack Monitoring application automatically creates dedicated dashboards for the monitoring data. You can use the dashboards to analyze the monitoring data. For more information, see View dashboards.