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

Add Node.js agent in Kubernetes via InitContainers (using prebuilt agent image)

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:4.8.0
  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.          volumeMounts:
  12.             - mountPath: /apm   
  13.         name: app-volume 

Notes
​For applications using the PM2 process manager instead of Kubernetes, enable PM2 support by adding the following in the env section of your deployment YAML:
  1. ​- name: APMINSIGHT_PROCESS_MANAGER
  2.   value: "true"

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:4.8.0
  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.           volumeMounts:
  36.             - mountPath: /apm   
  37.               name: app-volume
  38.       volumes:
  39.          - name: app-volume 
  40.       emptyDir: {}

    • Related Articles

    • APM Insight integration for Next.js in Kubernetes

      To integrate the Site24x7 APM Insight Next.js agent into your Kubernetes application using initContainers with the prebuilt agent image, follow the steps below: Prerequisites A Next.js application container image The Site24x7 APM Insight license key ...
    • Bundled .NET and .NET Core agents in a single MSI

      In APM Insight .NET agent version 6.8.0, the .NET and .NET Core agents have been bundled into a single MSI, enabling unified monitoring of both application types. Upgrade requirements for .NET Core agent 6.7 and below If you're using .NET Core agent ...
    • How to uninstall the Site24x7 Windows Server Monitoring Agent

      Method 1: To uninstall the Site24x7 Windows Server Monitoring Agent, click the link below: https://staticdownloads.site24x7.com/server/Site24x7WindowsAgentUninstall.zip Unzip and execute the Uninstall.bat file in the Command Prompt as an ...
    • How to identify and resolve conflicts between other APM products and the APM Insight .NET agent

      Problem statement: You are experiencing either of the below issues and suspect that another APM product is interfering with the Site24x7 .NET agent. 1. The .NET monitor is not created under APM > APM Insight > Applications, even after the .NET agent ...
    • Unable to add SQL insight monitor

      If the SQL Insight monitor is not getting added even after entering your credentials, try these troubleshooting steps: Ensure that the Auto-discover applications feature is enabled. If not, you will need to trigger discovery using the Discover ...