How to add an APM Insight Node.js agent in Kubernetes via InitContainers?

How to add an APM Insight Node.js agent in Kubernetes via InitContainers?

To integrate the APM Insight Node.js agent into your Kubernetes applications using InitContainers, follow the steps given below:

Step 1:
Create an empty volume that will be used to copy the agent files during the initContainers process.
Example:
  1. volumes:
  2.    - name: app-volume

Step 2:
Include the following initContainers command in your helm chart/deployment YAML file.
  1. initContainers:
  2.       - name: init-npm
  3.         image: site24x7/apminsight-nodejsagent:latest
  4.         imagePullPolicy: IfNotPresent
  5.         command: ['cp', '-r', '/opt/site24x7/.', '/apm']
  6.         volumeMounts:
  7.   - name: app-volume
  8.     mountPath: /apm

Step 3:
Mount the volume created in step 2 into your application container.
Example:
  1. containers:
  2.           env:
  3.             - name: NODE_OPTIONS
  4.               value: "--require /apm/node_modules/apminsight"
  5.             - name: APMINSIGHT_LICENSE_KEY
  6.               value: "<license-key>"
  7.             - name: APMINSIGHT_APP_NAME
  8.               value: "<application-name>"
  9.             - name: APMINSIGHT_APP_PORT
  10.               value: "<application-port>"
  11.             - name: APMINSIGHT_APM_HOST
  12.               value: "<manageengine-applications-manager-server-host>"
  13.             - name: APMINSIGHT_APM_PORT
  14.               value: "<manageengine-applications-manager-server-port>"
  15.          volumeMounts:
  16.             - mountPath: /apm   
  17.         name: app-volume 
Example YAML deployment file for your reference:
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4.   name: sample-deployment
  5. spec:
  6.   replicas: 1
  7.   selector:
  8.     matchLabels:
  9.       app: sample-app
  10.   template:
  11.     metadata:
  12.       labels:
  13.         app: sample-app
  14.     spec:
  15.       initContainers:
  16.       - name: init-npm
  17.         image: site24x7/apminsight-nodejsagent:latest
  18.         imagePullPolicy: IfNotPresent
  19.         command: ['cp', '-r', '/opt/site24x7/.', '/apm']
  20.         volumeMounts:
  21.              - name: app-volume
  22.                 mountPath: /apm

  23.       containers:
  24.         - name: main-container
  25.           image: myrepository/sample-nodejs-app:latest
  26.           env:
  27.             - name: NODE_OPTIONS
  28.               value: "--require /apm/node_modules/apminsight"
  29.             - name: APMINSIGHT_LICENSE_KEY
  30.               value: "<license-key>"
  31.             - name: APMINSIGHT_APP_NAME
  32.               value: "<application-name>"
  33.             - name: APMINSIGHT_APP_PORT
  34.               value: "<application-port>"
  35.             - name: APMINSIGHT_APM_HOST
  36.               value: "<manageengine-applications-manager-server-host>"
  37.             - name: APMINSIGHT_APM_PORT
  38.               value: "<manageengine-applications-manager-server-port>"
  39.           volumeMounts:
  40.             - mountPath: /apm   
  41.               name: app-volume
  42.       volumes:
  43.          - name: app-volume 
  44.       emptyDir: {}


                  New to ADSelfService Plus?

                    • Related Articles

                    • How to add an APM Insight Java agent in Kubernetes via InitContainers?

                      Step 1. Create a secret to access the APM Insight license key in your application namespace: kubectl create secret generic app-secret --from-literal=s247licensekey='your_APMInsight_license_key' -n petclinic The license key can be obtained from the ...
                    • Adding APM Insight Java agent in a Kubernetes environment

                      There are three methods for installing the APM Insight Java agent in a Kubernetes environment: Using Dockerfile Using InitContainers Using Persistent Volumes Prerequisites Download the latest APM Insight Java agent ZIP file. Extract the ZIP file and ...
                    • Uninstrumented Block of Code - APM Insight

                      In the traces tab --> Slowest Method Calls and Count we show if you find Un-instrumented block of code the reason is as follows: Basically, What is un-instrumented block of code in APM Insight? By default, APM Insight agent monitors known frameworks ...
                    • Unable to Add Kubernetes Monitor

                      If you are having trouble adding a Kubernetes monitor in Applications Manager, ensure that the the prerequisites have been met: Verify whether you can establish an SSH connection to the Kubernetes server from the APM installed machine. Use the ...
                    • APM Insight Java agent setup in K8s via Persistent Volumes

                      Prerequisites 1. A persistent volume (with a capacity of 100mb). 2. The persistent volume mounted on all deployment pods (via persistent volume claim). 3. The Applications Manager APM Insight Java agent zip file was downloaded, moved, and extracted ...