展開、ロギング、分散トレース、パフォーマンス、およびクラスターの状態を含む監視メトリックの完全なガイド。
こんにちは、Habr。「マイクロサービスアーキテクチャ」コースの一環として、資料の翻訳を用意しました。
また、「kafkaの例を使用した分散メッセージキュー」というトピックに関するオープンウェビナーにご招待します。
観察可能なマイクロサービスを探していますが、Kubernetesでそれらを実装する方法がまだわかりませんか?まあ...多分これはあなたが探していた記事です。
まず、可観測性とは何かを理解しましょう。この用語は、制御システムエンジニアリングに由来し、「外部出力に関する情報に基づいて、システムの内部状態をどれだけ適切に判断できるかを示す尺度」として定義されました。簡単に言えば、可観測性とは、是正措置を促進するためのシステムの適切な理解を意味します。
可観測性は3つの柱に基づいています。
() : , . (events) , .
(): /, . / .
: , . .
— Kubernetes?
— Kubernetes-
, .
, .
Weather-front: , . .
Weather-services: , API .
Weather-db: Maria, , .
(Deployment object) Kubernetes, — kubectl get deploy
.
, .
Weather-front:
- image: brainupgrade/weather:microservices-front imagePullPolicy: Always name: weather-front
Weather-services:
- image: brainupgrade/weather-services:2.0.0
imagePullPolicy: Always
name: weather-services
Weather-db:
- image: mariadb:10.3
name: mariadb
ports:
- containerPort: 3306
name: mariadb
— —
, EFK: Elasticsearch, Fluentd Kibana. .
Elasticsearch Kibana:
helm repo add elastic https://helm.elastic.co
helm repo update
helm install --name elasticsearch elastic/elasticsearch --set replicas=1 --namespace elasticsearch
helm install --name kibana elastic/kibana
Fluentd:
containers:
- name: fluentd
imagePullPolicy: "Always"
image: fluent/fluentd-kubernetes-daemonset:v1.12.0-debian-elasticsearch7-1.0
env:
- name: FLUENT_ELASTICSEARCH_HOST
value: "elasticsearch-master.elasticsearch.svc.cluster.local"
- name: FLUENT_ELASTICSEARCH_PORT
value: "9200"
Kibana, :
Fluentd (Fluentd Daemonset - 4):
Elasticsearch. Kibana:
«» , — .
— — ()
(distributed tracing) — Java-, Zipkin, Jaeger, Elasticsesarch APM . .
EFK, APM, Elasticsearch. -, APM Kubernetes Deployment.
Elastic APM:
containers:
- name: apm-server
image: docker.elastic.co/apm/apm-server:7.5.0
ports:
- containerPort: 8200
name: apm-port
APM , APM . , weather-front. weather-services.
APM weather-front:
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:
- image: brainupgrade/weather:microservices-front
imagePullPolicy: Always
name: weather-front
volumeMounts:
- mountPath: /elastic/apm/agent
name: elastic-apm-agent
env:
- name: ELASTIC_APM_SERVER_URL
value: "http://apm-server.elasticsearch.svc.cluster.local:8200"
- name: ELASTIC_APM_SERVICE_NAME
value: "weather-front"
- name: ELASTIC_APM_APPLICATION_PACKAGES
value: "in.brainupgrade"
- name: ELASTIC_APM_ENVIRONMENT
value: prod
- name: ELASTIC_APM_LOG_LEVEL
value: DEBUG
- name: JAVA_TOOL_OPTIONS
value: -javaagent:/elastic/apm/agent/elastic-apm-agent.jar
, Observability -> APM console Kibana, , ( 6).
, weather-front, :
, , , , (trace Sample) . .
, weather-front weather-services. Trace Sample, (transaction details).
Actions .
, «» .
— —
«», , APM, (Latency), (Throughput) (Error rate).
, Spring Boot Prometheus Actuator . Prometheus Grafana, :
Prometheus Grafana:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install --name prometheus prometheus-community/prometheus
helm install --name grafana grafana/grafana
Prometheus Grafana , :
template:
metadata:
labels:
app: weather-services
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8888"
prometheus.io/path: /actuator/prometheus
containers:
- image: brainupgrade/weather-services:2.0.0
imagePullPolicy: Always
name: weather-services
volumeMounts:
- mountPath: /elastic/apm/agent
name: elastic-apm-agent
env:
- name: management.endpoints.web.exposure.include
value: "*"
- name: spring.application.name
value: weather-services
- name: management.server.port
value: "8888"
- name: management.metrics.web.server.request.autotime.enabled
value: "true"
- name: management.metrics.tags.application
value: weather-services
Grafana, id 12685 , . weather-front: