简体   繁体   中英

jaeger configuration in spring boot application when both of them are deployed on kubernetes

So, I am trying to trace logs of my spring boot application with jaeger so what are the steps that should be perform if my application and jaeger is deploy on kubernetes. I have successfully deployed jaeger and spring boot application now how will I configure jaeger in my service. My services are not visible in the jaegar console.

显示在我的 kubernetes 集群上运行的所有服务

I have added the following configuration to the yml:

opentracing.jaeger.udp-sender.host=localhost
opentracing.jaeger.udp-sender.port=6831
apiVersion: v1
kind: List
items:
- apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: jaeger
    labels:
      app: jaeger
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: all-in-one
  spec:
    replicas: 1
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          app: jaeger
          app.kubernetes.io/name: jaeger
          app.kubernetes.io/component: all-in-one
        annotations:
          prometheus.io/scrape: "true"
          prometheus.io/port: "16686"
      spec:
          containers:
          -   env:
              - name: COLLECTOR_ZIPKIN_HTTP_PORT
                value: "9411"
              image: jaegertracing/all-in-one
              name: jaeger
              ports:
                - containerPort: 5775
                  protocol: UDP
                - containerPort: 6831
                  protocol: UDP
                - containerPort: 6832
                  protocol: UDP
                - containerPort: 5778
                  protocol: TCP
                - containerPort: 16686
                  protocol: TCP
                - containerPort: 9411
                  protocol: TCP
              readinessProbe:
                httpGet:
                  path: "/"
                  port: 14269
                initialDelaySeconds: 5
- apiVersion: v1
  kind: Service
  metadata:
    name: jaeger-query
    labels:
      app: jaeger
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: query
  spec:
    ports:
      - name: query-http
        port: 80
        protocol: TCP
        targetPort: 16686
    selector:
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: all-in-one
    type: LoadBalancer
- apiVersion: v1
  kind: Service
  metadata:
    name: jaeger-collector
    labels:
      app: jaeger
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: collector
  spec:
    ports:
    - name: jaeger-collector-tchannel
      port: 14267
      protocol: TCP
      targetPort: 14267
    - name: jaeger-collector-http
      port: 14268
      protocol: TCP
      targetPort: 14268
    - name: jaeger-collector-zipkin
      port: 9411
      protocol: TCP
      targetPort: 9411
    selector:
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: all-in-one
    type: ClusterIP
- apiVersion: v1
  kind: Service
  metadata:
    name: jaeger-agent
    labels:
      app: jaeger
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: agent
  spec:
    ports:
    - name: agent-zipkin-thrift
      port: 5775
      protocol: UDP
      targetPort: 5775
    - name: agent-compact
      port: 6831
      protocol: UDP
      targetPort: 6831
    - name: agent-binary
      port: 6832
      protocol: UDP
      targetPort: 6832
    - name: agent-configs
      port: 5778
      protocol: TCP
      targetPort: 5778
    clusterIP: None
    selector:
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: all-in-one
- apiVersion: v1
  kind: Service
  metadata:
    name: zipkin
    labels:
      app: jaeger
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: zipkin
  spec:
    ports:
    - name: jaeger-collector-zipkin
      port: 9411
      protocol: TCP
      targetPort: 9411
    clusterIP: None
    selector:
      app.kubernetes.io/name: jaeger
      app.kubernetes.io/component: all-in-one

Output og kubectl get service jaeger-query

Name:                     jaeger-query
Namespace:                default
Labels:                   app=jaeger
                          app.kubernetes.io/component=query
                          app.kubernetes.io/name=jaeger
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"jaeger",
                            "app.kubernetes.io/component":"query","app.kuber...
Selector:                 app.kubernetes.io/component=all-in-one,app.kubernetes.io/name=jaeger
Type:                     LoadBalancer
IP:                       10.24.14.223
LoadBalancer Ingress:     35.222.40.241
Port:                     query-http  80/TCP
TargetPort:               16686/TCP
NodePort:                 query-http  30290/TCP
Endpoints:                10.20.2.7:16686
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

So the solution that works for me is - I have made the following changes in my application.properties file of application

opentracing.jaeger.udp-sender.host=http://<load_balancer_ip_of_jaeger_service>:<expose_port>(example ":80")
opentracing.jaeger.http-sender.url=http://<cluster_ip_or_load_balancer_ip_of jaeger_collector>:<expose_port>/api/traces(example of expose port ":1468")

You add opentracing-spring-jaeger-starter library into the project which simply contains the code needed to provide a Jaeger implementation of the OpenTracing's io.opentracing.Tracer interface.

Since you have the jaeger deployed in Kubernetes and exposed it via a loadbalancer service you can use the loadbalancer IP and port to connect to it from outside the Kubernetes cluster.

You should config:

opentracing.jaeger.udp-sender.host=jaeger-agent
opentracing.jaeger.udp-sender.port=6831

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM