获取 Envoy 访问日志

    • 按照安装指南中的说明安装 Istio。

    • 启动 示例,以获取发送请求的测试源。

    如果您启用了自动 sidecar 注入,请执行

    否则,在部署 sleep 应用程序前,您必须手动注入 sidecar:

    Zip

    1. $ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)
    1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
    • 启动 样例程序。

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

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

    Zip

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

    修改 istio 配置文件:

    1. $ helm template install/kubernetes/helm/istio --namespace=istio-system -x templates/configmap.yaml --set global.proxy.accessLogFile="/dev/stdout" | kubectl replace -f -

    您也可以通过设置 accessLogEncoding 来在 JSON 和 TEXT 两种格式之间切换。

    • global.proxy.accessLogFile
    • global.proxy.accessLogEncoding
    • global.proxy.accessLogFormat
    • 检查 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 -
    • 检查 的日志:
    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)和其他相关信息

    关闭 和 httpbin 服务:

    编辑 istio 的配置信息然后设置 accessLogFile""

    1. configmap "istio" replaced