Kubectl :--v 接口调试,以及设置日志输出详细程度

Kubectl --v 操作演示

[root@10 ~]# kubectl get pod --v=0
NAME                                       READY   STATUS                  RESTARTS   AGE
api-demo-56db594ddf-rc5jf                  1/1     Running                 1          29d
busybox                                    1/1     Running                 0          22h
busybox-6f88f747db-c5pdn                   0/1     CrashLoopBackOff        3597       21d
busybox-deployment-7d8b8f459f-5c26l        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-6m27f        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-7xq5q        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-ck4ff        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-gq5fs        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-vfxvc        1/1     Running                 0          21h
ds.kusc00201-5b6hn                         1/1     Running                 1          20d
ds.kusc00201-9jqmt                         1/1     Running                 0          20d
ds.kusc00201-bf6tx                         1/1     Running                 0          20d
ds.kusc00201-c8rxh                         1/1     Running                 0          20d
ds.kusc00201-cgjzz                         1/1     Running                 1          20d
ds.kusc00201-gpstf                         1/1     Running                 0          20d
ds.kusc00201-js47m                         1/1     Running                 0          20d
falco-daemonset-2hg9w                      1/1     Running                 0          32h
falco-daemonset-68sc9                      1/1     Running                 1          32h
falco-daemonset-944zb                      1/1     Running                 1          32h
falco-daemonset-d8dnh                      1/1     Running                 0          32h
falco-daemonset-db7vg                      1/1     Running                 1          32h
falco-daemonset-kr8wj                      1/1     Running                 0          32h
falco-daemonset-vdsb6                      1/1     Running                 2          32h
lumpy--koala                               0/1     Init:CrashLoopBackOff   3695       20d
nginx-864459b57d-zqgjt                     1/1     Running                 0          21h
single-nginx-deployment-69dd5c845f-5znk9   1/1     Running                 0          44d
single-nginx-deployment-69dd5c845f-85vvr   0/1     ContainerCreating       0          21h
single-nginx-deployment-69dd5c845f-cdkfc   1/1     Running                 0          21d
test                                       1/1     Running                 1          19d
[root@10 ~]# kubectl get pod --v=2
I0108 19:16:05.058744  409257 get.go:558] no kind is registered for the type v1beta1.Table in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"
NAME                                       READY   STATUS                  RESTARTS   AGE
api-demo-56db594ddf-rc5jf                  1/1     Running                 1          29d
busybox                                    1/1     Running                 0          22h
busybox-6f88f747db-c5pdn                   0/1     CrashLoopBackOff        3597       21d
busybox-deployment-7d8b8f459f-5c26l        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-6m27f        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-7xq5q        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-ck4ff        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-gq5fs        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-vfxvc        1/1     Running                 0          21h
ds.kusc00201-5b6hn                         1/1     Running                 1          20d
ds.kusc00201-9jqmt                         1/1     Running                 0          20d
ds.kusc00201-bf6tx                         1/1     Running                 0          20d
ds.kusc00201-c8rxh                         1/1     Running                 0          20d
ds.kusc00201-cgjzz                         1/1     Running                 1          20d
ds.kusc00201-gpstf                         1/1     Running                 0          20d
ds.kusc00201-js47m                         1/1     Running                 0          20d
falco-daemonset-2hg9w                      1/1     Running                 0          32h
falco-daemonset-68sc9                      1/1     Running                 1          32h
falco-daemonset-944zb                      1/1     Running                 1          32h
falco-daemonset-d8dnh                      1/1     Running                 0          32h
falco-daemonset-db7vg                      1/1     Running                 1          32h
falco-daemonset-kr8wj                      1/1     Running                 0          32h
falco-daemonset-vdsb6                      1/1     Running                 2          32h
lumpy--koala                               0/1     Init:CrashLoopBackOff   3695       20d
nginx-864459b57d-zqgjt                     1/1     Running                 0          21h
single-nginx-deployment-69dd5c845f-5znk9   1/1     Running                 0          44d
single-nginx-deployment-69dd5c845f-85vvr   0/1     ContainerCreating       0          21h
single-nginx-deployment-69dd5c845f-cdkfc   1/1     Running                 0          21d
test                                       1/1     Running                 1          19d
[root@10 ~]# kubectl get pod --v=8
I0108 19:16:08.907946  409391 loader.go:359] Config loaded from file /root/.kube/config
I0108 19:16:08.912806  409391 loader.go:359] Config loaded from file /root/.kube/config
I0108 19:16:08.924331  409391 loader.go:359] Config loaded from file /root/.kube/config
I0108 19:16:08.947717  409391 loader.go:359] Config loaded from file /root/.kube/config
I0108 19:16:08.948706  409391 round_trippers.go:383] GET https://10.10.101.170:6443/api/v1/namespaces/default/pods?limit=500
I0108 19:16:08.948739  409391 round_trippers.go:390] Request Headers:
I0108 19:16:08.948755  409391 round_trippers.go:393]     Accept: application/json;as=Table;v=v1beta1;g=meta.k8s.io, application/json
I0108 19:16:08.948771  409391 round_trippers.go:393]     User-Agent: kubectl/v1.12.3 (linux/amd64) kubernetes/435f92c
I0108 19:16:08.989401  409391 round_trippers.go:408] Response Status: 200 OK in 40 milliseconds
I0108 19:16:08.989454  409391 round_trippers.go:411] Response Headers:
I0108 19:16:08.989471  409391 round_trippers.go:414]     Content-Type: application/json
I0108 19:16:08.989485  409391 round_trippers.go:414]     Date: Wed, 08 Jan 2020 11:16:08 GMT
I0108 19:16:08.990879  409391 request.go:942] Response Body: {"kind":"Table","apiVersion":"meta.k8s.io/v1beta1","metadata":{"selfLink":"/api/v1/namespaces/default/pods","resourceVersion":"53664878"},"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":"The aggregate readiness state of this pod for accepting traffic.","priority":0},{"name":"Status","type":"string","format":"","description":"The aggregate status of the containers in this pod.","priority":0},{"name":"Restarts","type":"integer","format":"","description":"The number of times the containers in this pod have been restarted.","priority":0},{"name":"Age","type":"str [truncated 24720 chars]
I0108 19:16:09.005556  409391 get.go:558] no kind is registered for the type v1beta1.Table in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"
NAME                                       READY   STATUS                  RESTARTS   AGE
api-demo-56db594ddf-rc5jf                  1/1     Running                 1          29d
busybox                                    1/1     Running                 0          22h
busybox-6f88f747db-c5pdn                   0/1     CrashLoopBackOff        3597       21d
busybox-deployment-7d8b8f459f-5c26l        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-6m27f        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-7xq5q        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-ck4ff        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-gq5fs        1/1     Running                 0          21h
busybox-deployment-7d8b8f459f-vfxvc        1/1     Running                 0          21h
ds.kusc00201-5b6hn                         1/1     Running                 1          20d
ds.kusc00201-9jqmt                         1/1     Running                 0          20d
ds.kusc00201-bf6tx                         1/1     Running                 0          20d
ds.kusc00201-c8rxh                         1/1     Running                 0          20d
ds.kusc00201-cgjzz                         1/1     Running                 1          20d
ds.kusc00201-gpstf                         1/1     Running                 0          20d
ds.kusc00201-js47m                         1/1     Running                 0          20d
falco-daemonset-2hg9w                      1/1     Running                 0          32h
falco-daemonset-68sc9                      1/1     Running                 1          32h
falco-daemonset-944zb                      1/1     Running                 1          32h
falco-daemonset-d8dnh                      1/1     Running                 0          32h
falco-daemonset-db7vg                      1/1     Running                 1          32h
falco-daemonset-kr8wj                      1/1     Running                 0          32h
falco-daemonset-vdsb6                      1/1     Running                 2          32h
lumpy--koala                               0/1     Init:CrashLoopBackOff   3695       20d
nginx-864459b57d-zqgjt                     1/1     Running                 0          21h
single-nginx-deployment-69dd5c845f-5znk9   1/1     Running                 0          44d
single-nginx-deployment-69dd5c845f-85vvr   0/1     ContainerCreating       0          21h
single-nginx-deployment-69dd5c845f-cdkfc   1/1     Running                 0          21d
test                  

Kubectl 日志输出详细程度和调试

-v, --v Level

  • number for the log level verbosity (日志级别的数值)

Kubectl 日志输出详细程度是通过 -v 或者 --v 来控制的,参数后跟了一个数字表示日志的级别。Kubernetes 通用的日志习惯和相关的日志级别在 这里 有相应的描述。

详细程度描述
--v=0通常对此有用,*始终*对运维人员可见。
--v=1如果您不想要详细程度,则为合理的默认日志级别。
--v=2有关服务的有用稳定状态信息以及可能与系统中的重大更改相关的重要日志消息。这是大多数系统的建议默认日志级别。
--v=3有关更改的扩展信息。
--v=4Debug 级别。
--v=6显示请求的资源。
--v=7显示 HTTP 请求头。
--v=8显示 HTTP 请求内容。
--v=9显示 HTTP 请求内容而不截断内容。

注意:也可以输入大于9的数值,输出的结果会更详细

日志约定

以下是要使用的klog级别的约定。 全局首选使用klog来 记录日志,以更好地控制运行时。

  • klog.Errorf()-始终是一个错误

  • klog.Warningf()-意外的,但可能不是错误

  • klog.Infof()具有多个级别:

    • klog.V(0)-通常对于操作者总是有用的
      • 程序员错误
      • 记录有关紧急情况的额外信息
      • CLI参数处理
    • klog.V(1)-如果您不想冗长,则为合理的默认日志级别。
      • 有关配置的信息(在X上监听,在Y监听)
      • 与可以纠正的状况相关的频繁重复的错误(检测到吊舱不健康)
    • klog.V(2)-有关服务的有用的稳态信息和重要的日志消息,这些消息可能与系统中的重大更改相关。对于大多数系统,这是建议的默认日志级别。
      • 记录HTTP请求及其退出代码
      • 系统状态改变(杀戮荚)
      • 控制器状态更改事件(启动Pod)
      • 计划程序日志消息
    • klog.V(3)-有关更改的扩展信息
      • 有关系统状态更改的更多信息
    • klog.V(4)-调试级别的详细程度
      • 登录特别棘手的代码部分,您可能想稍后再回来检查它
    • klog.V(5)-跟踪级别的详细程度
      • 上下文了解导致错误和警告的步骤
      • 解决所报告问题的更多信息

实际的默认级别为V(2)。开发人员和QE环境可能希望以V(3)或V(4)运行。如果要更改日志级别,则可以传入-v=X,X是所需的最大日志级别。

 

参考链接:

https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md

https://kubernetes.io/zh/docs/reference/kubectl/cheatsheet/

https://github.com/kubernetes/klog/blob/master/klog.go#L407-L420

https://github.com/kubernetes/kubernetes/issues/35054

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琦彦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值