获取 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:
$ kubectl apply -f @samples/sleep/sleep.yaml@
Otherwise, manually inject the sidecar before deploying the sleep
application with the following command:
$ 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:
$ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
- 启动 httpbin 样例程序。
如果您启用了 sidecar 自动注入,通过以下命令部署 httpbin
服务:
$ kubectl apply -f @samples/httpbin/httpbin.yaml@
否则,您必须在部署 httpbin
应用程序前进行手动注入,部署命令如下:
$ kubectl apply -f <(istioctl kube-inject -f @samples/httpbin/httpbin.yaml@)
开启 Envoy 访问日志
修改 istio
配置文件:
$ istioctl manifest apply --set values.global.proxy.accessLogFile="/dev/stdout"
configmap "istio" replaced
您也可以通过设置 accessLogEncoding
为 JSON
或 TEXT
来在两种格式之间切换。
您也许希望通过设置 accessLogFormat
来自定义访问日志的格式。
这三种参数也可以通过安装选项来进行配置:
global.proxy.accessLogFile
global.proxy.accessLogEncoding
global.proxy.accessLogFormat
测试访问日志
- 从
sleep
向httpbin
发送一个请求:
$ kubectl exec -it $(kubectl get pod -l app=sleep -o jsonpath='{.items[0].metadata.name}') -c sleep -- curl -v httpbin:8000/status/418
* Trying 172.21.13.94...
* TCP_NODELAY set
* Connected to httpbin (172.21.13.94) port 8000 (#0)
> GET /status/418 HTTP/1.1
...
< HTTP/1.1 418 Unknown
< server: envoy
...
-=[ teapot ]=-
_...._
.' _ _ `.
| ."` ^ `". _,
\_;`"---"`|//
| ;/
\_ _/
`"""`
* Connection #0 to host httpbin left intact
- 检查
sleep
的日志:
$ kubectl logs -l app=sleep -c istio-proxy
[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
的日志:
$ kubectl logs -l app=httpbin -c istio-proxy
[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
)和其他请求相关信息。
清除
$ kubectl delete -f @samples/sleep/sleep.yaml@
$ kubectl delete -f @samples/httpbin/httpbin.yaml@
关闭 Envoy 的访问日志
编辑 istio
配置文件然后设置 accessLogFile
为 ""
。
$ istioctl manifest apply
configmap "istio" replaced
相关内容
Improving availability and reducing latency.
Provides an overview of Mixer's plug-in architecture.
This task shows you how to configure Istio to collect and customize metrics.
了解如何配置代理以向 Jaeger 发送追踪请求。
How to configure the proxies to send tracing requests to LightStep.
This task shows you how to configure Istio to log to a Fluentd daemon.