Help Docs

Adding the APM Insight PHP agent in Kubernetes via init containers

The below steps will guide you through the process of integrating the APM Insight PHP agent into your Kubernetes deployment using init containers.

Step 1:

Create an empty volume that will be used to copy the agent files during the init containers process.

volumes:
 - name: apminsight-volume

Step 2:

Include the following initContainers command in your helm chart or deployment YAML file:

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:

  1. Mount the volume created in step 1 into your application container.
  2. Add the following environment variables to application containers.
    • S247_LICENSE_KEY
    • ZPA_APPLICATION_NAME
  3. Run the installation script from the postStart life cycle hook and restart your web server.
    Note To restart the web server, use the command /etc/init.d/apache2 reload or kill -USR1 1 for Apache-based servers. If you are using NGINX- or FPM-based servers, include the command kill -USR2 1.
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: S247_LICENSE_KEY
      value: "your-license-key"
    - name: ZPA_APPLICATION_NAME
      value: "name-for-your-application" 
  ports:
    - containerPort: 80
  volumeMounts:
    - mountPath: /apm
      name: apminsight-volume

Example YAML deployment file for your reference:

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: S247_LICENSE_KEY
          value: "your-license-key"
        - name: ZPA_APPLICATION_NAME
          value: "name-for-your-application" 
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /apm
          name: apminsight-volume
---
apiVersion: v1
kind: Service
metadata:
 name: php-app-service
spec:
 type: NodePort
 selector:
  app: php-app
 ports:
 - port: 8080
   targetPort: 80
   nodePort: 31000

 

Was this document helpful?

Would you like to help us improve our documents? Tell us what you think we could do better.


We're sorry to hear that you're not satisfied with the document. We'd love to learn what we could do to improve the experience.


Thanks for taking the time to share your feedback. We'll use your feedback to improve our online help resources.

Shortlink has been copied!