10.7.1 集成部署

首先,替换Istio自身包含的Zipkin服务定义,使用如下新的YAML定义一个对外部Zipkin兼容的服务,如下所示:


apiVersion: v1
kind: Service
metadata:
  name: zipkin
  namespace: istio-system
spec:
  ports:
    - name: zipkin-rest
      port: 9411
      protocol: TCP
      targetPort: 9411
  selector:
    app: external-zipkin
  sessionAffinity: None
  type: ClusterIP

上述内容保存为文件zipkin-service.yaml,运行以下命令创建服务:


kubectl apply -n istio-system -f zipkin-service.yaml

该服务所需定义的关联部署及其引用到的配置项定义如下所示,其中在配置项中需要指定连接Zipkin v1 API的端点地址,如http://ip:9411/api/v1/spans等:


apiVersion: v1
kind: ConfigMap
metadata:
  name: external-zipkin-nginx-conf
data:
  nginx.conf: |
    user nginx;
    worker_processes  3;
    error_log  /var/log/nginx/error.log;
    events {
      worker_connections  10240;
    }
    http {
      log_format  main
              'remote_addr:$remote_addr\t'
              'time_local:$time_local\t'
              'method:$request_method\t'
              'uri:$request_uri\t'
              'host:$host\t'
              'status:$status\t'
              'bytes_sent:$body_bytes_sent\t'
              'referer:$http_referer\t'
              'useragent:$http_user_agent\t'
              'forwardedfor:$http_x_forwarded_for\t'
              'request_time:$request_time';
      access_log  /var/log/nginx/access.log main;
      server {
          listen       9411;
          server_name  _;
          location / {
              root   html;
              index  index.html index.htm;
          }
          
          location /api/v1/spans {
              proxy_pass {{zipkin.v1.span.api.endpoint}};
          }
      }
    }
  
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: external-zipkin
  labels:
    app: external-zipkin
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: external-zipkin
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 9411
        volumeMounts:
        - mountPath: /etc/nginx # mount nginx-conf volumn to /etc/nginx
          name: nginx-conf
        - mountPath: /var/log/nginx
          name: log
      volumes:
      - name: nginx-conf
        configMap:
          name: external-zipkin-nginx-conf # place ConfigMap 'nginx-conf' on / 
            etc/nginx
          items:
            - key: nginx.conf
              path: nginx.conf
      - name: log
        emptyDir: {}

上述内容保存为文件external-zipkin-nginx.yaml,运行以下命令创建对应的部署及配置项:


kubectl apply -n istio-system -f external-zipkin-nginx.yaml