更新时间:2024-11-21 GMT+08:00
分享

通过修改deployment.yaml接入APM

如果使用CCE或开源Kubernetes部署应用,可以通过修改deployment.yaml接入APM,即可在指标、调用链界面上查看应用情况。

前提条件

部署APM Agent时,必须确保接入APM的机器与APM服务网络连通,Agent才能正常工作。

可使用Telnet命令测试目标机器与APM服务器网络是否连通。例如,以检查华北-北京四区域的连通性为例,请登录应用所部署的机器,并输入命令telnet 100.125.12.108 41333,其他区域地址请参考探针接入地址

操作步骤

编辑deployment.yaml。

  1. 在volumes中增加一个emptyDir。

    volumes:
    - name: paas-apm2
       emptyDir: {}

  2. 在containers.volumeMounts中增加moutPath。

    volumeMounts:
    - name: paas-apm2
       mountPath: /paas-apm2/javaagent/

  3. 在env中增加JAVA_TOOL_OPTIONS环境变量。

    env:
    - name: JAVA_TOOL_OPTIONS
       value: '-javaagent:/paas-apm2/javaagent/apm-javaagent/apm-javaagent.jar'

  4. 新增initContainers。

    initContainers:
      - name: init-javaagent
        image: {swrAddress}/op_svc_apm/javaagent:{agentVersion}
        command:
          - /bin/sh
          - '-c'
          - cd /paas-apm2/javaagent/apm-javaagent; /bin/sh init-config.sh -master_address {masterAddress} -app_name {appName} -access_key {accessKey} -access_value {secretKey} -business {business} -env {env}
        resources:
          limits:
            cpu: 250m
            memory: 250Mi
           requests:
            cpu: 250m
            memory: 250Mi
         volumeMounts:
          - name: paas-apm2
            mountPath: /var/init/javaagent
         terminationMessagePath: /dev/termination-log
         terminationMessagePolicy: File
         imagePullPolicy: Always
         monitorGroup: default

参数说明

参数

参数说明

swrAddress

必填,探针镜像地址。组成方式为swr.{regionId}.myhuaweicloud.com,例如:上海一的swrAddress为swr.cn-east-3.myhuaweicloud.com。

agentVersion

必填,探针版本。参考JavaAgent更新说明,比如:2.4.8-x86_64。

masterAddress

必填,探针上报地址。参考探针接入地址,比如:上海一 https://100.125.4.27:41333。

appName

必填,组件名称。

accessKey

必填,APM上报AK,从APM控制台->系统管理->访问密钥获取

secretKey

必填,APM上报SK,从APM控制台->系统管理->访问密钥获取

business

选填,所属应用名称。

env

选填,环境名称,用于区分所属环境,可用于搜索和配置。

配置示例

spec:
  replicas: 1
  selector:
    matchLabels:
      app: vmall-admin
      version: v1
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: vmall-admin
        version: v1
    spec:
      volumes:
        - name: vol-171526714525730640
          hostPath:
            path: /vmall/vmall-deploy/vmall-data/app/vmall-admin/logs
            type: ''
        - name: paas-apm2
          emptyDir: {}
      initContainers:
        - name: init-javaagent
          image: swr.cn-north-4.myhuaweicloud.com/op_svc_apm/javaagent:2.4.8-x86_64
          command:
            - /bin/sh
            - '-c'
            - cd /paas-apm2/javaagent/apm-javaagent; /bin/sh init-config.sh -master_address https://100.125.12.108:41333 -app_name vmall-admin -access_key {AK} -access_value {SK} -business vmall-demo
          resources:
            limits:
              cpu: 250m
              memory: 250Mi
            requests:
              cpu: 250m
              memory: 250Mi
          volumeMounts:
            - name: paas-apm2
              mountPath: /var/init/javaagent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
          monitorGroup: default
      containers:
        - name: vmall-admin
          image: swr.cn-north-4.myhuaweicloud.com/vmall-org/vmall-admin:1.0.0
          env:
            - name: PAAS_APP_NAME
              value: vmall-admin
            - name: PAAS_NAMESPACE
              value: default
            - name: PAAS_PROJECT_ID
              value: e49731583bc54978aa7b4da1a2196e46
            - name: CLOUDDEPLOY_SYS_INCREMENT
              value: '1719279081896'
            - name: JAVA_TOOL_OPTIONS
              value: '-javaagent:/paas-apm2/javaagent/apm-javaagent/apm-javaagent.jar'
          resources:
            limits:
              cpu: '1'
              memory: 2Gi
            requests:
              cpu: 500m
              memory: 1Gi
          volumeMounts:
            - name: vol-171526714525730640
              mountPath: /var/logs
            - name: paas-apm2
              mountPath: /paas-apm2/javaagent/
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      imagePullSecrets:
        - name: default-secret
      schedulerName: default-scheduler
      tolerations:
        - key: node.kubernetes.io/not-ready
          operator: Exists
          effect: NoExecute
          tolerationSeconds: 300
        - key: node.kubernetes.io/unreachable
          operator: Exists
          effect: NoExecute
          tolerationSeconds: 300 

通过APM管理应用

应用启动后,等待3分钟应用数据就会呈现在APM界面中,此时登录APM,您可以在APM进行应用性能优化,详细操作请参考《应用性能管理 用户指南 (2.0)》

相关文档