Installing APM Insight PHP Agent and Data Exporter in Kubernetes using Init Containers

To monitor PHP applications deployed in Kubernetes using Applications Manager, both the APM Insight PHP Agent and the Applications Manager Data Exporter must be configured inside your pods. This can be accomplished by using init containers to copy the necessary agent files before the main application starts.

Step 1. Declare a Shared Volume

Create a shared volume that will be used by the init container to extract the agent files and make them accessible to the main application container.

volumes:
  - name: apminsight-volume

Step 2. Add Init Container

Use an init container to extract the APM Insight PHP Agent into the shared volume.

initContainers:
  - name: init-apminsight
    image: site24x7/apminsight-phpagent:latest
    imagePullPolicy: Always
    command: ["unzip", "/opt/apminsight.zip", "-d", "/opt"]
    volumeMounts:
      - name: apminsight-volume
        mountPath: /opt/apminsight

Step 3. Mount Volume and Configure Application Container

Mount the volume in your PHP application container, set environment variables, and run the installation script during the container’s lifecycle using the postStart hook.

containers:
- name: php-app
  image: my-php-app:8.2-alpine3.18-apache
  lifecycle:
    postStart:
      exec:
        command: ["/bin/sh", "-c", "chmod +x /apm/DockerInstallAgentPHP.sh && /apm/DockerInstallAgentPHP.sh && kill -USR1 1"]
  env:
    - name: APPMANAGER_LICENSE_KEY
      value: "your-license-key"
- name: ZPA_APPLICATION_NAME
      value: "name-for-your-application"
- name: APM_HOST
      value: "https:<apm_host>/<apm_port>"

  ports:
    - containerPort: 80
  volumeMounts:
    - mountPath: /apm
      name: apminsight-volume

Example Kubernetes Deployment YAML

The following is an example YAML configuration for deploying a PHP application integrated with the APM Insight PHP Agent and Applications Manager Data Exporter.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: php-app
spec:
  selector:
    matchLabels:
      app: php-app
  template:
    metadata:
      labels:
        app: php-app
    spec:
      volumes:
      - name: apminsight-volume
      initContainers:
      - name: init-apminsight
        image: site24x7/apminsight-phpagent:latest
        imagePullPolicy: Always
        command: ["unzip", "/opt/apminsight.zip", "-d", "/opt"]
        volumeMounts:
        - name: apminsight-volume
          mountPath: /opt/apminsight
      containers:
      - name: php-app
        image: my-php-app:8.2-alpine3.18-apache
        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh", "-c", "chmod +x /apm/DockerInstallAgentPHP.sh && /apm/DockerInstallAgentPHP.sh && kill -USR1 1"]
        env:
        - name: APPMANAGER_LICENSE_KEY
      value: "your-license-key"
- name: ZPA_APPLICATION_NAME
      value: "name-for-your-application"
- name: APM_HOST
      value: "https:<apm_host>/<apm_port>"

   ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /apm
          name: apminsight-volume

Service YAML

apiVersion: v1
kind: Service
metadata:
  name: php-app-service
spec:
  type: NodePort
  selector:
    app: php-app
  ports:
  - port: 8080
    targetPort: 80
    nodePort: 31000

 

Note:
  • The APM Insight PHP Agent and Applications Manager Data Exporter must be in the same container or volume-accessible environment.
  • Ensure your Kubernetes nodes have internet access to fetch the agent and exporter scripts.

Thank you for your feedback!

Was this content helpful?

We are sorry. Help us improve this page.

How can we improve this page?
Do you need assistance with this topic?
By clicking "Submit", you agree to processing of personal data according to the Privacy Policy.