1. 程式人生 > >在istio中部署非all-in-one的jaeger

在istio中部署非all-in-one的jaeger

本文基於istion 1.0.4版本,並且置tracing.enable=true的情況下部署istio環境。 然後去部署非all-in-one的jaeger,jaeger版本為1.7,使用elasticsearch作為儲存。

在istion中集成了all-in-one的jaeger(pod:istion-tracing-xxxxx, service:tracing)。同時istion中也部署了jaeger-agent, jaeger-collector, jaeger-query這三個service.

部署非all-in-one的jaeger之前,先修改istion-tracing deployment中的replicas為0,以便刪除目前部署好的all-in-one的pod。

然後開始部署jaeger:

         1. 部署configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: jaeger-configuration
  namespace: kube-system
  labels:
    app: jaeger
    jaeger-infra: configuration
data:
  span-storage-type: elasticsearch
  collector: |
    es:
      server-urls: http://elasticsearch:9200
      username: elastic
      password: changeme
    collector:
      zipkin:
        http-port: 9411
  query: |
    es:
      server-urls: http://elasticsearch:9200
      username: elastic
      password: changeme

2. elasticsearch

        非all-in-one的jaeger使用elasticsearch作為儲存。

        部署elasticsearch statefulset:

apiVersion: apps/v1beta1
  kind: StatefulSet
  metadata:
    name: elasticsearch
    namespace: kube-system
    labels:
      app: jaeger
      jaeger-infra: elasticsearch-statefulset
  spec:
    serviceName: elasticsearch
    replicas: 1
    template:
      metadata:
        labels:
          app: jaeger-elasticsearch
          jaeger-infra: elasticsearch-replica
      spec:
        containers:
          - name: elasticsearch
            image: docker.elastic.co/elasticsearch/elasticsearch:5.6.0
            imagePullPolicy: Always
            command:
              - bin/elasticsearch
            args:
              - "-Ehttp.host=0.0.0.0"
              - "-Etransport.host=127.0.0.1"
            volumeMounts:
              - name: data
                mountPath: /data
            readinessProbe:
              exec:
                command:
                - curl
                - --fail
                - --silent
                - --output
                - /dev/null
                - --user
                - elastic:changeme
                - localhost:9200
              initialDelaySeconds: 5
              periodSeconds: 5
              timeoutSeconds: 4
        volumes:
          - name: data
            emptyDir: {}

 部署elasticsearch service:

  apiVersion: v1
  kind: Service
  metadata:
    name: elasticsearch
    namespace: kube-system
    labels:
      app: jaeger
      jaeger-infra: elasticsearch-service
  spec:
    clusterIP: None
    selector:
      app: jaeger-elasticsearch
    ports:
    - port: 9200
      name: elasticsearch
    - port: 9300
      name: transport

    3. jaeger-agent
        部署deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: istio-tracing-agent
  namespace: kube-system
  labels:
    app: istio-tracing-agent
    chart: tracing-agent-0.1.0
    release: istio
    heritage: Tiller
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: istio-tracing-agent
      annotations:
        sidecar.istio.io/inject: "false"
        scheduler.alpha.kubernetes.io/critical-pod: ""
    spec:
      containers:
        - name: jaeger-agent
          image: jaegertracing/jaeger-agent:latest
          ports:
            - containerPort: 5778
              protocol: TCP
            - containerPort: 5775
              protocol: UDP
            - containerPort: 6831
              protocol: UDP
            - containerPort: 6832
              protocol: UDP
          command:
            - "/go/bin/agent-linux"
            - "--collector.host-port=jaeger-collector.kube-system.svc.cluster.local:14267"

           修改jaeger-agent service中的selector值為 app: istio-tracing-agent

          4.jaeger-collector

           部署jaeger-collector deployment:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: istio-tracing-collector
  namespace: kube-system
  labels:
    app: istio-tracing-collector
    chart: tracing-collector-0.1.0
    release: istio
    heritage: Tiller
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: istio-tracing-collector
      annotations:
        sidecar.istio.io/inject: "false"
        scheduler.alpha.kubernetes.io/critical-pod: ""
    spec:
      containers:
      - image: jaegertracing/jaeger-collector:latest
        name: jaeger-collector
        args: ["--config-file=/conf/collector.yaml"]
        ports:
        - containerPort: 14267
          protocol: TCP
        - containerPort: 14268
          protocol: TCP
        - containerPort: 9411
          protocol: TCP
        readinessProbe:
          httpGet:
            path: "/"
            port: 14269
        volumeMounts:
        - name: jaeger-configuration-volume
          mountPath: /conf
        env:
        - name: SPAN_STORAGE_TYPE
          valueFrom:
            configMapKeyRef:
              name: jaeger-configuration
              key: span-storage-type
      volumes:
        - configMap:
            name: jaeger-configuration
            items:
              - key: collector
                path: collector.yaml
          name: jaeger-configuration-volume

        修改jaeger-collector service中的selector值為 app: istio-tracing-collector

        5. jaeger-query

           部署jaeger-query deployment:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: istio-tracing-query
  namespace: kube-system
  labels:
    app: istio-tracing-query
    chart: tracing-query-0.1.0
    release: istio
    heritage: Tiller
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: istio-tracing-query
      annotations:
        sidecar.istio.io/inject: "false"
        scheduler.alpha.kubernetes.io/critical-pod: ""
    spec:
      containers:
      - image: jaegertracing/jaeger-query:latest
        name: jaeger-query
        args: ["--config-file=/conf/query.yaml"]
        ports:
        - containerPort: 16686
          protocol: TCP
        readinessProbe:
          httpGet:
            path: "/"
            port: 16687
        volumeMounts:
        - name: jaeger-configuration-volume
          mountPath: /conf
        env:
        - name: SPAN_STORAGE_TYPE
          valueFrom:
            configMapKeyRef:
              name: jaeger-configuration
              key: span-storage-type
      volumes:
        - configMap:
            name: jaeger-configuration
            items:
              - key: query
                path: query.yaml
          name: jaeger-configuration-volume

          修改jaeger-query service中的selector值為 app: istio-tracing-query

          由於istio中的all-in-one jaeger集成了spark-dependencies, 因此 部署非all-in-one的jaeger 需要手動再部署spark-dependencies. 

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: jaeger-spark-dependencies-cronjob
spec:
  schedule: "*/10 * * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 2
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: jaeger-spark-dependencies-cronjob
            image: jaegertracing/spark-dependencies:latest
            env:
              - name: STORAGE
                value: elasticsearch
              - name: ES_NODES
                value: elasticsearch:9200
              - name: ES_USERNAME
                value: elastic
              - name: ES_PASSWORD
                value: changeme
          restartPolicy: Never

         如果istio中使用了virtalservices, 並且暴露了jaeger-query至公共的URL。 則需要修改virtalservices的配置。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: mgmt-api-vs-dev
  namespace: dev
spec:
  hosts:
  - jqeger-query.xxx.xxxx
  gateways:
  - istio-autogenerated-k8s-ingress
  http:
  - match:
    route:
    - destination:
        host: jaeger-query
        port:
          number: 443
      weight: 100

         需要注意的是route下的host的值為jaeger-service的name。