使用 -v 或 --v 标志跟着一个整数来指定日志级别,能够查看 kubectl 命令内部与 kubernetes 接口的交互细节

参数说明

--v=0

总是对操作人员可见。

--v=1

合理的默认日志级别,如果您不需要详细输出。

--v=2

可能与系统的重大变化相关的,有关稳定状态的信息和重要的日志信息。这是对大多数系统推荐的日志级别。

--v=3

有关更改的扩展信息。

--v=4

调试级别详细输出。

--v=6

显示请求的资源。

--v=7

显示HTTP请求的header。

--v=8

显示HTTP请求的内容。

示例

命令

# 根据 pod name 查找
kubectl get pods --all-namespaces  --field-selector metadata.name=id-generator-944bb7cbb-zzn2d --v=8

结果,可以看到所有 http 交互的参数

[root@ecs-bj4-gitlab-01 devops]# kubectl get pods --all-namespaces  --field-selector metadata.name=id-generator-944bb7cbb-zzn2d --v=8
I1110 16:10:29.063844   32171 loader.go:375] Config loaded from file:  /root/.kube/config
I1110 16:10:29.109496   32171 round_trippers.go:421] GET https://10.88.174.13:5443/api/v1/pods?fieldSelector=metadata.name=id-generator-944bb7cbb-zzn2d&limit=500
I1110 16:10:29.109515   32171 round_trippers.go:428] Request Headers:
I1110 16:10:29.109520   32171 round_trippers.go:432]     Accept: application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json
I1110 16:10:29.109525   32171 round_trippers.go:432]     User-Agent: kubectl/v1.19.11 (linux/amd64) kubernetes/c6a2f08
I1110 16:10:29.149194   32171 round_trippers.go:447] Response Status: 200 OK in 39 milliseconds
I1110 16:10:29.149214   32171 round_trippers.go:450] Response Headers:
I1110 16:10:29.149219   32171 round_trippers.go:453]     Cache-Control: no-cache, private
I1110 16:10:29.149222   32171 round_trippers.go:453]     Content-Type: application/json
I1110 16:10:29.149225   32171 round_trippers.go:453]     Content-Length: 3942
I1110 16:10:29.149229   32171 round_trippers.go:453]     Date: Wed, 10 Nov 2021 08:10:29 GMT
I1110 16:10:29.149280   32171 request.go:1097] Response Body: {"kind":"Table","apiVersion":"meta.k8s.io/v1","metadata":{"selfLink":"/api/v1/pods","resourceVersion":"106760022"},"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":"string","format":"","descr [truncated 2918 chars]
NAMESPACE   NAME                           READY   STATUS    RESTARTS   AGE
default     id-generator-944bb7cbb-zzn2d   1/1     Running   0          73m

点赞(3) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部