Install the Node.js agent in ACK and ACS clusters by using the ack-onepilot component

Updated at:

The ack-onepilot component automatically installs the agent for Node.js applications that run in Container Service for Kubernetes (ACK) or Container Compute Service (ACS) clusters. You do not need to package the agent into your application image or modify the application startup command. You can then view monitoring data such as application topology, API calls, and traces in Cloud Monitor 2.0. This topic describes how to install the ack-onepilot component and enable Application Monitoring for Node.js applications by configuring application labels.

The ack-onepilot component prepares the agent and its integration configuration before an application starts. For Node.js applications, the component automatically loads the agent by using environment variables. For more information about how the component works, see ack-onepilot component fundamentals.

Note

This topic uses an ACK cluster as an example to describe the procedure. For ACS clusters, configure applications by following the same procedure. For the component authorization method, see Step 2: Grant access permissions to ARMS resources.

Prerequisites

  • An ACK or ACS cluster is created. For more information, see Create an ACK managed cluster or Create an ACS cluster.

  • The namespace in which the application resides is created. This topic uses the default namespace. For more information about namespace management, see Manage namespaces and quotas.

  • The Node.js version and dependencies used by the application are supported by the agent. For details about the supported scope, see Node.js components and frameworks supported by ARMS Application Monitoring.

  • The ack-onepilot version is 5.3.3 or later. If the component is not installed in the cluster or the installed version is earlier than 5.3.3, complete Step 1 first.

  • The current account has the cluster permissions and RAM permissions required to complete the operations in this topic, including installing or upgrading cluster components, modifying the permission policies of the Worker RAM role, editing the Helm configuration and Deployment of the component, and creating Secrets.

  • The Node.js agent is not manually loaded through code or startup parameters. If the agent is manually loaded, remove the existing loading configuration first to avoid repeated initialization.

Usage notes

  • The integration configuration takes effect when a new pod is created. Updating the application labels triggers a redeployment of the workload. Plan the change window accordingly.

  • When a pod contains multiple containers, the component injects Node.js loading parameters into each standard container in the pod. For pods that contain different languages or module types, deploy Node.js applications separately.

Step 1: Install the ack-onepilot

  1. Log on to the ACK console. In the cluster list, click the cluster for which you want to enable Application Monitoring.

  2. In the left-side navigation pane, click Components and Add-ons. Search for ack-onepilot.

  3. Complete the following operations based on the installation status of the component.

    • ack-onepilot is not installed: Install ack-onepilot from the search results, configure the installation parameters based on your cluster environment, and confirm the installation. After the installation is complete, verify that the component version is 5.3.3 or later.

    • ack-onepilot is installed: Check the component version. The version must be 5.3.3 or later. If the version is earlier than 5.3.3, upgrade the component before you proceed with the subsequent steps.

    Note

    For ACS clusters, set accessKey and accessKeySecret in the component installation parameters. For the permission requirements and configuration methods of the credentials, see Step 2: Grant access permissions to ARMS resources.

Step 2: Grant access permissions to ARMS resources

The ack-onepilot component requires access to ARMS resources. Complete the authorization based on your cluster type. If the cluster already has the required authorization, you can directly enable monitoring for applications. Application monitoring data is viewed in the Cloud Monitor 2.0 console. The following table lists the authorization methods and required permission policies for each cluster type.

Cluster type

Authorization method

Required permission policies

ACK managed clusters

Use the ARMS Addon Token of the cluster. If the cluster does not have this token, add permission policies to the Worker RAM role

AliyunTracingAnalysisFullAccess and AliyunARMSFullAccess (added to the Worker RAM role)

ACK dedicated clusters and ACK One registered clusters

Configure an AccessKey pair for the component by using either the Helm configuration method or the Secret configuration method

AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess

ACK Serverless and ECI scenarios

Complete the authorization on the Cloud Resource Access Authorization page

—

ACS clusters

Set the component installation parameters of ack-onepilot: accessKey and accessKeySecret

AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess

ACK managed clusters

First, check whether the cluster has an ARMS Addon Token.

  1. In the target cluster, choose Configurations > Secrets.

  2. Set the namespace to kube-system and search for addon.arms.token.

  3. Complete the following operations based on the search result.

    • The Secret exists: The cluster can use Addon Token authorization. No additional configuration is required. You can proceed directly to Step 3.

    • The Secret is not found: Add permissions to the cluster role.

      1. Go to Cluster Information > Basic Information. In the Cluster Resources section, click Worker RAM role.

      2. On the permissions page, add the AliyunTracingAnalysisFullAccess and AliyunARMSFullAccess policies.

      3. Save the authorization configuration.

ACK dedicated clusters and ACK One registered clusters

Configure an AccessKey pair that has the AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess permissions for the component. You can use either of the following two methods. You do not need to configure both.

Configuration method

Credential storage location

Required operations

Configure by using Helm

In the component Helm configuration, under controller: accessKey and accessKeySecret

Edit only the Helm configuration of the component

Configure by using a Secret

A Secret named ack-onepilot-aksk, referenced by the environment variables of the Deployment

Create a Secret and edit the ack-onepilot Deployment

Configure by using Helm

  1. Go to the Applications > Helm page of the cluster and edit the ack-onepilot configuration.

  2. Under the controller configuration, enter accessKey and accessKeySecret.

  3. Save the configuration. After the component is updated, redeploy the business application.

Configure by using a Secret

  1. In the namespace where ack-onepilot resides, create a Secret of the Opaque type named ack-onepilot-aksk.

  2. Add two keys, ak and sk, to store the AccessKey ID and AccessKey secret respectively.

  3. Edit the ack-onepilot Deployment and set the following environment variables to reference the Secret.

    Environment variable

    Secret

    Key

    ONE_PILOT_ACCESSKEY

    ack-onepilot-aksk

    ak

    ONE_PILOT_ACCESSKEY_SECRET

    ack-onepilot-aksk

    sk

  4. Save the Deployment configuration. After the component is updated, redeploy the business application.

ACK Serverless and ECI scenarios

Go to the Cloud Resource Access Authorization page and complete the authorization. Then, restart the ack-onepilot pod.

ACS clusters

When you install ack-onepilot in Step 1, set the component installation parameters accessKey and accessKeySecret. The credentials must have the AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess permissions. To obtain the credentials, see Create an AccessKey pair. To grant the required permissions, see Grant permissions to a RAM user.

Step 3: Enable Application Monitoring for the Node.js application

  1. Log on to the ACK console and open the target cluster.

  2. Choose Workloads > Deployments, and find the target Node.js application.

  3. Open the YAML configuration page of the application.

    • Existing application: Open the Edit YAML page of the application.

    • New application: Click Create from YAML.

  4. Under spec.template.metadata.labels, add the following labels.

    labels:
      aliyun.com/app-language: nodejs
      armsPilotAutoEnable: "on"
      armsPilotCreateAppName: "nodejs-demo"
      armsPilotAppWorkspace: "workspace"

    Label

    Description

    aliyun.com/app-language

    The language of the application. For Node.js applications, set this to nodejs.

    armsPilotAutoEnable

    The Application Monitoring switch. Set this to "on".

    armsPilotCreateAppName

    The name of the application displayed in the Cloud Monitor 2.0 console. Replace this value with the name of your application.

    armsPilotAppWorkspace

    The target workspace to which the application monitoring data belongs. Set this label to the Workspace value in the integration configuration, and replace it with the name of your workspace. If this label is not configured, the default workspace is used.

    Important
    • Add the labels under spec.template.metadata.labels in the pod template. Adding labels only to metadata.labels of the Deployment does not enable monitoring for the application.

    • If the application is already configured with armsAutoInstrumentationEnable: "off", delete this label or change it to "on". Otherwise, the agent is not automatically loaded.

  5. If the application uses ECMAScript Modules (ESM), add the following label under labels at the same location. Use the same indentation level as the other integration labels. CommonJS applications do not require this configuration.

    labels:
      aliyun.com/nodejs-module-type: "esm"
    Note

    aliyun.com/nodejs-module-type supports commonjs and esm. By default, the agent is loaded in CommonJS mode. For ESM applications, set this to esm so that the component configures both agent initialization and ESM module loading.

  6. Verify that the configuration of the container environment variables and startup parameters does not affect agent injection.

    • The application startup script must retain the NODE_OPTIONS environment variable to avoid overriding the agent loading parameters injected by the component.

    • If you use valueFrom to set NODE_OPTIONS, the component skips the injection of agent loading parameters for the container. In this case, configure the non-sensitive startup parameters that you want to retain directly in the container's env[].value.

    • For startup parameters set through the image ENV or envFrom, explicitly specify them in env[].value so that the component retains the original parameters and appends the agent configuration.

  7. Save the configuration and wait for the new pod to start. For an existing application, click Update. For a new application, create the resource after the YAML configuration is complete.

The following example shows a complete Deployment configuration for a CommonJS application. Before you use this configuration, replace the placeholder values such as image, the application name (armsPilotCreateAppName), and the workspace (armsPilotAppWorkspace). For an existing application, retain the original resource, storage, and health check configurations, and add only the integration labels.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nodejs-demo
  namespace: default
  labels:
    app: nodejs-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nodejs-demo
  template:
    metadata:
      labels:
        app: nodejs-demo
        aliyun.com/app-language: nodejs
        armsPilotAutoEnable: "on"
        armsPilotCreateAppName: "nodejs-demo"
        armsPilotAppWorkspace: "workspace"
    spec:
      containers:
        - name: nodejs-demo
          image: your-registry/your-nodejs-app:your-tag
          imagePullPolicy: IfNotPresent

For ESM applications, add a label to spec.template.metadata.labels in the preceding example: aliyun.com/nodejs-module-type: "esm". The other integration labels remain unchanged.

View monitoring details

  1. After the application starts, send requests to the application APIs to generate request data.

  2. Log on to the Cloud Monitor 2.0 console and go to the workspace that you configured, which is the workspace specified by armsPilotAppWorkspace. If this label is not configured, go to the default workspace.

  3. Choose All Features > Application Observability > Application Insights.

  4. In the application list, find the application specified by armsPilotCreateAppName and click the application name to view monitoring data such as instances, API calls, and traces.

Note

If the application does not appear in the application list, check the following items in order: whether the application is redeployed and a new pod is generated after the label change, whether the ack-onepilot version is 5.3.3 or later, whether the ARMS authorization is completed for the cluster type, and whether the pod template is still configured with armsAutoInstrumentationEnable: "off", and whether NODE_OPTIONS is set by using valueFrom, which causes the component to skip the injection.

References