全部產品
Search
文件中心

Application Real-Time Monitoring Service:使用本地鏡像緩衝模式加速ack-onepilot接入

更新時間:Feb 03, 2026

本文檔介紹如何使用本地鏡像緩衝模式加速ack-onepilot接入Java應用。

背景

預設條件下,為了保持應用接入的靈活性,ack-onepilot組件所注入的init-container會動態地根據規則拉取對應版本的探針包。但是在部分情境下,臨時動態拉取探針包可能會帶來問題:

  • 例如在邊緣情境下,網路品質較差,可能會導致探針包拉取的時間大幅延長,甚至因為逾時等原因導致探針包直接拉取失敗。

  • 在同時接入大量應用的情境下,可能會導致機器的IOPS上升,短時間內佔用機器較多的IO資源。

前提條件

  • ack-onepilot 不低於 5.1.0。

  • 應用接入語言為Java。

  • 接入探針版本大於等於4.2.5。

操作步驟

以下樣本YAML描述了K8s中一個簡單的Java應用如何使用本地鏡像緩衝模式加速ack-onepilot接入。

應用樣本YAML

apiVersion: v1
kind: Namespace
metadata:
  name: arms-demo
---
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: arms-springboot-demo
  namespace: arms-demo
  labels:
    app: arms-springboot-demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: arms-springboot-demo
  template:
    metadata:
      labels:
        app: arms-springboot-demo
        armsPilotAutoEnable: "on"
        armsPilotCreateAppName: "arms-k8s-demo"
        # 開啟本地鏡像緩衝模式,必填
        apsara.apm/enable-cached-agent: 'true'
        # 本地鏡像緩衝模式下,指定探針的版本,可以替換為使用者實際需要的探針版本
        aliyun.com/agent-version: 4.2.5
    spec:
      containers:
        - resources:
            limits:
              cpu: 0.5
          image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-springboot-demo:v0.1
          imagePullPolicy: Always
          name: arms-springboot-demo
          env:
            - name: SELF_INVOKE_SWITCH
              value: "true"
            - name: COMPONENT_HOST
              value: "arms-demo-component"
            - name: COMPONENT_PORT
              value: "6666"
            - name: MYSQL_SERVICE_HOST
              value: "arms-demo-mysql"
            - name: MYSQL_SERVICE_PORT
              value: "3306"
---
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: arms-springboot-demo-subcomponent
  namespace: arms-demo
  labels:
    app: arms-springboot-demo-subcomponent
spec:
  replicas: 2
  selector:
    matchLabels:
      app: arms-springboot-demo-subcomponent
  template:
    metadata:
      labels:
        app: arms-springboot-demo-subcomponent
        armsPilotAutoEnable: "on"
        armsPilotCreateAppName: "arms-k8s-demo-subcomponent"
        # 開啟本地鏡像緩衝模式,必填
        apsara.apm/enable-cached-agent: 'true'
        # 本地鏡像緩衝模式下,指定探針的版本,可以替換為使用者實際需要的探針版本
        aliyun.com/agent-version: 4.2.5
    spec:
      containers:
        - resources:
            limits:
              cpu: 0.5
          image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-springboot-demo:v0.1
          imagePullPolicy: Always
          name: arms-springboot-demo-subcomponent
          env:
            - name: SELF_INVOKE_SWITCH
              value: "false"
            - name: MYSQL_SERVICE_HOST
              value: "arms-demo-mysql"
            - name: MYSQL_SERVICE_PORT
              value: "3306"
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: arms-demo-component
  name: arms-demo-component
  namespace: arms-demo
spec:
  ports:
    # the port that this service should serve on
    - name: arms-demo-component-svc
      port: 6666
      targetPort: 8888
  # label keys and values that must match in order to receive traffic for this service
  selector:
    app: arms-springboot-demo-subcomponent
---
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: arms-demo-mysql
  namespace: arms-demo
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - resources:
            limits:
              cpu: 0.5
          image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-demo-mysql:v0.1
          name: mysql
          ports:
            - containerPort: 3306
              name: mysql
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: mysql
  name: arms-demo-mysql
  namespace: arms-demo
spec:
  ports:
    # the port that this service should serve on
    - name: arms-mysql-svc
      port: 3306
      targetPort: 3306
  # label keys and values that must match in order to receive traffic for this service
  selector:
    app: mysql
---
  1. 安裝ack-onepilot並為其授予正確的資源存取權限。具體操作,請參見安裝ARMS探針接入助手(ack-onepilot)

  2. 登入Container Service管理主控台,在左側導覽列選擇叢集列表

  3. 叢集列表頁面,單擊目的地組群名稱,然後在左側導覽列,選擇工作負載 > 無狀態

  4. 無狀態頁面的目標應用右側選擇image > YAML 編輯

    如需建立一個新應用,單擊使用YAML建立資源

  5. 在YAML檔案中將以下labels添加到spec.template.metadata層級下,然後單擊更新

    labels:
      armsPilotAutoEnable: "on"
      armsPilotCreateAppName: "arms-k8s-demo-subcomponent"
      # 開啟本地鏡像緩衝模式,必填
      apsara.apm/enable-cached-agent: 'true'
      # 本地鏡像緩衝模式下,指定探針的版本,可以替換為使用者實際需要的探針版本。發行的探針版本列表可以參考探針管理文檔。
      aliyun.com/agent-version: 4.2.5
      aliyun.com/app-language: java
  6. 無狀態頁面上,單擊目標應用操作列的image > ARMS控制台即可查看應用監控詳情。

    image