istio部署-istio jaeger & kiali

參考

1. 使用 Jaeger

  • jaegertracing/jaeger 是一個用於分佈式跟蹤的開源軟件,提供原生 OpenTracing 支持,向下兼容 ZipKin
  • istio 中採用 Jaeger 做爲分佈式跟蹤組件;
  • istio sidecar 爲網格中的應用提供的跟蹤功能只能提供調用環節的數據,若是須要支持整條鏈路,須要根據 OpenTracing 規範對應用進行改寫。

1.1 啓用 Jaeger

1.1.1 定製 Jaeger values.yaml

  • Jaeger 默認不啓用,須要定製安裝清單,能夠經過 helm template--set 參數定製安裝清單文件。
# 同時啓用 "ingress" ,開放服務
vim install/kubernetes/helm/istio/charts/tracing/values.yaml

ingress:
  #  啓用 "ingress",默認值 "false"
  enabled: true
  # Used to create an Ingress record.
  hosts:
    # 修改 "domain"
    - tracing.istio
  annotations:
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  tls:
    # Secrets must be manually created in the namespace.
    # - secretName: tracing-tls
    #   hosts:
    #     - tracing.local

1.1.2 渲染並啓用 Jaeger

# 直接修改 Jaeger 的 `values.yaml` 文件的 "enabled: false" 爲 "enabled: true" 並不生效;
# 但修改 `values.yaml` 文件的其他部分是有效的
helm template install/kubernetes/helm/istio \
--set tracing.enabled=true \
--name istio \
--namespace istio-system > default-tracing.yaml

# 查看資源對象
kubectl get pod -n istio-system -w

# `values.yaml` 文件的 "contextPath" 參數不體現,默認值即 "/jaeger"
URL: http://tracing.istio/jaeger/

# 構建流量觀察 jaeger 服務
kubectl exec -it -c sleep $(kubectl get pod -l app=sleep,version=v1 -o jsonpath={.items[0].metadata.name}) /bin/bash
bash-4.4# for i in `seq 100` ; do http --body http://flaskapp/env/version ; done

1.2 跟蹤參數傳遞

1.2.1 孤立的跟蹤信息

# 樣例服務在 istio 源代碼的 samples 目錄下
cd istio-1.1.7/samples/httpbin
kubectl apply -f httpbin.yaml

# 在 "sleep" 服務的 Pod 內發起請求,要求 "flaskapp" 調用 "httpbin" 服務的 "/get" 路徑,並返回 "httpbin" 給出的響應,同時要顯示 "sleep" 發出的請求 Header 的內容;
# 完整路徑:"sleep" --> "flaskapp" --> "httpbin",但 "OpenTracing" 所依賴的 `header` 沒有被傳遞,致使 Jaeger 沒法肯定調用之間的關係
kubectl exec -it -c sleep $(kubectl get pod -l app=sleep,version=v1 -o jsonpath={.items[0].metadata.name}) /bin/bash
bash-4.4# http --debug http://flaskapp/fetch_with_header?url=http://httpbin:8000/get
  • 返回信息中,requests.request 是 httpie 客戶端發出請求的 header 的原始內容;
  • flaskapp 收到的 header 內容中有一系列 "X-*" 的請求 header ,是 Evory 代理對請求進行的修改,其中包含分佈式跟蹤所須要的 Request-Id 等請求 header 。

1.2.2 跟蹤參數傳遞

1.2.2.1 fetch_with_trace
  • flaskapp 服務的代碼中定義了一個 fetch_with_trace 方法:
# 路徑:"/app/main.py"
@app.route('/fetch_with_trace')                              
def fetch_with_trace():                                      
    url = request.args.get('url', '')                        
    request_headers = dict(request.headers)
    new_header = {}                        
    for key in request_headers.keys():     
        if key.lower() in TRACE_HEADERS:   
            new_header[key] = request_headers[key]
                                                  
    req = Request(url, headers = new_header)      
    return urlopen(req).read()
  • 經過 fetch_with_trace 方法:將中間服務收到的請求在進行下一級請求時,將其中用於跟蹤的 header 傳遞下去,便可將孤立的跟蹤信息融合在一塊兒。
kubectl exec -it -c sleep $(kubectl get pod -l app=sleep,version=v1 -o jsonpath={.items[0].metadata.name}) /bin/bash
bash-4.4# for i in `seq 100` ; do http http://flaskapp/fetch_with_trace?url=http://httpbin:8000/ip ; done
1.2.2.1 fetch_with_header
  • 經過 /fetch_with_header 方法,能夠觀察 header 傳遞過程當中的變化:
bash-4.4# do http http://flaskapp/fetch_with_header?url=http://httpbin:8000/get
  • 返回兩組 http header :
    • 第一組來自 flaskapp ,表示 sleep --> flaskapp 的請求內容;
    • 第二組來自 httpbin ,表示 flaskapp --> httpbin 的請求內容。

2. 使用 Kiali

  • kiali 也是一個用於 istio 可視化的軟件:
  • 與 Grafana & Prometheus 不一樣的是,Kiali 目前專用於 istio 系統;
  • 除提供監控,可視化,跟蹤等通用功能外,還專門提供了 istio 的配置驗證,健康評估等高級功能。

2.1 啓用 Kiali

2.1.1 定製 Kiali values.yaml

  • Kiali 默認未啓用,須要定製安裝清單,能夠經過 helm template--set 參數渲染定製安裝清單文件。
# 同時啓用 "ingress" ,開放服務
vim install/kubernetes/helm/istio/charts/kiali/values.yaml

# 使用當前最新(2019年6月先後)穩定鏡像
tag: v0.20
# "ingress" 資源的 "spec.rules.host.http.paths.path" 字段,即 "subpath"
contextPath: /kiali

ingress:
  #  啓用 "ingress",默認值 "false"
  enabled: true
  # Used to create an Ingress record.
  hosts:
    # 修改 "domain"
    - kiali.istio
  annotations:
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  tls:
    # Secrets must be manually created in the namespace.
    # - secretName: kiali-tls
    #   hosts:
    #     - kiali.local

dashboard:
  # 以名爲  "kiali" 的 "Secret" 對象傳遞登錄帳號與密碼
  secretName: kiali # You must create a secret with this name - one is not provided out-of-box.
  # 重定向,以 "ConfigMap" 對象的形式掛載到工做負載
  # 注意:能夠被訪問的外部地址
  grafanaURL: http://grafana:3000 # If you have Grafana installed and it is accessible to client browsers, then set this to its external URL. Kiali will redirect users to this URL when Grafana metrics are to be shown.
  jaegerURL: http://tracing:80 # If you have Jaeger installed and it is accessible to client browsers, then set this property to its external URL. Kiali will redirect users to this URL when Jaeger tracing is to be shown.

2.1.2 渲染並啓用 Kiali

# 直接修改 Jaeger 的 `values.yaml` 文件的 "enabled: false" 爲 "enabled: true" 並不生效;
# 但修改 `values.yaml` 文件的其他部分是有效的
helm template install/kubernetes/helm/istio \
--set kiali.enabled=true \
--name istio \
--namespace istio-system > default-tracing.yaml

# 建立 "Secret" 對象 "kiali"
kubectl create secret generic kiali -n istio-system --from-literal "username=admin" --from-literal "passphrase=admin"

# 查看資源對象
kubectl get pod -n istio-system -w

# 訪問地址
URL: http://kiali.istio/kiali/
相關文章
相關標籤/搜索