打开调试日志
在实际使用中,通常通过 kubectl 来访问 apiserver,也可以通过 Kubernetes 各个语言的 client 库来访问 apiserver。在使用 kubectl 时,打开调试日志也可以看到每个 API 调用的格式,比如
[root@localhost ~]# kubectl --v=8 get pods
I1126 19:10:44.878279 108242 loader.go:359] Config loaded from file /root/.kube/config
I1126 19:10:44.878942 108242 loader.go:359] Config loaded from file /root/.kube/config
I1126 19:10:44.882024 108242 round_trippers.go:383] GET https://10.0.60.51:6443/apis/metrics.k8s.io/v1beta1?timeout=32s
I1126 19:10:44.882038 108242 round_trippers.go:390] Request Headers:
I1126 19:10:44.882069 108242 round_trippers.go:393] Accept: application/json, */*
I1126 19:10:44.882076 108242 round_trippers.go:393] User-Agent: kubectl/v1.12.1 (linux/amd64) kubernetes/4ed3216
I1126 19:10:44.891669 108242 round_trippers.go:408] Response Status: 503 Service Unavailable in 9 milliseconds
I1126 19:10:44.891683 108242 round_trippers.go:411] Response Headers:
I1126 19:10:44.891689 108242 round_trippers.go:414] Date: Mon, 26 Nov 2018 11:10:44 GMT
I1126 19:10:44.891695 108242 round_trippers.go:414] Content-Type: text/plain; charset=utf-8
I1126 19:10:44.891701 108242 round_trippers.go:414] X-Content-Type-Options: nosniff
I1126 19:10:44.891707 108242 round_trippers.go:414] Content-Length: 20
I1126 19:10:44.893661 108242 request.go:942] Response Body: service unavailable
I1126 19:10:44.895465 108242 request.go:1144] body was not decodable (unable to check for Status): couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
I1126 19:10:44.895484 108242 cached_discovery.go:77] skipped caching discovery info due to the server is currently unable to handle the request
I1126 19:10:44.896047 108242 loader.go:359] Config loaded from file /root/.kube/config
I1126 19:10:44.896454 108242 round_trippers.go:383] GET https://10.0.60.51:6443/apis/metrics.k8s.io/v1beta1?timeout=32s
I1126 19:10:44.896464 108242 round_trippers.go:390] Request Headers:
I1126 19:10:44.896470 108242 round_trippers.go:393] Accept: application/json, */*
I1126 19:10:44.896477 108242 round_trippers.go:393] User-Agent: kubectl/v1.12.1 (linux/amd64) kubernetes/4ed3216
I1126 19:10:44.898065 108242 round_trippers.go:408] Response Status: 503 Service Unavailable in 1 milliseconds
I1126 19:10:44.898077 108242 round_trippers.go:411] Response Headers:
I1126 19:10:44.898084 108242 round_trippers.go:414] Content-Type: text/plain; charset=utf-8
I1126 19:10:44.898090 108242 round_trippers.go:414] X-Content-Type-Options: nosniff
I1126 19:10:44.898096 108242 round_trippers.go:414] Content-Length: 20
I1126 19:10:44.898101 108242 round_trippers.go:414] Date: Mon, 26 Nov 2018 11:10:44 GMT
I1126 19:10:44.900199 108242 request.go:942] Response Body: service unavailable
I1126 19:10:44.901131 108242 request.go:1144] body was not decodable (unable to check for Status): couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
I1126 19:10:44.901147 108242 cached_discovery.go:77] skipped caching discovery info due to the server is currently unable to handle the request
I1126 19:10:44.901174 108242 shortcut.go:89] Error loading discovery information: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: the server is currently unable to handle the request
I1126 19:10:44.902749 108242 round_trippers.go:383] GET https://10.0.60.51:6443/apis/metrics.k8s.io/v1beta1?timeout=32s
I1126 19:10:44.902759 108242 round_trippers.go:390] Request Headers:
I1126 19:10:44.902765 108242 round_trippers.go:393] Accept: application/json, */*
I1126 19:10:44.902772 108242 round_trippers.go:393] User-Agent: kubectl/v1.12.1 (linux/amd64) kubernetes/4ed3216
I1126 19:10:44.903598 108242 round_trippers.go:408] Response Status: 503 Service Unavailable in 0 milliseconds
I1126 19:10:44.903610 108242 round_trippers.go:411] Response Headers:
I1126 19:10:44.903617 108242 round_trippers.go:414] Content-Type: text/plain; charset=utf-8
I1126 19:10:44.903624 108242 round_trippers.go:414] X-Content-Type-Options: nosniff
I1126 19:10:44.903629 108242 round_trippers.go:414] Content-Length: 20
I1126 19:10:44.903635 108242 round_trippers.go:414] Date: Mon, 26 Nov 2018 11:10:44 GMT
I1126 19:10:44.904512 108242 request.go:942] Response Body: service unavailable
I1126 19:10:44.905238 108242 request.go:1144] body was not decodable (unable to check for Status): couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
I1126 19:10:44.905252 108242 cached_discovery.go:77] skipped caching discovery info due to the server is currently unable to handle the request
I1126 19:10:44.906620 108242 loader.go:359] Config loaded from file /root/.kube/config
I1126 19:10:44.906861 108242 round_trippers.go:383] GET https://10.0.60.51:6443/api/v1/namespaces/default/pods?limit=500
I1126 19:10:44.906870 108242 round_trippers.go:390] Request Headers:
I1126 19:10:44.906877 108242 round_trippers.go:393] Accept: application/json;as=Table;v=v1beta1;g=meta.k8s.io, application/json
I1126 19:10:44.906884 108242 round_trippers.go:393] User-Agent: kubectl/v1.12.1 (linux/amd64) kubernetes/4ed3216
I1126 19:10:44.909416 108242 round_trippers.go:408] Response Status: 200 OK in 2 milliseconds
I1126 19:10:44.909431 108242 round_trippers.go:411] Response Headers:
I1126 19:10:44.909438 108242 round_trippers.go:414] Content-Type: application/json
I1126 19:10:44.909445 108242 round_trippers.go:414] Date: Mon, 26 Nov 2018 11:10:44 GMT
I1126 19:10:44.909650 108242 request.go:942] Response Body: {"kind":"Table","apiVersion":"meta.k8s.io/v1beta1","metadata":{"selfLink":"/api/v1/namespaces/default/pods","resourceVersion":"773119"},"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":"strin [truncated 17935 chars]
I1126 19:10:44.911428 108242 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
app-c8c54f79-2bfh9 1/1 Running 15 11d
app-c8c54f79-9cg8q 1/1 Running 15 11d
app-c8c54f79-9d494 1/1 Running 15 11d
app-c8c54f79-9qcbj 1/1 Running 15 11d
app-c8c54f79-9wdgk 1/1 Running 15 11d
app-c8c54f79-bdcrl 1/1 Running 15 11d
app-c8c54f79-bq4fh 1/1 Running 15 11d
app-c8c54f79-cmtn4 1/1 Running 15 11d
app-c8c54f79-qd7z8 1/1 Running 15 11d
app-c8c54f79-wz9gq 1/1 Running 15 11d
filled-oyster-heapster-796448dd9d-whfk6 2/2 Running 2 7d2h
healthcheck 0/1 CrashLoopBackOff 1432 11d
httpd-5c44c97cb5-h5z7l 1/1 Running 1 12d
httpd-5c44c97cb5-rdlr8 1/1 Running 1 12d
httpd-5c44c97cb5-vhz9z 1/1 Running 1 12d
liveness 1/1 Running 1997 11d
mypod 1/1 Running 14 11d
nginx-deployment-5fd98dbf5f-th4jb 1/1 Running 1 13d
nginx-deployment-5fd98dbf5f-zhmjz 1/1 Running 1 13d
orderly-ostrich-mychart-86957b459c-9cdfh 1/1 Running 1 10d
producer-consumer 2/2 Running 30 11d
prometheus-operator-88fcf6d95-cjrcf 0/1 CrashLoopBackOff 58 7d1h
readiness 0/1 Completed 0 11d