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.
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:
- Mount the volume created in step 1 into your application container.
- Add the following environment variables to application containers.
- S247_LICENSE_KEY
- ZPA_APPLICATION_NAME
- 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
-
On this page
- Example YAML deployment file