Help Docs

Adding the APM Insight Java agent in a Kubernetes environment

There are two methods for installing the APM Insight Java agent in a Kubernetes environment.

Prerequisites

  1. Log in to Site24x7.
  2. Go to APM > APM Insight > Applications and click the Java icon.
  3. Click Download to obtain the APM Insight Java agent ZIP file (apminsight-javaagent.zip).
  4. Extract the ZIP file and locate the agent's JAR and configuration files.
  5. Open the apminsight.conf file in any text editor and include the license.key, application.name, and proxy details.

Adding the APM Insight Java agent in Kubernetes via Init Containers

These steps guide you through the process of integrating the APM Insight Java agent into your Kubernetes deployment using Init Containers.

Step 1: Create a secret for the Site24x7 license key

Create a secret for the Site24x7 license key in your application namespace.

Example:

kubectl create secret generic app-secret --from-literal=s247_license_key=<your_s247_license_key> -n petclinic

Replace app-secret, <your_s247_license_key>, and namespace (petclinic) with the appropriate values.

Note

You can obtain the license key from your Site24x7 account by navigating to Admin > Developer > Device Key.

Step 2: Create an empty volume

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

Example:

volumes:
- name: s247agent

Step 3: Include the InitContainers spec field

Include the following InitContainers command in your Helm chart/deployment YAML file.

initContainers:
- name: agent-copy
  image: site24x7/apminsight-javaagent:latest
  imagePullPolicy: IfNotPresent
  command: ['cp', '-r', '/opt/site24x7/.', '/home/apm']
  volumeMounts:
  - name: s247agent
    mountPath: /home/apm

Step 4: Mount the volume

Mount the volume created in step 2 into your application container.

Example:

containers:
- name: petclinic
  image: petclinic:latest
  imagePullPolicy: IfNotPresent
  ports:
  - containerPort: 8080
  volumeMounts:
  - name: s247agent
    mountPath: /home/apm

Step 5: Add environment variables

Add the following environment variables to application container.

Environment variable 1:

  • Name: S247_LICENSE_KEY
  • Value: s247_license_key from the secret added in step 1

Environment variable 2:

  • Name: JAVA_TOOL_OPTIONS
  • Value: "-javaagent:[mount/path]/apminsight-javaagent.jar -Dapminsight.application.name=[DesiredMonitorName]"

Example:

env:
- name: JAVA_TOOL_OPTIONS
  value: -javaagent:/home/apm/apminsight-javaagent.jar -Dapminsight.application.name=petclinic-k8s
- name: S247_LICENSE_KEY
  valueFrom:
    secretKeyRef:
      name: petclinic-secrets
      key: s247_license_key

In this step, we configure the arguments that the application (Java process) will use during startup and the agent to report data to the specified monitor name.

Example YAML deployment file for your reference

apiVersion: v1
kind: Namespace
metadata:
  name: petclinic

---
apiVersion: v1
kind: Secret
metadata:
  name: petclinic-secrets
  namespace: petclinic
type: Opaque
data:
  s247_license_key: OGQ3NTg0YmIxNWE1YTIzYjhmN35rfed2M1M2U3N2ExOTVhNzM1YWYyMg==

---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: petclinic
  name: petclinic-deployment
  labels:
    app: petclinic
spec:
  replicas: 2
  selector:
    matchLabels:
      app: petclinic
  template:
    metadata:
      labels:
        app: petclinic
    spec:
      containers:
      - name: petclinic
        image: petclinic:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
        env:
        - name: JAVA_TOOL_OPTIONS
          value: -javaagent:/home/apm/apminsight-javaagent.jar -Dapminsight.application.name=petclinic-k8s
        - name: S247_LICENSE_KEY
          valueFrom:
            secretKeyRef:
              name: petclinic-secrets
              key: s247_license_key
        volumeMounts:
        - name: s247agent
          mountPath: /home/apm
      initContainers:
      - name: agent-copy-init
        image: site24x7/apminsight-javaagent:latest
        imagePullPolicy: IfNotPresent
        command: ['cp', '-r', '/opt/site24x7/.', '/home/apm']
        volumeMounts:
        - name: s247agent
          mountPath: /home/apm
      volumes:
      - name: s247agent

---
apiVersion: v1
kind: Service
metadata:
  namespace: petclinic
  name: petclinic-service
spec:
  type: NodePort
  selector:
    app: petclinic
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
    nodePort: 30200

Adding the APM Insight Java agent via a Docker container

Follow the steps below to install the Java agent in a Docker container:

Note
Refer to this help page for detailed instructions with screenshots.
  1. Place all the agent files in the same local directory where your Dockerfile is located.
  2. Open the Dockerfile with any text editor, and copy all the APM Insight Java agent files to a directory inside the target container.
  3. Add -javaagent:[absolute_path_of_agent_jar]/apminsight-javaagent.jar (Java argument) to the startup command.
  4. Use the updated Dockerfile to create your container image.
  5. Once the image is ready, start your application by spawning containers using the Docker image you created.
  6. Once the application is up and receiving requests, view the monitor under APM > APM Insight > Applications.

How to install various APM Insight agents in a Docker container
Java | .NET | PHP | Node.js | Python

How to install various APM Insight agents in a Kubernetes environment
.NET | PHP | Node.js | Python

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!