写在前面
日常访问kubernetes是离不开kubectl的,我们平时开发的时候基本都是走的apiserver的rest api,常常需要访问官网的api-reference,十分得不如kubectl用着方便啊,但是没办法。。。
然后就总是想着能不能kubectl执行命令的时候,把发到后端的报文打印出来,这样就不用一遍一遍的翻官方文档了,没想到,kubectl早就洞察了一切啊,一查还真有打印选项。
正文
kubectl get deployment --v=8
I0702 16:33:03.774716 19207 loader.go:359] Config loaded from file /root/.kube/config
I0702 16:33:03.797326 19207 round_trippers.go:416] GET https://172.18.141.129:6443/apis/extensions/v1beta1/namespaces/default/deployments?limit=500
I0702 16:33:03.797382 19207 round_trippers.go:423] Request Headers:
I0702 16:33:03.797407 19207 round_trippers.go:426] Accept: application/json;as=Table;v=v1beta1;g=meta.k8s.io, application/json
I0702 16:33:03.797428 19207 round_trippers.go:426] User-Agent: kubectl/v1.14.0 (linux/amd64) kubernetes/641856d
I0702 16:33:03.825980 19207 round_trippers.go:441] Response Status: 200 OK in 28 milliseconds
I0702 16:33:03.826016 19207 round_trippers.go:444] Response Headers:
I0702 16:33:03.826031 19207 round_trippers.go:447] Content-Type: application/json
I0702 16:33:03.826045 19207 round_trippers.go:447] Date: Tue, 02 Jul 2019 08:33:03 GMT
I0702 16:33:03.826301 19207 request.go:942] Response Body: {"kind":"Table","apiVersion":"meta.k8s.io/v1beta1","metadata":{"selfLink":"/apis/extensions/v1beta1/namespaces/default/deployments","resourceVersion":"5553091"},"columnDefinitions":[{"name":"Name","type":"string","format":"name","description":"Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names","priority":0},{"name":"Ready","type":"string","format":"","description":"Number of the pod with ready state","priority":0},{"name":"Up-to-date","type":"string","format":"","description":"Total number of non-terminated pods targeted by this deployment that have the desired template spec.","priority":0},{"name":"Available","type":"string","format":"","description":"Total number of available pods (ready for at least minReadySec [truncated 5739 chars]
I0702 16:33:03.828649 19207 get.go:570] no kind is registered for the type v1beta1.Table in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"
如上,只需在原有的kubectl命令后面加一个--v=8,就可以看到所有的交互信息了,request,response一目了然。
使用 -v 或 --v 来指定日志级别:
详细等级 | 描述 |
---|---|
--v=0 | 总是对操作人员可见。 |
--v=1 | 合理的默认日志级别,如果您不需要详细输出。 |
--v=2 | 可能与系统的重大变化相关的,有关稳定状态的信息和重要的日志信息。这是对大多数系统推荐的日志级别。 |
--v=3 | 有关更改的扩展信息。 |
--v=4 | 调试级别详细输出。 |
--v=6 | 显示请求的资源。 |
--v=7 | 显示HTTP请求的header。 |
--v=8 | 显示HTTP请求的内容。 |