使用本地镜像缓存模式加速ack-onepilot接入

本文档介绍如何使用本地镜像缓存模式加速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. 登录容器服务管理控制台,在左侧导航栏选择集群列表

  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
  6. 无状态页面上,单击目标应用操作列的image > ARMS控制台即可查看应用监控详情。

    image