APM Insight integration for Next.js in Kubernetes

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 

  1. A Next.js application container image
  2. The Site24x7 APM Insight license key
  3. 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:
  1. volumes:
  2. - name: agent-volume
  3. 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:
  1. initContainers:
  2. - name: init-apm
  3. image: site24x7/apminsight-nextjsagent:1.2.0
  4. imagePullPolicy: Always
  5. command: ['cp', '-r', '/opt/site24x7/.', '/apm']
  6. volumeMounts:
  7. - name: agent-volume
  8. mountPath: /apm

Step 3: Mount the volume in the application container

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/next"
  5. - name: APMINSIGHT_LICENSE_KEY
  6. value: "xxxxxxxxxxxxxxxx"
  7. - name: APMINSIGHT_APP_NAME
  8. value: "k8s-nextjs-application"
  9. - name: APMINSIGHT_APP_PORT
  10. value: "3001"
  11. volumeMounts:
  12. - name: agent-volume
  13. mountPath: /apm

NotesFor 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:
  1. - name: APMINSIGHT_PROCESS_MANAGER
  2.   value: "true"

Example 

Here's a sample YAML deployment file:
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: nextjs-app
  5. namespace: nextjs
  6. labels:
  7. app: nextjs-app
  8. version: v1
  9. spec:
  10. replicas: 1
  11. selector:
  12. matchLabels:
  13. app: nextjs-app
  14. template:
  15. metadata:
  16. labels:
  17. app: nextjs-app
  18. version: v1
  19. spec:
  20.  initContainers:
  21.  - name: init-apm
  22. image: site24x7/apminsight-nextjsagent:1.2.0
  23. imagePullPolicy: Always
  24. command: ['cp', '-r', '/opt/site24x7/.', '/apm']
  25. volumeMounts:
  26. - name: agent-volume
  27. mountPath: /apm
  28. containers:
  29. - name: nextjs-app
  30. image: nextjs-sampleapp:latest
  31. ports:
  32. - containerPort: 3001
  33. name: http
  34. env:
  35. - name: NODE_OPTIONS
  36. value: "--require /apm/node_modules/@apminsight/next"
  37. - name: APMINSIGHT_LICENSE_KEY
  38. value: "xxxxxxxxxxxxxxxx"
  39. - name: APMINSIGHT_APP_NAME
  40. value: "k8s-nextjs-application"
  41. - name: APMINSIGHT_APP_PORT
  42. value: "3001"
  43. imagePullPolicy: Always
  44.  volumeMounts:
  45. - name: agent-volume
  46. mountPath: /apm
  47. volumes:
  48. - name: agent-volume
  49. emptyDir: {}
  50. restartPolicy: Always
    • Related Articles

    • Troubleshooting false positive alerts in monitoring

      Problem False positive alerts are being generated. Possible cause The monitoring system is down in some locations. The Website monitor might be configured for one location, such as Seattle, but may appear down when accessed from another location, ...
    • How to configure the NGINX status page for monitoring NGINX performance

      The NGINX plugin uses the NGINX status page to pull the performance metrics of the NGINX server. You may encounter the following errors while installing the NGINX plugin integration: Error_code : HTTP Error 404: This error usually indicates that the ...
    • Site24x7 Real User Monitoring (RUM) - Data Collection

      When you include Site24x7 RUM beacon script in your web pages, the following data is collected. All data that's being collected is in accordance with GDPR compliance. Performance details of web page load time - Metrics like response time of web page ...
    • Compare our various methodologies for Website Monitoring

      Get to know Site24x7 monitors better and choose the one that best fits your monitoring needs. Compare the functionality of the following monitors: Website Monitoring Webpage Speed (Browser) Web Transaction Monitoring Web Transaction (Browser) SSL/TLS ...