Install the Node.js agent in ACK and ACS clusters by using the ack-onepilot component
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.
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
defaultnamespace. 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
Log on to the ACK console. In the cluster list, click the cluster for which you want to enable Application Monitoring.
In the left-side navigation pane, click Components and Add-ons. Search for
ack-onepilot.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.
NoteFor ACS clusters, set
accessKeyandaccessKeySecretin 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 |
|
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 |
|
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: |
|
ACK managed clusters
First, check whether the cluster has an ARMS Addon Token.
In the target cluster, choose Configurations > Secrets.
Set the namespace to
kube-systemand search foraddon.arms.token.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.
Go to Cluster Information > Basic Information. In the Cluster Resources section, click Worker RAM role.
On the permissions page, add the
AliyunTracingAnalysisFullAccessandAliyunARMSFullAccesspolicies.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 | Edit only the Helm configuration of the component |
Configure by using a Secret | A Secret named | Create a Secret and edit the ack-onepilot Deployment |
Configure by using Helm
Go to the Applications > Helm page of the cluster and edit the ack-onepilot configuration.
Under the
controllerconfiguration, enteraccessKeyandaccessKeySecret.Save the configuration. After the component is updated, redeploy the business application.
Configure by using a Secret
In the namespace where ack-onepilot resides, create a Secret of the Opaque type named
ack-onepilot-aksk.Add two keys,
akandsk, to store the AccessKey ID and AccessKey secret respectively.Edit the ack-onepilot Deployment and set the following environment variables to reference the Secret.
Environment variable
Secret
Key
ONE_PILOT_ACCESSKEYack-onepilot-akskakONE_PILOT_ACCESSKEY_SECRETack-onepilot-akskskSave 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
Log on to the ACK console and open the target cluster.
Choose Workloads > Deployments, and find the target Node.js application.
Open the YAML configuration page of the application.
Existing application: Open the Edit YAML page of the application.
New application: Click Create from YAML.
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-languageThe language of the application. For Node.js applications, set this to
nodejs.armsPilotAutoEnableThe Application Monitoring switch. Set this to
"on".armsPilotCreateAppNameThe name of the application displayed in the Cloud Monitor 2.0 console. Replace this value with the name of your application.
armsPilotAppWorkspaceThe 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.
ImportantAdd the labels under
spec.template.metadata.labelsin the pod template. Adding labels only tometadata.labelsof 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.
If the application uses ECMAScript Modules (ESM), add the following label under
labelsat 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"Notealiyun.com/nodejs-module-typesupportscommonjsandesm. By default, the agent is loaded in CommonJS mode. For ESM applications, set this toesmso that the component configures both agent initialization and ESM module loading.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_OPTIONSenvironment variable to avoid overriding the agent loading parameters injected by the component.If you use
valueFromto setNODE_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'senv[].value.For startup parameters set through the image
ENVorenvFrom, explicitly specify them inenv[].valueso that the component retains the original parameters and appends the agent configuration.
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: IfNotPresentFor 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
After the application starts, send requests to the application APIs to generate request data.
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.Choose All Features > Application Observability > Application Insights.
In the application list, find the application specified by
armsPilotCreateAppNameand click the application name to view monitoring data such as instances, API calls, and traces.
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.