Updated on 2023-06-19 GMT+08:00

Connecting a Deployment Application to APM

Deployment is a workload that does not store any data or status. If you have deployed a Deployment application using Cloud Container Engine (CCE) or open-source Kubernetes, you can execute the configuration script to connect the application to APM and view its data on the topology and transaction pages.

Prerequisites

  • You have connected an Elastic Cloud Server (ECS) to a cluster by running the kubectl command. For details, see Connecting to a Cluster Using kubectl.
  • You have deployed an application using CCE or open-source Kubernetes.

Procedure

Step 1: Subscribe to APM

See Subscribing to APM and Buying a Package.

Step 2: Install the ICAgent

  • If the ICAgent is bound to CCE, skip this step.
  1. Obtain an Access Key ID/Secret Access Key (AK/SK).
  2. Log in to the APM console.
  3. In the navigation pane, choose Agent > Management.
  4. Click Install ICAgent. On the page that is displayed, set Host to HUAWEI CLOUD host and OS to Linux.
  5. Select the Obtain AK/SK installation mode, enter the obtained AK/SK in the text box to generate the ICAgent installation command, and click Copy Command.

    Ensure that the AK/SK are correct. Otherwise, the ICAgent cannot be installed.

  6. Remotely log in to the ECS server as the root user and run the preceding command to install the ICAgent.

    When the message "ICAgent install success" is displayed, the ICAgent is successfully installed in the /opt/oss/servicemgr/ directory.

(Optional) Step 3: Modify Permissions

If you start the program as a non-root user, run the following commands to modify the permissions on the probe file and output directory before enabling application monitoring:

chmod -R 777 /opt/oss/servicemgr/ICAgent/pinpoint/
mkdir -p /opt/apm-container 
chmod -R 777 /opt/apm-container 

Step 4: Enable Application Monitoring

  1. On the ECS or CCE, configure the startup script of the Deployment. Specifically, add the following information in bold to the YAML file.

    Run the following command to edit the YAML file:

    vi xxx.yaml
    xxx indicates the name of the description file customized when you create the Deployment application. The following provides an example. For more information about deployments, see Kubernetes documents.
    kind: Deployment 
    apiVersion: apps/v1 
    metadata: 
      name: user-service 
      namespace: default 
      selfLink: /apis/apps/v1/namespaces/default/deployments/user-service 
      uid: b231788d-9abd-11e8-80a5-fa163e3a2cc7 
      resourceVersion: '50972062' 
      generation: 13 
      creationTimestamp: '2018-08-08T03:46:56Z' 
      labels: 
        app: user-service 
        stack-name: auto-test 
      annotations: 
        deployment.kubernetes.io/revision: '5' 
        description: '' 
      enable: true 
    spec: 
      replicas: 1 
      selector: 
        matchLabels: 
          app: user-service 
      template: 
        metadata: 
          creationTimestamp: null 
          labels: 
            app: user-service 
          enable: true 
        spec: 
          #External mount directory of the container, including the data output path and Java probe package path.
          volumes: 
            - name: paas-apm 
              hostPath:  
                path: /opt/apm-container 
            - name: pinpoint-pkg 
              hostPath:  
                path: /opt/oss/servicemgr/ICAgent/pinpoint 
          containers: 
            - name: user-service 
              image: '100.125.0.198:20202/zhyyy/user-service:v1' 
              ports: 
                - containerPort: 8080 
                  protocol: TCP 
              env: 
                - name: PAAS_APP_NAME 
                  # Workload name (service name).
                  value: user-service 
                - name: PAAS_NAMESPACE 
                  #CCE cluster namespace. For a non-CCE cluster, this parameter is left blank.
                  value: default 
                - name: PAAS_PROJECT_ID 
                  #Tenant's project ID.
                  value: d698369a975645bfb35f8437d11c5a12 
                - name: PAAS_CLUSTER_ID 
                  #CCE cluster ID, which can be queried by pressing F12 on the CCE console. For a non-CCE cluster, this parameter is left blank.
                  value: 89b49857-5433-11e8-941c-0255ac101f3e 
                 - name: PAAS_POD_ID
                               valueFrom:
                                 fieldRef:
                                   fieldPath: metadata.uid
                - name: PAAS_MONITORING_GROUP 
                 # Application name (monitoring group). You are advised to set the same application name for the services that fulfill the same function.
                  value: shoppingmall 
                - name: JAVA_TOOL_OPTIONS 
                  value: -javaagent:/opt/oss/servicemgr/ICAgent/pinpoint/pinpoint-bootstrap.jar -Dapm_container=true 
              resources: {} 
             #Internal mount directory of the container, including the data output path and Java probe package path.
              volumeMounts: 
                - name: paas-apm 
                  mountPath: /paas-apm/collectors/pinpoint 
                - name: pinpoint-pkg 
                  mountPath: /opt/oss/servicemgr/ICAgent/pinpoint 
    
              terminationMessagePath: /dev/termination-log 
              terminationMessagePolicy: File 
              imagePullPolicy: Always 
          restartPolicy: Always 
          terminationGracePeriodSeconds: 30 
          dnsPolicy: ClusterFirst 
          securityContext: {} 
          schedulerName: default-scheduler 
      strategy: 
        type: RollingUpdate 
        rollingUpdate: 
          maxUnavailable: 0 
          maxSurge: 1 
      revisionHistoryLimit: 10 
      progressDeadlineSeconds: 600 
    status: 
      observedGeneration: 13 
      replicas: 1 
      updatedReplicas: 1 
      readyReplicas: 1 
      availableReplicas: 1 
      conditions: 
        - type: Progressing 
          status: 'True' 
          lastUpdateTime: '2018-09-02T13:25:46Z' 
          lastTransitionTime: '2018-08-08T03:46:56Z' 
          reason: NewReplicaSetAvailable 
          message: ReplicaSet "user-service-f584f46b7" has successfully progressed. 
        - type: Available 
          status: 'True' 
          lastUpdateTime: '2018-12-21T11:01:33Z' 
          lastTransitionTime: '2018-12-21T11:01:33Z' 
          reason: MinimumReplicasAvailable 
          message: Deployment has minimum availability.
  2. Restart the application using the modified script, and enable application performance monitoring.

Step 5: Manage the Application on APM

Three minutes after the application is started, its data will be displayed on the APM console. You can log in to the APM console and optimize application performance through topology and tracing. For details, see APM User Guide.