This README provides a step-by-step guide to setting up Elastic APM on a Kubernetes cluster using Kind (Kubernetes in Docker), Docker Compose, and Kubernetes YAML configurations. It also includes details on how APM agents are initialized through Init Containers in the deployed applications. Follow the instructions below to get Elastic APM running and monitor your applications in Kibana.
Use Kind to create a local Kubernetes cluster with the following command:
kind create cluster --config kind-ingress-config.yaml
Ensure that all necessary services are running by starting Docker Compose:
docker compose up -d
Create a dedicated namespace for the APM server:
kubectl create ns apm
Edit the apm-server.yaml
file to include your Elastic server details. Use the following command to edit the file:
nano apm-server.yaml
After editing the file, apply the APM server configuration to your Kubernetes cluster:
kubectl apply -f apm-server.yaml -n apm
After deployment, your APM server can be accessed using the Kubernetes DNS service. The access details are as follows:
apm-server.apm.svc.cluster.local:8200
Deploy test applications to the Kubernetes cluster.
-
Create a namespace for the applications:
kubectl create ns test
-
Deploy the applications:
kubectl apply -f . -n test
Manifests contents:
apiVersion: apps/v1 kind: Deployment metadata: name: dotnetcore-sevgin spec: selector: matchLabels: app: dotnetcore-sevgin replicas: 1 template: metadata: labels: app: dotnetcore-sevgin spec: volumes: - name: elastic-apm-test emptyDir: {} initContainers: - name: elastic-dotnet-agent image: busybox command: ["/bin/sh","-c"] args: - wget -qO './elastic-apm-agent/ElasticApmAgent.zip' https://github.com/elastic/apm-agent-dotnet/releases/download/1.7.0/ElasticApmAgent_1.7.0.zip; cd elastic-apm-agent; cat ElasticApmAgent.zip | busybox unzip -; volumeMounts: - mountPath: /elastic-apm-agent name: elastic-apm-test containers: - name: dotnetcore-sevgin image: mcr.microsoft.com/dotnet/samples:aspnetapp ports: - containerPort: 80 volumeMounts: - mountPath: /elastic-apm-agent name: elastic-apm-test env: - name: DOTNET_STARTUP_HOOKS value: "/elastic-apm-agent/ElasticApmAgentStartupHook.dll" - name: ELASTIC_APM_SERVER_URLS value: "http://apm-server.apm.svc.cluster.local:8200" # Apm Server Address - name: ELASTIC_APM_SERVICE_NAME value: "SevginGalibov" # App Apm service name
apiVersion: apps/v1 kind: Deployment metadata: name: petclinic namespace: test labels: app: petclinic spec: replicas: 1 selector: matchLabels: app: petclinic template: metadata: labels: app: petclinic spec: dnsPolicy: ClusterFirstWithHostNet 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 volumeMounts: - mountPath: /elastic/apm/agent name: elastic-apm-agent env: - name: ELASTIC_APM_SERVER_URL value: "http://apm-server.apm.svc.cluster.local:8200" - name: ELASTIC_APM_SERVICE_NAME value: "Sample Java App" - name: ELASTIC_APM_APPLICATION_PACKAGES value: "org.springframework.samples.petclinic" - name: ELASTIC_APM_LOG_LEVEL value: DEBUG - name: JAVA_TOOL_OPTIONS value: -javaagent:/elastic/apm/agent/elastic-apm-agent.jar
Once the applications are deployed, you can verify that the APM data is being collected by checking the APM section in Kibana.
This guide walked you through setting up Elastic APM on a Kubernetes cluster, deploying applications, and verifying the APM data in Kibana. You are now ready to monitor your applications' performance and troubleshoot issues effectively.