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:
- volumes:
- - name: app-volume
Step 2:
Include the following initContainers command in your helm chart/deployment YAML file.
- initContainers:
- - name: init-npm
- image: site24x7/apminsight-nodejsagent:4.8.0
- imagePullPolicy: IfNotPresent
- command: ['cp', '-r', '/opt/site24x7/.', '/apm']
- volumeMounts:
- - name: app-volume
- mountPath: /apm
Step 3:
Mount the volume created in step 2 into your application container.
Example:
- containers:
- env:
- - name: NODE_OPTIONS
- value: "--require /apm/node_modules/apminsight"
- - name: APMINSIGHT_LICENSE_KEY
- value: "<license-key>"
- - name: APMINSIGHT_APP_NAME
- value: "<application-name>"
- - name: APMINSIGHT_APP_PORT
- value: "<application-port>"
- volumeMounts:
- - mountPath: /apm
- name: app-volume
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:
- - name: APMINSIGHT_PROCESS_MANAGER
- value: "true"
Example YAML deployment file for your reference:
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- name: sample-deployment
- spec:
- replicas: 1
- selector:
- matchLabels:
- app: sample-app
- template:
- metadata:
- labels:
- app: sample-app
- spec:
- initContainers:
- - name: init-npm
- image: site24x7/apminsight-nodejsagent:4.8.0
- imagePullPolicy: IfNotPresent
- command: ['cp', '-r', '/opt/site24x7/.', '/apm']
- volumeMounts:
- - name: app-volume
- mountPath: /apm
- containers:
- - name: main-container
- image: myrepository/sample-nodejs-app:latest
- env:
- - name: NODE_OPTIONS
- value: "--require /apm/node_modules/apminsight"
- - name: APMINSIGHT_LICENSE_KEY
- value: "<license-key>"
- - name: APMINSIGHT_APP_NAME
- value: "<application-name>"
- - name: APMINSIGHT_APP_PORT
- value: "<application-port>"
- volumeMounts:
- - mountPath: /apm
- name: app-volume
- volumes:
- - name: app-volume
- emptyDir: {}
Related Articles
Adding APM Insight Java agent in Kubernetes via InitContainers
Step 1: Create a secret for the Site24x7 license key in your application namespace. You can obtain the license key from your site24x7 account by navigating to Admin > Developer > Device Key. Example: kubectl create secret generic app-secret ...
How to deploy the Site24x7 PHP agent in a Kubernetes environment?
For PHP version 7.0 and above The PHP agent (PHP version 7.0 and above) can be deployed in a Kubernetes environment using any of the following methods. You can also keep the license keys in a configmap to avoid using them in the deployment files. ...
Prerequisites for Node.js agent installation
For a smooth Node.js agent installation, ensure that you've fulfilled the following prerequisites. The environment should have node version 16.20.2 or above installed. The application user should have full permission to access the agent directory. ...
Managing Node.js applications using PM2 Process Manager
Configure PM2 to manage standalone applications Follow the instructions below to configure PM2 to manage Node.js applications. Steps to configure PM2 Configure the processManagerEnabled key in the already created apminsightnode.json file. Pass the ...
How to enable Kubernetes monitoring on clusters that have arm-based nodes
If you would like to add a Kubernetes monitor for your clusters that have arm-based nodes, ensure that you have followed the steps below: Download the latest site24x7-agent.yaml file from the Site24x7 web console. Replace the image name ...