Resource: 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: {}