About observability of microservices in Kubernetes

A complete guide to deployment, logging, distributed tracing, performance, and monitoring metrics, including cluster health.

Hello, Habr. As part of the course "Microservice Architecture" we have prepared a translation of the material for you.



We also invite you to an open webinar on the topic
"Distributed message queues using the example of kafka."






Looking for observable microservices but don't yet know how to implement them with Kubernetes? Well ... maybe this is the article you were looking for.





First, let's understand what observability is. This term originated in control systems engineering and was defined as "a measure of how well the internal states of a system can be determined based on information about its external outputs." In simple terms, observability implies adequate understanding of the system to facilitate corrective action.





 Observability rests on three pillars:





  • () : , . (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:





, Grafana id 6417, - :






"Microservice Architecture".





Β« Β».








All Articles