After you install ack-onepilot and compile the Go binary file, Application Real-Time Monitoring Service (ARMS) monitors your Go application deployed in Container Service for Kubernetes (ACK) or Container Compute Service (ACS). Then, you can view the monitoring data, such as the application topology, interface calls, and database analysis data in the ARMS console. This topic describes how to install an ARMS agent for a Go application deployed in ACK or ACS.
If you have any questions while using an ARMS agent, join the DingTalk group chat (ID: 35568145) for technical support.
Prerequisites
An ACK or ACS cluster is created.
ACK cluster: You can create an ACK managed cluster, ACK dedicated cluster, or ACK Serverless cluster, or a registered cluster, based on your business requirements.
ACS cluster: For information about how to create an ACS cluster, see Create an ACS cluster.
A namespace is created in the cluster. For more information, see Manage namespaces and resource quotas. The namespace used in this example is default.
Check the operating system and architecture of the environment, and the versions of Go and frameworks. For more information, see Go components and frameworks supported by ARMS.
Procedure
The procedure for installing an ARMS agent for an application deployed in ACK is the same as that for an application deployed in ACS. The following uses the ACK environment as an example.
Step 1: Install ack-onepilot
Log on to the ACK console. On the Clusters page, click the name of the cluster.
In the left-side navigation pane, choose
. On the Add-ons page, enter ack-onepilot in the upper-right corner.ImportantMake sure that the ack-onepilot is V3.2.0 or later.
Click Install on the ack-onepilot card.
NoteBy default, the ack-onepilot component supports 1,000 pods. For every additional 1,000 pods in the cluster, you must add 0.5 CPU cores and 512 MB memory for the component.
In the dialog box that appears, configure the parameters and click OK. We recommend that you use the default values.
NoteAfter you install ack-onepilot, you can upgrade, configure, or uninstall it on the Add-ons page.
Step 2: Build a Go application image
If your project repository is managed by go mod vendor
, ensure your go.mod
file includes the google.golang.org/protobuf
dependency (either direct or indirect) and add the -mod=vendor
flag to your build command.
If google.golang.org/protobuf
is missing:
Import the following dependencies to your
main.go
file:_ "google.golang.org/protobuf/proto" _ "google.golang.org/protobuf/runtime/protoimpl"
Run the following commands to resolve dependencies:
go mod tidy go mod vendor
Method 1 (recommended): Manual image build
Run the
wget
command to download the compilation tool instgo based on the region where the environment and machine reside. Store instgo in a directory where you have the write permissions, because instgo triggers automatic updates during compilation.NoteThe compilation tool for Go, instgo, is provided by ARMS to help you monitor your Go applications.
If you are able to access Object Storage Service (OSS) over the Internet, you can directly use the public endpoint of the operating system and architecture in the China (Hangzhou) region to obtain the compilation tool.
Add executable permissions to the compilation tool.
Linux/Darwin
# Grant the permissions. chmod +x instgo
Windows
In Windows, you do not need to grant permissions.
(Optional) Configure the license key and build parameters.
ImportantIf you skip this step, instgo enters Dev mode and installs the ARMS agent of the latest version by default. To deploy the agent in a production environment, we recommend that you set the DescribeTraceLicenseKey parameter.
You can call an API operation to obtain the license key. For more information, see DescribeTraceLicenseKey.
After you obtain the license key, run the
set
command to set the compilation parameter.instgo set --licenseKey=${YourLicenseKey} --regionId=${YourRegionId} --dev=false
Add instgo as a prefix to your existing compilation command and run the following command:
instgo go build {arg1} {arg2} {arg3}
Use the binary file compiled in the previous step to build the image.
References
The first time that you compile the application, the ARMS agent is downloaded to the
/opt
directory (C:\ProgramData
in Windows) by default. If you have no permissions on the directory, you can use the--cacheDir
flag to specify a cache directory or run thesudo -E
command to compile the agent. In Windows, run commands to compile the application as an administrator.If the compilation is forcibly stopped or killed, a residue may be caused. For information about how to clean up the residue, see Uninstall an ARMS agent for Go.
Method 2: Non-intrusive image build
Replace base images in the Go binary build stage with ARMS build images for non-intrusive image build. ARMS provides multi-architecture (AMD64/ARM64) build images for both Alpine and Debian Linux.
Here's a sample Dockerfile for building Go images in stages:
# Stage 1
FROM golang:1.22-alpine3.19 as builder
RUN --mount=type=ssh \
go build -v -buildmode=pie -ldflags "-linkmode external -extldflags -static" \
-o /workspace/demo
# Stage 2
FROM alpine
COPY --from=builder /workspace/demo /demo
# The default startup command.
CMD ["/demo"]
Stages:
A Go binary file is created.
The binary file is copied to runtime images and built as the images for the Go application.
Replace Go base images with ARMS build images and retain other commands:
# Stage 1
# Use ARMS build images and retain other commands.
# Use the image in the target region.
FROM registry-cn-hangzhou.ack.aliyuncs.com/acs/golangbuilder-alpine-linux-amd64:0.0.1 as builder
RUN --mount=type=ssh \
go build -v -buildmode=pie -ldflags "-linkmode external -extldflags -static" \
-o /workspace/demo
# stage 2
FROM alpine
COPY --from=builder /workspace/demo /demo
# The default startup command.
CMD ["/demo"]
Step 3: Grant access permissions on ARMS resources
ACK managed cluster
If you don't have ARMS Addon Token in your ACK managed cluster, perform the following steps to authorize the ACK cluster to access ARMS. If you do have it, go to Step 4.
If a cluster has ARMS Addon Token, ARMS performs password-free authorization on the cluster. ARMS Addon Token may not exist in some ACK managed clusters. We recommend that you check whether an ACK managed cluster has ARMS Addon Token before you use ARMS to monitor applications in the cluster. If the cluster has no ARMS Addon Token, you must authorize the cluster to access ARMS.
ACK dedicated cluster/registered cluster
To monitor an application deployed in an ACK dedicated cluster or registered cluster, make sure that the AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess permissions are granted to the Alibaba Cloud account. For more information about how to grant permissions to a RAM user, see Grant permissions to a RAM user.
After installing the ack-onepilot component, enter the AccessKey ID and AccessKey secret of the Alibaba Cloud account in the configuration file of ack-onepilot.
In the left-side navigation pane, choose
. Then, click Update next to ack-onepilot.Replace
accessKey
andaccessKeySecret
with the AccessKey ID and AccessKey secret of the Alibaba Cloud account and click OK.NoteFor more information about how to obtain an AccessKey pair, see Create an AccessKey pair.
The AccessKey secret of an Alibaba Cloud account is displayed only when you create the AccessKey pair for the Alibaba Cloud account. You cannot query the AccessKey secret in subsequent operations. This helps reduce the risks of AccessKey pair leaks. Record the AccessKey secret and keep it confidential.
Restart the Deployment.
ASK/ECI cluster
To monitor applications in an ACK Serverless (ASK) cluster or applications in a Kubernetes cluster connected to Elastic Container Instance, you must first authorize the cluster to access ARMS on the Cloud Resource Access Authorization page. Then, restart all pods on which the ack-onepilot component is deployed.
Step 4: Enable Application Monitoring for the application
The following YAML template shows how to create a Deployment and enable Application Monitoring for the application:
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the page that appears, select the resource group and region where your cluster resides in the upper-left corner, and click the name of the cluster. Then, in the left-side navigation pane, click Workloads and choose either Deployments, StatefulSets, or DaemonSets, depending on your needs.
On the page that appears, find the application and choose
in the Actions column.To enable Application Monitoring for a new Go application, click Create from YAML on the Deployments page.
In the YAML file, add the following tags to
spec.template.metadata
:labels: aliyun.com/app-language: golang # Specify a Go application. armsPilotAutoEnable: 'on' armsPilotCreateAppName: "<your-deployment-name>" # Replace <your-deployment-name> with the Deployment name.
Verify the result
After about one minute, log on to the ARMS console. In the left-side navigation pane, choose . If the application is displayed on the Application List page, the application is being monitored.