k8s 部署elasticsearch-apm

k8s 部署elasticsearch-apm

文档地址

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

说明

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

说以elasticsearch 和kibana 最好使用6.8 以上的版本

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
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
  generation: 1
  labels:
    app: elasticsearch-apm
  name: elasticsearch-apm
  namespace: platform-uat
spec:
  rules:
  - host: elasticsearch-apm.c80aaf74c1b654c4fa6ad0eb8a2f60539.cn-shanghai.alicontainer.com
    http:
      paths:
      - backend:
          serviceName: elasticsearch-apm
          servicePort: 8200
        path: /

执行

kubectl apply -f elasticsearch-apm-server.yaml

apm-agent 部署

agent 下载地址 https://search.maven.org/search?q=g:co.elastic.apm%20AND%20a: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 \
-jar <app-name>.jar

3. 配置 kibana

上一篇:如何更快地对复杂的应用程序进行故障排除?


下一篇:夜深了,写了个JQuery的省市区三级级联效果