Setup Elastic APM with elasticsearch operator and test
Continue from the previous article, this one we will talk about how to install the APM server and setup sample application for test.
For the step of install via elasticsearch-operator, please check the post here. Step-by-step installation guide.
Before we start, need to check the CRD to make sure it is there.
command: kubectl get crd -n elasticsearch
NAME CREATED AT
apmservers.apm.k8s.elastic.co 2020-02-18T03:47:42Z
elasticsearches.elasticsearch.k8s.elastic.co 2020-02-18T03:47:42Z
eniconfigs.crd.k8s.amazonaws.com 2019-12-24T12:55:36Z
kibanas.kibana.k8s.elastic.co 2020-02-18T03:47:42Z
Then, create an APM YAML file
### elastic-apm.yaml
apiVersion: apm.k8s.elastic.co/v1
kind: ApmServer
metadata:
name: elastic-apm
namespace: elasticsearch
spec:
version: 7.6.0
count: 1
hostNetwork: true
http:
tls: ### for make it easy to test, let's disable tls for now
selfSignedCertificate:
disabled: true
config:
name: elastic-apm
apm-server:
jaeger.grpc.enabled: true
jaeger.http.enabled: true
rum.enabled: true
rum.event_rate.limit: 300
rum.event_rate.lru_size: 1000
rum.allow_origins: ['']
rum.library_pattern: "node_modules|bower_components|~"
rum.exclude_from_grouping: "^/webpack"
rum.source_mapping.enabled: true
rum.source_mapping.cache.expiration: 5m
rum.source_mapping.index_pattern: "apm--sourcemap*"
elasticsearchRef:
name: "elastic-operator"
Apply the elastic-apm.yaml file and Monitor APM Server deployment.
kubectl apply -f ./elastic-apm.yaml
apmserver.apm.k8s.elastic.co/elastic-apm createdkubectl get apmservers -n elasticsearch
NAME HEALTH NODES VERSION AGE
elastic-apm green 1 7.6.0 176m
Now, that deploys a sample-application for test APM
In this case, I will be using the application with elastic APM java agent
###sample-application.yaml
### kubectl apply -f sample-application.yaml---
apiVersion: apps/v1
kind: Deployment
metadata:
name: petclinic
namespace: elasticsearch
labels:
app: petclinic
service: petclinic
spec:
replicas: 1
selector:
matchLabels:
app: petclinic
template:
metadata:
labels:
app: petclinic
service: petclinic
spec:
dnsPolicy: ClusterFirstWithHostNet
###################### Shared volume and init container ##########################
volumes:
- name: elastic-apm-agent
emptyDir: {}
initContainers:
- name: elastic-java-agent
image: docker.elastic.co/observability/apm-agent-java:1.12.0
volumeMounts:
- mountPath: /elastic/apm/agent
name: elastic-apm-agent
command: ['cp', '-v', '/usr/agent/elastic-apm-agent.jar', '/elastic/apm/agent']
##################################################################################
containers:
- name: petclinic
image: eyalkoren/pet-clinic:without-agent
######################### Volume path and agent config ###########################
volumeMounts:
- mountPath: /elastic/apm/agent
name: elastic-apm-agent
env:
- name: ELASTIC_APM_SERVER_URL
value: "http://elastic-apm-apm-http.elasticsearch.svc.cluster.local:8200"
- name: ELASTIC_APM_SERVICE_NAME
value: "petclinic"
- name: ELASTIC_APM_APPLICATION_PACKAGES
value: "org.springframework.samples.petclinic"
- name: ELASTIC_APM_ENVIRONMENT
value: test
- name: ELASTIC_APM_LOG_LEVEL
value: DEBUG
- name: ELASTIC_APM_SECRET_TOKEN
valueFrom:
secretKeyRef:
name: elastic-apm-apm-token
key: secret-token
- name: JAVA_TOOL_OPTIONS
value: -javaagent:/elastic/apm/agent/elastic-apm-agent.jar
---
apiVersion: v1
kind: Service
metadata:
name: petclinic
namespace: elasticsearch
labels:
app: petclinic
spec:
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30001
selector:
service: petclinic
After creating the application, try to open the page to click on any pages to generate fake data.
kubectl port-forward svc/petclinic -n elasticsearch 8080:8080
Finally, get everything done. Now we can go look at the APM dashboard
For more details for the test application, please check the link
That’s it for now. Will see you next time