# APM JAVA agent issue with kubernetes 1.14 \[Without Modifying Application Iamge\]

**URL:** <https://discuss.elastic.co/t/apm-java-agent-issue-with-kubernetes-1-14-without-modifying-application-iamge/243084>\
**Category:** APM\
**Tags:** docker, java\
**Created:** [July 29, 2020, 3:16pm UTC](https://discuss.elastic.co/t/apm-java-agent-issue-with-kubernetes-1-14-without-modifying-application-iamge/243084 "2020-07-29T15:16:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chopper20](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@chopper20](https://discuss.elastic.co/u/chopper20)\
**Post date:** [July 29, 2020, 3:16pm UTC](https://discuss.elastic.co/t/apm-java-agent-issue-with-kubernetes-1-14-without-modifying-application-iamge/243084/1 "2020-07-29T15:16:07Z")

</div>

Resource: [https://www.elastic.co/blog/using-elastic-apm-java-agent-on-kubernetes-k8s](https://www.elastic.co/blog/using-elastic-apm-java-agent-on-kubernetes-k8s)

I am following the above URL and configured application-deployment.yaml.I am facing issue in JAVA Agent. I am not running application jar in Docker instead extracting and copying files in Docker Image.

Error:  
Picked up JAVA\_TOOL\_OPTIONS: -javaagent:/elastic/apm/agent/elastic-apm-agent.jar  
Error occurred during initialization of VM  
agent library failed to init: instrument  
Error opening zip file or JAR manifest missing : /elastic/apm/agent/elastic-apm-agent.jar

DockerFile:

```
FROM openjdk:8-jre-alpine

RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' > 
/etc/nsswitch.conf

ENV AWS_DEFAULT_REGION=ap-south-1

EXPOSE 8080

ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/ /app
ADD /mypay_config/db_app_config/staging_config.yml /application.yml
ADD /src/main/resources/credential.properties /credential.properties
ADD /src/main/resources/application-staging.properties /application- 
staging.properties

CMD java -noverify -XX:TieredStopAtLevel=1 -Xms1g -Xmx1g - 
Dspring.config.location=file://./application.yml -Dspring.jmx.enabled=false -cp 
app:app/lib/* com.mypay.assuredpay.AssuredPayApplication -- 
spring.profiles.active=staging --logging.path=/var/log/mypay/ -- 
spring.properties.path=./ --api.ops.enabled=false

```

Application Deployment File

```
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: webapp
    spec:
      initContainers:
      - name: elastic-java-agent
        image: docker.elastic.co/observability/apm-agent-java:1.17.0
        volumeMounts:
        - name: elastic-apm-agent
          mountPath: /elastic/apm/agent
        command: ['cp', '-v', '/usr/agent/elastic-apm-agent.jar', '/elastic/apm/agent']
      containers:
      - name: webapp
        volumeMounts:
        - name: elastic-apm-agent
          mountPath: /elastic/apm/agent
        env:
        - name: AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
              name: aws-secret
              key: AWS_ACCESS_KEY_ID
        - name: AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: aws-secret
              key: AWS_SECRET_ACCESS_KEY
        - name: ELASTIC_APM_SERVER_URL 
          value: "http://apm-server.default.svc.cluster.local:8200"
        - name: ELASTIC_APM_SERVICE_NAME
          value: "stg-webapp"
        - name: ELASTIC_APM_APPLICATION_PACKAGES
          value: "com.mypay.assuredpay"
        - name: ELASTIC_APM_ENVIRONMENT 
          value: Staging
        - name: ELASTIC_APM_LOG_LEVEL
          value: INFO
        - name: JAVA_TOOL_OPTIONS
          value: -javaagent:/elastic/apm/agent/elastic-apm-agent.jar
        image: IMAGE
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /echo
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 120
          periodSeconds: 100
          successThreshold: 1
          timeoutSeconds: 60
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthcheck
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 120
          periodSeconds: 100
          successThreshold: 1
          timeoutSeconds: 60
        imagePullPolicy: Always
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "/mnt/prestop.sh"]

        resources:
          limits:
            cpu: 2000m
            memory: 2000Mi
          requests:
            cpu: 200m
            memory: 1000Mi
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: prestop-volume
          mountPath: /mnt
      volumes:
      - name: prestop-volume
        configMap:
          name: staging-prestop-script-config
      - name: elastic-apm-agent
        emptyDir: {}
```

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [July 30, 2020, 10:28am UTC](https://discuss.elastic.co/t/apm-java-agent-issue-with-kubernetes-1-14-without-modifying-application-iamge/243084/2 "2020-07-30T10:28:45Z")

</div>

Hi and welcome to the forum!

It looks like the application JVM can't find the agent jar in the specified path, although I can't why.  
I just verified that the `docker.elastic.co/observability/apm-agent-java:1.17.0` image is good.  
You need to verify that the agent jar is available in the right location for the JVM to read when it starts.  
Sorry I can't assist further...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 20, 2020, 6:28am UTC](https://discuss.elastic.co/t/apm-java-agent-issue-with-kubernetes-1-14-without-modifying-application-iamge/243084/3 "2020-08-20T06:28:50Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
