• 获取 Envoy 访问日志
    • Before you begin
    • 开启 Envoy 访问日志
    • 测试访问日志
    • 清除
      • 关闭 Envoy 的访问日志
    • 相关内容

    获取 Envoy 访问日志

    Istio 最简单的日志类型是Envoy 的访问日志。Envoy 代理打印访问信息到标准输出。Envoy 容器的标准输出能够通过 kubectl logs 命令打印出来。

    Before you begin

    • Setup Istio by following the instructions in the Installation guide.

    • Deploy the sleep sample app to use as a test source for sending requests.If you haveautomatic sidecar injectionenabled, run the following command to deploy the sample app:

    Zip

    1. $ kubectl apply -f @samples/sleep/sleep.yaml@

    Otherwise, manually inject the sidecar before deploying the sleep application with the following command:

    Zip

    1. $ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)

    You can use any pod with curl installed as a test source.

    • Set the SOURCE_POD environment variable to the name of your source pod:
    1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
    • 启动 httpbin 样例程序。

    如果您启用了 sidecar 自动注入,通过以下命令部署 httpbin 服务:

    Zip

    1. $ kubectl apply -f @samples/httpbin/httpbin.yaml@

    否则,您必须在部署 httpbin 应用程序前进行手动注入,部署命令如下:

    Zip

    1. $ kubectl apply -f <(istioctl kube-inject -f @samples/httpbin/httpbin.yaml@)

    开启 Envoy 访问日志

    修改 istio 配置文件:

    1. $ istioctl manifest apply --set values.global.proxy.accessLogFile="/dev/stdout"
    2. configmap "istio" replaced

    您也可以通过设置 accessLogEncodingJSONTEXT 来在两种格式之间切换。

    您也许希望通过设置 accessLogFormat 来自定义访问日志的格式。

    这三种参数也可以通过安装选项来进行配置:

    • global.proxy.accessLogFile
    • global.proxy.accessLogEncoding
    • global.proxy.accessLogFormat

    测试访问日志

    • sleephttpbin 发送一个请求:
    1. $ kubectl exec -it $(kubectl get pod -l app=sleep -o jsonpath='{.items[0].metadata.name}') -c sleep -- curl -v httpbin:8000/status/418
    2. * Trying 172.21.13.94...
    3. * TCP_NODELAY set
    4. * Connected to httpbin (172.21.13.94) port 8000 (#0)
    5. > GET /status/418 HTTP/1.1
    6. ...
    7. < HTTP/1.1 418 Unknown
    8. < server: envoy
    9. ...
    10. -=[ teapot ]=-
    11. _...._
    12. .' _ _ `.
    13. | ."` ^ `". _,
    14. \_;`"---"`|//
    15. | ;/
    16. \_ _/
    17. `"""`
    18. * Connection #0 to host httpbin left intact
    • 检查 sleep 的日志:
    1. $ kubectl logs -l app=sleep -c istio-proxy
    2. [2019-03-06T09:31:27.354Z] "GET /status/418 HTTP/1.1" 418 - "-" 0 135 11 10 "-" "curl/7.60.0" "d209e46f-9ed5-9b61-bbdd-43e22662702a" "httpbin:8000" "172.30.146.73:80" outbound|8000||httpbin.default.svc.cluster.local - 172.21.13.94:8000 172.30.146.82:60290 -
    • 检查 httpbin 的日志:
    1. $ kubectl logs -l app=httpbin -c istio-proxy
    2. [2019-03-06T09:31:27.360Z] "GET /status/418 HTTP/1.1" 418 - "-" 0 135 5 2 "-" "curl/7.60.0" "d209e46f-9ed5-9b61-bbdd-43e22662702a" "httpbin:8000" "127.0.0.1:80" inbound|8000|http|httpbin.default.svc.cluster.local - 172.30.146.73:80 172.30.146.82:38618 outbound_.8000_._.httpbin.default.svc.cluster.local

    请注意,与请求相对应的信息分别出现在源(sleep)和目标(httpbin)的 Istio 代理日志中。您可以在日志中看到 HTTP 动词(GET)、HTTP 路径(/status/418)、响应码(418)和其他请求相关信息。

    清除

    关闭 sleep 和 httpbin 服务:

    ZipZip

    1. $ kubectl delete -f @samples/sleep/sleep.yaml@
    2. $ kubectl delete -f @samples/httpbin/httpbin.yaml@

    关闭 Envoy 的访问日志

    编辑 istio 配置文件然后设置 accessLogFile""

    1. $ istioctl manifest apply
    2. configmap "istio" replaced

    相关内容

    Mixer and the SPOF Myth

    Improving availability and reducing latency.

    Mixer Adapter Model

    Provides an overview of Mixer's plug-in architecture.

    Collecting Metrics

    This task shows you how to configure Istio to collect and customize metrics.

    Jaeger

    了解如何配置代理以向 Jaeger 发送追踪请求。

    LightStep

    How to configure the proxies to send tracing requests to LightStep.

    Logging with Fluentd

    This task shows you how to configure Istio to log to a Fluentd daemon.