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
- The application name and application port details
Integration steps
Step 1: Create an empty volume
Create and define an empty volume that will be used to copy the agent files during the initContainers process:
volumes:
- name: agent-volume
emptyDir: {}
Step 2: Add initContainers to copy agent files
To configure your deployment, add the following initContainers specification to your Helm chart or deployment YAML file:
initContainers:
- name: init-apm
image: site24x7/apminsight-nextjsagent:1.2.0
imagePullPolicy: Always
command: ['cp', '-r', '/opt/site24x7/.', '/apm']
volumeMounts:
- name: agent-volume
mountPath: /apm
Step 3: Mount the volume in the application container
Mount the volume created in step 2 into your application container.
Example
containers:
env:
- name: NODE_OPTIONS
value: "--require /apm/node_modules/@apminsight/next"
- name: APMINSIGHT_LICENSE_KEY
value: "xxxxxxxxxxxxxxxx"
- name: APMINSIGHT_APP_NAME
value: "k8s-nextjs-application"
- name: APMINSIGHT_APP_PORT
value: "3001"
volumeMounts:
- name: agent-volume
mountPath: /apm

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 file:
- name: APMINSIGHT_PROCESS_MANAGER
value: "true"
Example
Here's a sample YAML deployment file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nextjs-app
namespace: nextjs
labels:
app: nextjs-app
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: nextjs-app
template:
metadata:
labels:
app: nextjs-app
version: v1
spec:
initContainers:
- name: init-apm
image: site24x7/apminsight-nextjsagent:1.2.0
imagePullPolicy: Always
command: ['cp', '-r', '/opt/site24x7/.', '/apm']
volumeMounts:
- name: agent-volume
mountPath: /apm
containers:
- name: nextjs-app
image: nextjs-sampleapp:latest
ports:
- containerPort: 3001
name: http
env:
- name: NODE_OPTIONS
value: "--require /apm/node_modules/@apminsight/next"
- name: APMINSIGHT_LICENSE_KEY
value: "xxxxxxxxxxxxxxxx"
- name: APMINSIGHT_APP_NAME
value: "k8s-nextjs-application"
- name: APMINSIGHT_APP_PORT
value: "3001"
imagePullPolicy: Always
volumeMounts:
- name: agent-volume
mountPath: /apm
volumes:
- name: agent-volume
emptyDir: {}
restartPolicy: Always
Related Articles
DC migration steps for APM Insight agents
For Server based installations 1. Obtain the new device key. 2. Update the license.key value in the APM Insight configuration file (or the environment variable mentioned) with the new device key. The location varies for each agent, as listed below: ...
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: ...
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 ...
DC migration steps for APM Insight Node.js agent
Obtain the new device key. Update the licenseKey value in the apminsighnode.json file located at the <application root directory>. Log in to the server and delete the existing instance information file apminsight.json located at <application root ...
Understanding automatic integration of Site24x7 APM and server monitors
Server and APM instance integration happens automatically in the Site24x7 console. Once integrated, the performance metrics of the integrated servers are displayed in the Server Metrics tab on the APM details page. During APM instance monitor ...