01-elasticsearch-apm-server k8s 部署


k8s 部署elasticsearch-apm

文檔地址

官方文檔 https://www.elastic.co/guide/en/apm/index.html

說明

java agent 比需使用 6.5 版本以上的 apm-server

說以elasticsearch 和kibana 最好使用6.5 以上的版本

我這里使用的是6.8.7的版本

apm-server 部署

1. 創建apm-server 的配置文件

apm-server.docker.yml

apm-server:
  host: "0.0.0.0:8200"
output.elasticsearch:
  hosts: ["elasticsearch-client:9200"]

創建configmap

kubectl create cm elasticsearch-apm --from-file=apm-server.docker.yml --namespace=paltform-uat

2. 創建 apm-server

elasticsearch-apm-server.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
  labels:
    app: elasticsearch-apm
  name: elasticsearch-apm
  namespace: platform-uat
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: elasticsearch-apm
  template:
    metadata:
      labels:
        app: elasticsearch-apm
    spec:
      containers:
      - image: docker.elastic.co/apm/apm-server:6.8.7
        imagePullPolicy: IfNotPresent
        name: elasticsearch-apm
        ports:
        - containerPort: 8200
          protocol: TCP
        resources:
          limits:
            cpu: "1"
          requests:
            cpu: 25m
            memory: 512Mi
        volumeMounts:
        - mountPath: /usr/share/apm-server/apm-server.yml
          name: config
          subPath: apm-server.docker.yml
      volumes:
      - configMap:
          defaultMode: 420
          name: elasticsearch-apm
        name: config
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: elasticsearch-apm
  name: elasticsearch-apm
  namespace: platform-uat
spec:
  ports:
  - name: elasticsearch-apm
    port: 8200
    protocol: TCP
  selector:
    app: elasticsearch-apm

執行

kubectl apply -f elasticsearch-apm-server.yaml

apm-agent 部署

agent 下載地址 https://search.maven.org/search?q=g:co.elastic.apm AND a:elastic-apm-agent

在java 啟動參數下 添加

java \
-javaagent:/path/to/elastic-apm-agent-<version>.jar \
-Delastic.apm.service_name=my-cool-service \                                        #  需要修改成服務的名稱
-Delastic.apm.application_packages=org.example,org.another.example \    # 自定義作用暫時沒有發現
-Delastic.apm.server_urls=http://localhost:8200 \                                      #  需要修改成apm-server 的地址
-jar <app-name>.jar

3. 配置 kibana

  1. 在kibana 的 APM 菜單下 檢查server 的狀態

  2. 檢查agent 的 狀態。agent 狀態正常的情況下 Load Kibana objects

4. 查看 程序調用鏈信息

  1. 選擇java模塊
  2. 查看某個請求可以看到整體的調用鏈


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM