Skip to content

SevginGalibov/Elastic-APM-Kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bu proje hakkında Türkçe Dil için (docs/README.tr.md) dökümanlarına göz atın.

Elastic APM Setup on Kubernetes

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.


1. Create a Kubernetes Cluster

Use Kind to create a local Kubernetes cluster with the following command:

kind create cluster --config kind-ingress-config.yaml

Cluster Creation


2. Start Docker Compose Services

Ensure that all necessary services are running by starting Docker Compose:

docker compose up -d

Docker Compose Up


3. Create a Namespace for APM

Create a dedicated namespace for the APM server:

kubectl create ns apm

4. Configure and Deploy the APM Server

Edit the apm-server.yaml file to include your Elastic server details. Use the following command to edit the file:

nano apm-server.yaml

Edit APM Server Config

After editing the file, apply the APM server configuration to your Kubernetes cluster:

kubectl apply -f apm-server.yaml -n apm

APM Server Deployment


5. Access Information for APM Server

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

APM Server Access


6. Deploy Applications

Deploy test applications to the Kubernetes cluster.

  1. Create a namespace for the applications:

    kubectl create ns test
  2. 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

Application Deployment


7. Verify APM Data in Kibana

Once the applications are deployed, you can verify that the APM data is being collected by checking the APM section in Kibana.

Kibana APM Data


Summary

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published